Rspec - undefined метод 'let'

Это мой файл 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 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". Кто-нибудь знает, как это исправить? Благодаря

Ответ 1

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

у вас никогда не должно быть блока let внутри блока it. Его следует вызывать из describe

Ответ 2

let определяется только внутри describe. Вы использовали его в it