gpt4 book ai didi

rspec - 为什么我在 RSpec 3.0 中得到 "undefined method or variable ' example'"?

转载 作者:行者123 更新时间:2023-12-03 21:07:24 25 4
gpt4 key购买 nike

升级到 RSpec 3.0 后,我收到以下消息:

 Failure/Error: Unable to find matching line from backtrace
NameError:
undefined local variable or method `example' for #<RSpec::ExampleGroups::Anonymous:0x007f9ae985b548>

即使将规范减少到以下内容,该消息仍然存在:
describe "" do
it "" do
end
end

我确实注意到 capybara 靠近堆栈的顶部,如下所示:
 # /Users/palfvin/.rvm/gems/ruby-2.0.0-p247@botmetrics/gems/capybara-2.1.0/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>'

万一有帮助。

最佳答案

我遇到了与 before 类似的问题钩。

似乎 RSpec < 3 提供了 example每个钩子(Hook)中的对象,如下所示:

config.before(:each) do
if example.metadata[:js] # <--- this fails!
# do something
end
end

在 RSpec >= 3 中,您必须将显式示例参数传递给 block :
config.before(:each) do |example| # <--- see here!
if example.metadata[:js]
# do something
end
end

关于rspec - 为什么我在 RSpec 3.0 中得到 "undefined method or variable ' example'"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20413427/

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