本文介绍了Rspec-未定义的方法'let'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的rspec文件:
This is my rspec file:
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
运行时,出现以下错误:
When I run it, I get the following error:
Failure/Error: let(:bird) { FactoryGirl.create(:bird) }
NoMethodError:
undefined method `let' for #<RSpec::Core::ExampleGroup::Nested_1:0xad87f84>
我的Gemfile包含 rspec-rails和 capybara宝石。有人对如何解决这个问题有任何想法吗?
谢谢
My Gemfile has both 'rspec-rails' and 'capybara' gems. Anyone have any idea on how to fix this? Thanks
推荐答案
describe "Birds" do
let(:bird) { FactoryGirl.create(:bird) }
您永远不应该拥有<$ c $在 it
块内的c> let 块。应该在 description
you should never have a let
block inside of a it
block. It should be called from within a describe
这篇关于Rspec-未定义的方法'let'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!