Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec/Capybara "feature" method undefined when Guard runs specs in watched files, works when run manually

I am getting a strange issue when using Guard to run my specs.

I am running a feature spec that uses the Capybara "feature" / "scenario" syntax. I am also using Spring.

Everything works fine if I run rspec spec or spring rspec in the console or rspec in the Guard shell. But, when the watched specs get run automatically by Guard, I get the following error:

/spec/features/navigation_spec.rb:1:in <top (required)>': undefined methodfeature' for main:Object (NoMethodError)

Why is it not picking up the Capybara syntax only in this specific context?

Here is the relevant code:

GuardFile

guard :rspec, :spring => true do
    watch(%r{^spec/.+_spec\.rb$})
end

spec/features/navigation_spec.rb

feature "navigation" do
    context "When on the home page" do
        before { visit "/" }

        scenario "I should see the navigation header" do
            expect(page).to have_selector("div.navigation")
        end
    end
end

spec/spec_helper.rb

require 'capybara/rspec'
like image 891
dpdawson Avatar asked Oct 31 '13 19:10

dpdawson


1 Answers

For anyone who may run into a similar issue in the future, I forgot to include require 'spec_helper' in the feature spec (like an idiot).

like image 196
dpdawson Avatar answered Oct 14 '22 03:10

dpdawson