gpt4 book ai didi

ruby-on-rails - Rspec - 未定义的方法 'let'

转载 作者:数据小太阳 更新时间:2023-10-29 06:34:08 26 4
gpt4 key购买 nike

这是我的 rspec 文件:

require 'spec_helper'

describe "Birds" do
before { visit birds_path }
it "should have the right title" do
expect(page).to have_content("Approved Birds")
end
it "should contain the bird's name, genus, species" do
let(:bird) { FactoryGirl.create(:bird) }
expect(page).to have_content("#{bird.name}")
expect(page).to have_content("#{bird.genus}")
expect(page).to have_content("#{bird.species}")
end
end

当我运行它时,出现以下错误:

Failure/Error: let(:bird) { FactoryGirl.create(:bird) }
NoMethodError:
undefined method `let' for #<RSpec::Core::ExampleGroup::Nested_1:0xad87f84>

我的 Gemfile 包含“rspec-rails”和“capybara”gem。任何人都知道如何解决这个问题?谢谢

最佳答案

describe "Birds" do
let(:bird) { FactoryGirl.create(:bird) }

你不应该在 it block 中使用 let block 。它应该从 describe

中调用

关于ruby-on-rails - Rspec - 未定义的方法 'let',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23820224/

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