【发布时间】:2016-09-06 13:41:05
【问题描述】:
我正在使用 Ruby Cucumber 来测试一个应用程序。我的步骤定义之一是这样做的:
Then(/^all of my (\.\S+) should not have the below fields:$/) do |path,table|
#path is my api, table is the fields list I'm sending through cucumber feature file and @result is the json resonse
expect(JsonPath.on(@result.body,path).flatten.map(&:keys).flatten.uniq & table.raw.flatten).to be_empty
end
令人惊讶的是,这已经开始引发错误
The expect syntax does not support operator matchers, so you must pass a matcher to `#to`. (ArgumentError)
在我的一个新 git 分支中。即使现在主分支也不会为这行代码引发任何错误。
我尝试在与此相关的新分支中搜索任何代码差异,但一无所获,甚至没有任何 gem 版本的变化。
我尝试了以下几点:
puts JsonPath.on(@result.body,path).flatten.map(&:keys).flatten.uniq & table.raw.flatten
#[]
var = JsonPath.on(@result.body,path).flatten.map(&:keys).flatten.uniq & table.raw.flatten
puts var.class
#Array
所以,我的 & 操作会产生一个空数组,即 [],我在其上应用 rspec 匹配器 .to be_empty。
JSON 中具有相同值的相同代码在一个分支中有效,而在另一个分支中无效。这不是与机器相关的错误,因为不同机器上的同一分支会引发此错误。
我什至在这个新分支上更新了我的 RSpec gem 版本并尝试过,但错误仍然存在。我无法确定此失败的根本原因。救命!
【问题讨论】:
-
到目前为止,我在您显示的代码中没有发现问题。请在您的问题中包含整个回溯。
-
你只想要错误的回溯吗?
-
是的,这就是我要的。
-
我找到了。这是因为没有调用“super”而编写的“method_missing”方法。修改我的method_missing以使用super后,这个问题得到了解决
标签: ruby rspec cucumber rspec-expectations