gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:47:51 42 4
gpt4 key购买 nike

这是我的错误

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/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com