“undefined method 'allow'” after following deprecation instructions

564 views
Skip to first unread message

Grant Birchmeier

unread,
Jul 27, 2015, 12:44:11 PM7/27/15
to rspec
In my cucumber hooks file, I had this code under RSpec 2:

After do
  begin
    Challenge.unstub(:current)
  rescue RSpec::Mocks::MockExpectationError
  end
end

After upgrading to RSpec 3, I get a deprecation warning:

DEPRECATION: Using unstub from rspec-mocks' old :should syntax without explicitly enabling the syntax is deprecated. Use allow(...).to_receive(...).and_call_original or explicitly enable :should instead. Called from /Users/grant/xx/features/support/hooks.rb:37:in block in <top (required)>.

So I followed that, changing the offending line instead to:

allow(Challenge).to receive(:current).and_call_original

But now I get:

undefined method allow for #<Cucumber::Rails::World:0x007facbed9f1d0> (NoMethodError)

I've tried adding "include RSpec::Matchers" a few different ways, but it doesn't change anything.

I'm kind of stuck.  Can anyone show me the way?

-Grant 

Myron Marston

unread,
Jul 27, 2015, 12:46:52 PM7/27/15
to rs...@googlegroups.com

If allow is not defined, it means that RSpec::Mocks::ExampleMethods hasn’t been included in that context. I believe the fix would be:

World(RSpec::Mocks::ExampleMethods)

…but I haven’t written a cucumber hook in a long time.

One general question: why are you trying to unstub a method in an After hook? The lifecycle used by rspec-mocks is per example (i.e. per scenario in a cucumber context), assuming you’ve set it up correctly, so all stubs will be removed after each scenario anyway.

HTH,
Myron


--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/1dbbcdc2-d996-4d8a-b03f-5a8f6b1073a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Grant Birchmeier

unread,
Jul 27, 2015, 5:36:26 PM7/27/15
to rspec, myron....@gmail.com
Hm, I was not aware of that.  In that case, I guess it should be deleted altogether.  I'll try that out.  Thanks for the heads-up.
Reply all
Reply to author
Forward
0 new messages