2014-11-05 33 views
0

我已經使用了自定義設計失敗應用程序。使用rspec測試設計CustomFailure應用程序

class CustomFailure < Devise::FailureApp 
protected 
    def redirect_url 
     LOGIN_URL 
    end 

我使用默認故障應用程序,並根據環境變量的自定義應用程序失敗的。

我想用rspec測試這個功能。以下是我想在rspec的

If env['var'] = value 
    expect redirect_url to return 'hostname/customlogin/' 
else 
    expect redirect_url to return 'hostname/sign_in/' 

做的,但問題是,只有當我已經設置ENV [「變種」] CustomeFailure應用會存在。

if ENV["var"] == value 
    config.warden do |manager| 
     manager.failure_app = CustomFailure 
    end 
end 

那麼我該如何測試呢?

回答

0

我能夠爲此場景編寫測試用例。這不是我想要的正確行爲,但我可以繼續這一點。

require 'rails_helper' 
describe CustomFailure do 
    describe '.redirect_url' do 
     let(:expected_result) { 'hostname/customlogin' } 
     it 'returns the login url' do 
      @custom = CustomFailure.new 
      expect(@custom.send(:redirect_url)).to eq(expected_result) 
     end 
    end 
end