2

我正在尝试在我的rails (5.0.1)应用程序中使用ruby​​ 2.5.0-p0 (x86_64-linux )Comment测试我的模型的委托方法) 并收到此错误:

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

代码非常简洁明了,我认为库而不是我的实现代码可能存在一些错误。有谁知道这里出了什么问题?谢谢!

4

1 回答 1

4

您必须将您的 shoulda-matchers gem 升级到 4.0.0.rc1 或更高版本。

可以看到这个allow_nilcommit中引入的方法,属于4.0.0版本。

于 2019-07-08T03:10:41.407 回答