Shoulda :: Matchers :: Independent :: DelegateMethodMatcher:未定义方法`allow_nil'

时间:2019-07-08 02:32:00

标签: ruby-on-rails ruby rspec rspec-rails shoulda-matchers

我正尝试使用 shoulda-matchers(3.1.2) rspec-rails(3.7.2)测试我的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 模型的委托方法。我的 rails(5.0.1)应用程序中的em>和 ruby​​ 2.5.0-p0(x86_64-linux) 并得到此错误:

let routes: Routes;
routes = [
  {
    path: '',
    children: [
      {
        path: '',
        children: [
          {
            path: '',
            children: [
              {path: '', component: HeaderComponent, outlet: 'header'},
              {path: '', component: FooterComponent, outlet: 'footer'}
              // Routes that display a header and footer go here.
            ]
          },
          {
            path: '',
            children: [
              {
                path: '/frame',
                children: [{
                  path: 'search',
                  loadChildren: () => import('./search/search.module').then(module => module.SearchModule)
                }]
              }
            ]
          }
        ]
      }
    ]
  }
];

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

1 个答案:

答案 0 :(得分:2)

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

您可以看到this提交中引入了allow_nil方法,该方法属于4.0.0版本。