0

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!

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
Aks..
  • 1,343
  • 1
  • 20
  • 42

1 Answers1

0

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.

If it works when you switch back and forth, on different computers, with the same gem versions, then something in this diff is causing the problem, regardless of how unlikely you think that possibility is.

Start winnowing down the diff, either using git bisect if it's many commits, or by selectively applying the broken diff to the working one until you locate the code that breaks.

As a random guess: are you defining an empty method in the broken diff?

Xavier Shay
  • 4,067
  • 1
  • 30
  • 54
  • I found it. It was because of the "method_missing" method written without calling 'super'. After modifying my method_missing to use super, this issue got resolved – Aks.. Sep 13 '16 at 05:33