Module: OmniAuth::Test::StrategyTestCase

Defined in:
lib/omniauth/test/strategy_test_case.rb

Overview

Support for testing OmniAuth strategies.

Examples:

Usage

class MyStrategyTest < Test::Unit::TestCase
  include OmniAuth::Test::StrategyTestCase
  def strategy
    # return the parameters to a Rack::Builder map call:
    [MyStrategy, :some, :configuration, :options => 'here']
  end
  setup do
    post '/auth/my_strategy/callback', :user => { 'name' => 'Dylan', 'id' => '445' }
  end
end

Instance Method Summary collapse

Instance Method Details

#appObject



20
21
22
23
24
25
26
27
28
# File 'lib/omniauth/test/strategy_test_case.rb', line 20

def app
  strat = strategy
  resp = app_response
  Rack::Builder.new do
    use(OmniAuth::Test::PhonySession)
    use(*strat)
    run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [resp || env.key?('omniauth.auth').to_s]] }
  end.to_app
end

#app_responseObject



30
31
32
# File 'lib/omniauth/test/strategy_test_case.rb', line 30

def app_response
  nil
end

#sessionObject



34
35
36
# File 'lib/omniauth/test/strategy_test_case.rb', line 34

def session
  last_request.env['rack.session']
end

#strategyObject



38
39
40
41
# File 'lib/omniauth/test/strategy_test_case.rb', line 38

def strategy
  error = NotImplementedError.new('Including specs must define #strategy')
  raise(error)
end