Shoulda-matchers: Association matchers broken in 3.0.0

Created on 2 Oct 2015  路  8Comments  路  Source: thoughtbot/shoulda-matchers

Downgrading to 2.8.0 fixes these:

     Failure/Error: it { is_expected.to belong_to(:result)         }
     NoMethodError:
       undefined method `belong_to' for #<RSpec::ExampleGroups::BusinessModelResult::Associations:0x000001017f0c68>
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/matchers.rb:966:in `method_missing'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-core-3.3.2/lib/rspec/core/example_group.rb:671:in `method_missing'
     Failure/Error: it { is_expected.to have_many(:model_results)       }
       expected #<Result:0x000001074245c0> to respond to `has_many?`
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-support-3.3.0/lib/rspec/support.rb:86:in `block in <module:Support>'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-support-3.3.0/lib/rspec/support.rb:93:in `call'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-support-3.3.0/lib/rspec/support.rb:93:in `notify_failure'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/expectations/fail_with.rb:27:in `fail_with'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/expectations/handler.rb:40:in `handle_failure'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/expectations/handler.rb:27:in `with_matcher'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/expectations/expectation_target.rb:54:in `to'
     Failure/Error: it { is_expected.to have_one(:adverse_action_notification)   }
       expected #<Result:0x0000010a01b728> to respond to `has_one?`
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-support-3.3.0/lib/rspec/support.rb:86:in `block in <module:Support>'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-support-3.3.0/lib/rspec/support.rb:93:in `call'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-support-3.3.0/lib/rspec/support.rb:93:in `notify_failure'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/expectations/fail_with.rb:27:in `fail_with'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/expectations/handler.rb:40:in `handle_failure'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/expectations/handler.rb:27:in `with_matcher'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
     # ~/.rvm/gems/ruby-2.1.2@underwriting_service/gems/rspec-expectations-3.3.1/lib/rspec/expectations/expectation_target.rb:54:in `to'

Most helpful comment

Hey, for future reference, I had the same problem, only for one spec...I've setup the proper configuration for 3.0. What was wrong?

Before:

describe Subscriba::Limit do
...
end

After:

describe Subscriba::Limit, type: :model do
...
end

In my case, it's just the type: :model was missing in one model.

Hope that can help someone. Cheers.

All 8 comments

Try adding the configuration setup here. It fixed most of our tests, although some are still having issues.

Thanks @chrisjoywebb! That fixed it.

@baburdick could you please close this issue, if this is fixed. Thanks :heart:

@maurogeorge: Absolutely.

Thanks :smile:

Hey, for future reference, I had the same problem, only for one spec...I've setup the proper configuration for 3.0. What was wrong?

Before:

describe Subscriba::Limit do
...
end

After:

describe Subscriba::Limit, type: :model do
...
end

In my case, it's just the type: :model was missing in one model.

Hope that can help someone. Cheers.

Thanks @chrisjoywebb, amazing what one can accomplish when they read the docs. :smile:

Thanks @chrisjoywebb & @jipiboily.

Was this page helpful?
0 / 5 - 0 ratings