employer_profiles_controller_spec.rb
it 'assigns the profile as @profile' do
profile = FactoryGirl.create(:employer_profile, :user_id => @user)
get :show, :user_id => @user
assigns(:employer_profile).should eq(profile)
end
route.rb
get '/employer_profiles/:user_id', to: 'employer_profiles#show'
我正在使用位于
的设计宏@user
登录规范中的login_user
module ControllerMacros
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
user = FactoryGirl.create(:user)
sign_in user
end
end
end
最后是错误
Failure/Error: get :show, :user_id => @user
ActionController::UrlGenerationError:
No route matches {:user_id=>nil, :controller=>"employer_profiles", :action=>"show"}
# ./spec/controllers/employer_profiles_controller_spec.rb:15:in `block (3 levels) in <top (required)>'
答案 0 :(得分:1)
首先,您已经无处定义@user
。所以,在帮助器中定义它
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
@user = FactoryGirl.create(:user)
sign_in @user
end
end
然后get
的参数的参数应该在哈希值内。
而不是
get :show, :user_id => @user
你需要
get :show, {:user_id => @user.id}