I’m not sure why this isn’t working in rails, however it works in IRB.
I’m doing something like:
response = response.first
response is an array with hashes.
In irb, when trying to simulate this, it works fine.
e.g:
>> a = [{'a'=>3}]
=> [{"a"=>3}]
>> a = a.first
=> {"a"=>3}
However in debugger mode, in cucumber (in my step definition), i get this when doing the above statement:
e.g:
(rdb:1) response = response.first
NoMethodError Exception: undefined method `first' for nil:NilClass
(rdb:1) response
nil
Then, response gets set to nil.
Why are the behaviors different?
Are you 100% sure that
responseis a local variable? Ifresponsewere a method that would explain the behavior you are seeing: the local variableresponseshadows the methodresponse. If you want to call theresponsemethod you need to explicitly tell Ruby that want the method by either supplying an argument list or a receiver: