RSpec error "undefined method 'respond_to' for Rspec::Core::ExampleGroup::Nested"
I'm having a bug that I can't seem to pinpoint. I have an existing project that I'm adding tests to. When I try running my test (just a simple test... build a User with FactoryGirl, and calling "should respond_to(:email)"), I get the following error:
1) User should have an email Failure/Error: should respond_to(:email) NoMethodError: undefined method 'respond_to' for #<Rspec::Core::ExampleGroup::Nested_3:0x00000008355590> # ./spec/models/user_spec.rb:7:in 'block(2 levels) in <top (required)>'
I have a gist with my code in it here: https://gist.github.com/jeffstagg/9477647
I've got another project on the same dev box that runs rspec tests just fine, though I built it with my tests first and started the project with rspec / capybara / guard in mind. This project I'm coming back to later, and apparently missed something when setting up rspec for it. Can anyone see where I'm missing something?
You're trying to trigger RSpec's predicate matcher, which requires you write it as be_predicate, eg.
cat.can_has_cheezeburger? becomes cat.should be_can_has_cheezburger?
Sometimes these end up very readable, e.g. .too_big? => should be_too_big. Other times they don't quite work, like .respond_to? => should be_respond_to.
For such cases you're better off just using .respond_to?.should be_true
Add below to your rails_helper.rb(spec/support/rails_helper.rb) file:
Shoulda::Matchers.configure do |config| config.integrate do |with| with.test_framework :rspec with.library :rails end end