更新shoulda-matchers后的未定义方法'assign_to'

Rya*_*yan 6 testing gem rspec ruby-on-rails shoulda

'shoulda-matchers'在我的rails项目中的Gemfile中从版本1.4.2更新到2.0.0,现在当我运行我的rspec测试时,它给了我以下错误

undefined method `assign_to' for #<RSpec::Core::ExampleGroup::Nested_4::Nested_1::Nested_4::Nested_1:0x007fc96eaaaf48>
Run Code Online (Sandbox Code Playgroud)

是否在新的2.0.0版本中删除了此方法?

Rya*_*yan 13

是的,以下方法在版本1.5.0中已弃用,并在版本2.0.0的shoulda-matcher中删除.

  • assign_to
  • respond_with_content_type
  • query_the_database
  • validate_format_of
  • have_sent_email
  • permit (强参数匹配器)
  • delegate_method

如果您当前正在使用这些方法,开发人员建议以其他方式测试代码.

有关更改的简短列表,请访问https://github.com/thoughtbot/shoulda-matchers/blob/master/NEWS.md#v-200.

有关更改的详细列表以及删除这些方法的原因,您可以访问他们的博客http://robots.thoughtbot.com/post/47031676783/shoulda-matchers-2-0.