我的项目中测试环境为:
group :development, :test do
gem 'rspec-rails', '2.13.1'
gem 'capybara', '2.1.0'
end
rake routes:
Prefix Verb URI Pattern Controller#Action
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
root GET / static_pages#home
help GET /help(.:format) static_pages#help
about GET /about(.:format) static_pages#about
contact GET /contact(.:format) static_pages#contact
signup GET /signup(.:format) users#new
signin GET /signin(.:format) sessions#new
signout DELETE /signout(.:format) sessions#destroy
测试文件:static_pages_spec.rb
require 'spec_helper'
describe "StaticPages" do
describe "Home Page" do
it "should have the content 'Sample App'" do
visit signup_path
expect(page).to have_content('Sample App')
end
end
end
运行:rspec static_pages_spec.rb 报错:
Failures:
1) StaticPages Home Page should have the content 'Sample App'
Failure/Error: visit signup_path
NameError:
undefined local variable or method `signup_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa49a3a4>
# ./static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
Finished in 0.00196 seconds
1 example, 1 failure
Failed examples:
rspec ./static_pages_spec.rb:7 # StaticPages Home Page should have the content 'Sample App'
Randomized with seed 47907