Reputation: 21
Hi I am working on Daniel Kehoe's Rspec Tutorial. Everything went fine until I created the file spec/features/visitor/home_page_spec.rb . When I put the following test code in it
# Feature: Home Page
# As a visitor
# I want to visit a home page
# So I can learn more about the website
feature 'Home Page' do
# Scenario: Visit the Home Page
# Given I am a visitor
# When I visit the home page
# Then I should see "Welcome"
scenario 'Visit the Home Page' do
visit root_path
expect(page).to have_content 'Welcome'
end
end
and run rspec spec/features/visitor/home_page_spec.rb from the terminal, I got the error below. I get that the method was not defined but Daniel's tutorial just tells you to put the code in the folder above. Guess I am missing something. Thank you
rails-bootstrap/spec/features/visitor/home_page_spec.rb:7:in `<top (required)>':
undefined method `feature' for main:Object (NoMethodError)
Upvotes: 2
Views: 382
Reputation: 1281
The only way I get rake test to run is to add the below require to test/integration/home_page_test.rb
require 'minitest/rails/capybara'
This line is already in test/test_helper.rb so I'm not sure why it isn't picking it up. I also tried adding the .rspec file with the options suggested by Daniel. If nothing else works, try that.
Upvotes: 0
Reputation: 10952
What's in your .rspec file in the project directory? You should have:
--color
--format documentation
--require spec_helper
--require rails_helper
If the .rspec file is set up properly, you will not need additional require
statements in your spec files.
Upvotes: 2