I'm using Ruby Cucumber to test an app. One of my step definitions does this:
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
Surprisingly this has started raising an error
The expect syntax does not support operator matchers, so you must pass a matcher to `#to`. (ArgumentError)
in one of my new git branches. Even now the main branch does not raise any error for this line of code.
I tried searching for any difference of code in the new branch related to this, but found nothing, not even any change in gem versions.
Here are a few things I tried:
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
So, my & operation results in an empty array, i.e. [], on which I apply the rspec matcher .to be_empty
.
The same code with the same values from JSON works in one branch and doesn't in another. This is not a machine related error as the same branch on different machines raises this error.
I even updated my RSpec gem versions on this new branch and tried, but still the error exists. I'm unable to identify the root cause for this failure. Help!