我正在使用 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 版本并尝试过,但仍然存在错误。我无法确定此失败的根本原因。帮助!