2

I'm trying to test a delegate method of my Comment model using shoulda-matchers (3.1.2) & rspec-rails (3.7.2) in my rails (5.0.1) application with ruby 2.5.0-p0 (x86_64-linux) and getting this error:

1) Comment delegation 
     Failure/Error: it { should delegate_method(:name).to(:user).allow_nil }

     NoMethodError:
       undefined method `allow_nil' for #<Shoulda::Matchers::Independent::DelegateMethodMatcher:0x00005587de5bc488>
     # ./spec/models/comment_spec.rb:11:in `block (3 levels) in <top (required)>'

Finished in 0.00225 seconds (files took 3.62 seconds to load)
1 example, 1 failure

The code is quite clean and straightforward, I think there could be some errors with the library rather than my implementation code. Does anyone know what is going wrong here? Thanks!

You Nguyen
  • 9,961
  • 4
  • 26
  • 52

1 Answers1

4

You must upgrade your shoulda-matchers gem to the version 4.0.0.rc1 or greater.

You can see the allow_nil method was introduced in this commit, which belongs to the 4.0.0 release.

Sebastián Palma
  • 32,692
  • 6
  • 40
  • 59