我试图写一个破坏的测试并摔倒了一个试图让rspec看到我的覆盖的兔子洞。我故意提出错误,以便我注意到它。当我运行rails server
时,此代码在开发模式中成功引发错误。
class Devise::Extends::SessionsController < Devise::SessionsController
before_filter :log_logout, only: :destroy
after_filter :log_failed_login, only: [:new, :create]
def create
raise 'create'
super do |user|
# special stuff to go here
end
end
end
我正在设置devise.mapping
并尝试使用和不使用@
。
describe LicenseesController do
context 'viewing existing Licensee' do
let(:other_licensee) { FactoryGirl.create(:licensee) }
context 'as licensee_user for Licensee' do
# For own Licensee
# allows show
# disallows index, new, edit, create, delete, update
# For another Licensee
# returns not authorized
let(:user) { FactoryGirl.create(:licensee_user, :confirmed) }
before(:each) do
@request.env['devise.mapping'] = Devise.mappings[:user]
sign_in user
end
describe "GET show" do
it "assigns the requested licensee as @licensee" do
get :show, {:id => user.licensee.to_param}, valid_session
assigns(:licensee).should eq(user.licensee)
end
it "rejects trying to show another Licensee" do
expect do
get :show, {:id => other_licensee.to_param}, valid_session
end.to raise_exception(CanCan::AccessDenied)
end
end
# more tests
# This should return the minimal set of attributes required to create a valid
# Licensee. As you add validations to Licensee, be sure to
# adjust the attributes here as well.
let(:valid_attributes) { FactoryGirl.attributes_for(:licensee) }
let(:wsu_attributes) { FactoryGirl.attributes_for(:web_service_user) }
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# LicenseesController. Be sure to keep this updated too.
let(:valid_session) { {} }
context 'as superuser' do
before(:each) { sign_in user }
let(:user) { FactoryGirl.create(:superuser, :confirmed) }
describe "GET index" do
it "assigns all licensees as @licensees" do
licensee = Licensee.create! valid_attributes
get :index, {}, valid_session
assigns(:licensees).should eq([licensee])
end
end
end
在routes.rb
我有:
devise_for :users, controllers: { sessions: 'devise/extends/sessions' }
我是否遗漏了一些显而易见的事情需要让它发挥作用?它通过cucumber
测试以交互方式引发错误,但rspec
测试似乎完全跳过了覆盖并且所有测试都通过了。