で作業しているときに、Railsルートが見つかりませんでしたか?rspec、capybara、guard、spork with rails 3.1.1およびruby 1.9 0.3上のOSXライオンRspec/Capybara、[Rails 3.1.1、Ruby 1.9.3]
I持って、次のテスト
context "As a signed in user" do
let(:user) { FactoryGirl.create(:user) }
before(:each) do
visit new_user_session_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
describe "creating categories" do
it "helps me to create a new category" do
# given
visit new_category_path
# when
fill_in "Name", with: 'Supermarket'
fill_in "Color", with: "#CCC"
click_button "New Category"
# then
current_path.should eq(categories_path)
page.should have_content("Category successfully created")
category = user.categories.last
category.name.should eq("Supermarket")
category.color.should eq("#CCC")
end
end
end
しかし、それが実行されるときに、私は次のようなエラーに取得
Categories As a signed in user creating categories helps me to create a new category
Failure/Error: visit new_category_path
NameError:
undefined local variable or method `new_category_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x007fff0dcdccb0>
しかしrake routes
コマンドの私の出力は
categories GET /categories(.:format) {:action=>"index", :controller=>"categories"}
POST /categories(.:format) {:action=>"create", :controller=>"categories"}
new_category GET /categories/new(.:format) {:action=>"new", :controller=>"categories"}
edit_category GET /categories/:id/edit(.:format) {:action=>"edit", :controller=>"categories"}
category GET /categories/:id(.:format) {:action=>"show", :controller=>"categories"}
PUT /categories/:id(.:format) {:action=>"update", :controller=>"categories"}
DELETE /categories/:id(.:format) {:action=>"destroy", :controller=>"categories"}
category_index GET /category/index(.:format) {:controller=>"category", :action=>"index"}
category_new GET /category/new(.:format) {:controller=>"category", :action=>"new"}
welcome_index GET /welcome/index(.:format) {:controller=>"welcome", :action=>"index"}
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
user_confirmation POST /users/confirmation(.:format) {:action=>"create", :controller=>"devise/confirmations"}
new_user_confirmation GET /users/confirmation/new(.:format) {:action=>"new", :controller=>"devise/confirmations"}
GET /users/confirmation(.:format) {:action=>"show", :controller=>"devise/confirmations"}
root / {:controller=>"welcome", :action=>"index"}
だから私は間違っているかわからない、それは私が誰かがこの問題で私を助けることができると思いますcategories_path
と同じエラーを持っているnew_user_session_path私は訪問をコメントアウトした場合は、ありがとう!
がところでここに私のspec_helper.rbだ
require 'rubygems'
require 'spork'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end
end
Spork.each_run do
# This code will be run each time you run your specs.
FactoryGirl.reload
end
# --- Instructions ---
# - Sort through your spec_helper file. Place as much environment loading
# code that you don't normally modify during development in the
# Spork.prefork block.
# - Place the rest under Spork.each_run block
# - Any code that is left outside of the blocks will be ran during preforking
# and during each_run!
# - These instructions should self-destruct in 10 seconds. If they don't,
# feel free to delete them.
#
されている必要があり、これが起こった理由を任意のアイデアをお持ちですか? – Geo
db:test:prepareは推奨されていません。 Railsのテストヘルパーはテストスキーマを自動的に管理します。詳しくは、リリースノートを参照してください。 – Jordan