0

我试图编写一个测试,该测试打破并掉进了试图让 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测试似乎完全跳过了覆盖并且所有测试都通过了。

4

0 回答 0