ruby-on-rails - RSpec 3 运行时错误 : "let declaration accessed in a ` before(:context )` hook"

标签 ruby-on-rails ruby rspec rspec-rails rspec3

这是我的错误

Failure/Error: @queue = FactoryGirl.create(model.to_s.underscore.to_sym)
 RuntimeError:
   let declaration `model` accessed in a `before(:context)` hook at:
     /var/www/html/SQ-UI/spec/support/user_queue/asterisk_serialize_spec.rb:7:in `block (2 levels) in <top (required)>'

   `let` and `subject` declarations are not intended to be called
   in a `before(:context)` hook, as they exist to define state that
   is reset between each example, while `before(:context)` exists to
   define state that is shared across examples in an example group.enter code here

这是破坏的代码
let(:model) { described_class } # the class that includes the concern

before(:all) do
  @queue = FactoryGirl.create(model.to_s.underscore.to_sym)
end

我试过删除它们并移动它们,但没有成功。

最佳答案

您不能引用 let subject 中的变量(或 before(:all))/before(:context)钩。这样做在 RSpec 2 中被弃用并从 RSpec 3 中删除。

在您的情况下,您似乎可以内联 let变量进入before(:all)堵塞:

before(:all) do
  @queue = FactoryGirl.create(described_class.to_s.underscore.to_sym)
end

关于ruby-on-rails - RSpec 3 运行时错误 : "let declaration accessed in a ` before(:context )` hook",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36795362/

相关文章:

ruby-on-rails - 为什么我今天必须在我的命令前添加 'bundle exec'?

ruby-on-rails - 了解 Rails 中的约束

ruby-on-rails - View 中的反向链接应根据 Controller 更改

ruby - 在 Ruby 中,为什么堆栈跟踪中没有变量名?

ruby-on-rails - 渲染 Rails 模板/ View 以生成 PDF 然后直接从服务器通过 CUPS 打印的方法?

sql - Rails 3 模型将某些列映射到不同的模型属性

ruby-on-rails - rails 4.2.0 ActionController::UrlGenerationError

javascript - 如何通过单击按钮显示隐藏的 div 部分

ruby-on-rails - ruby/rails 中的自然语言日期?

ruby-on-rails - Ruby on Rails 中的日期自定义