RSpec を実行すると、次の 4 つのエラーが表示されます。
undefined local variable or method `signin_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x4203fa8>
しかし、このヘルパーとパスを問題なく使用する他のテストを実行しています。それで機能しないのは、リレーションシップ コントローラー テストのみです。
relationship_controller_spec.rb
require 'spec_helper'
describe RelationshipsController do
let(:user) { FactoryGirl.create(:user) }
let(:other_user) { FactoryGirl.create(:user) }
before { sign_in user }
describe "creating a relationship with Ajax" do
it "should increment the Relationship count" do
expect do
xhr :post, :create, relationship: { followed_id: other_user.id }
end.to change(Relationship, :count).by(1)
end
it "should respond with success" do
xhr :post, :create, relationship: { followed_id: other_user.id }
response.should be_success
end
end
describe "destroying a relationship with Ajax" do
before { user.follow!(other_user) }
let(:relationship) { user.relationships.find_by_followed_id(other_user) }
it "should decrement the Relationship count" do
expect do
xhr :delete, :destroy, id: relationship.id
end.to change(Relationship, :count).by(-1)
end
it "should respond with success" do
xhr :delete, :destroy, id: relationship.id
response.should be_success
end
end
end
ユーティリティ.rb:
def sign_in(user)
visit signin_path
fill_in 'Email', with: user.email.upcase
fill_in 'Password', with: user.password
click_button 'Sign In'
cookies[:remember_token] = user.remember_token
end
ルート.rb:
resources :users do
member do
get :following, :followers
end
end
resources :sessions, only: [:create, :destroy, :new]
resources :microposts, only: [:create, :destroy]
resources :relationships, only: [:create, :destroy]
# Application Root
root to: 'static_pages#home'
# Static Pages
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
# Users
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete