RSpec 3 RuntimeError: "let declaration accessed in a `before(:context)` hook"

RSpec 3 RuntimeError: "let declaration accessed in a `before(:context)` hook"

这是我的错误

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

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

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

在您的情况下,您似乎可以将 let 变量内联到 before(:all) 块中:

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