我有这些用于测试控制器身份验证的 shared_examples_for 方法。
支持/控制器/authentication_helpers.rb
module ControllerHelpers
include Devise::TestHelpers
shared_examples_for 'authenticate user' do |user, method, action, url_params={}|
before(:each) do
setup_controller_for_warden
request.env["devise.mapping"] = Devise.mappings[:user]
end
it "should redirect visitors to login page" do
sign_out user
if method == :get
get action, url_params
elsif method == :post
post action, url_params
elsif method == :put
put action, url_params
elsif method == :delete
delete action, url_params
end
response.should redirect_to new_user_session_path
end
it "should allow user" do
sign_in user
if method == :get
get action, url_params
elsif method == :post
post action, url_params
elsif method == :put
put action, url_params
elsif method == :delete
delete action, url_params
end
response.should be_success
end
end
end
我想将它与我的控制器规范文件一起使用。
Brief_controller_spec.rb
require 'spec_helper'
describe BriefController do
render_views
before(:all) do
@customer=Factory(:customer)
@project=Factory(:project_started, :owner => @customer)
end
context 'get :new' do
it_behaves_like 'authenticate user', @customer, :get, :new, {:project_id => @project.to_param}
end
end
当我运行这些规范文件时,我遇到了错误
Failure/Error: sign_in user
RuntimeError:
Could not find a valid mapping for
你知道我该如何处理这个错误吗?