Sha256: 5fc078e156ab46243fe6fb61ed3da3d76448cec67493450b60f94415f00f6ff0

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

require 'rack'
require 'omniauth/test'

module OmniAuth
  
  module Test
    
    # Support for testing OmniAuth strategies.
    #
    # @example Usage
    #   class MyStrategyTest < Test::Unit::TestCase
    #     include OmniAuth::Test::StrategyTestCase
    #     def strategy
    #       # return the parameters to a Rack::Builder map call:
    #       [MyStrategy.new, :some, :configuration, :options => 'here']
    #     end
    #     setup do
    #       post '/auth/my_strategy/callback', :user => { 'name' => 'Dylan', 'id' => '445' }
    #     end
    #   end
    module StrategyTestCase
      
      def app
        strat = self.strategy
        resp = self.app_response
        Rack::Builder.new {
          use OmniAuth::Test::PhonySession
          use *strat
          run lambda {|env| [404, {'Content-Type' => 'text/plain'}, [resp || env.key?('omniauth.auth').to_s]] }
        }.to_app
      end
      
      def app_response
        nil
      end

      def session
        last_request.env['rack.session']
      end
      
      def strategy
        raise NotImplementedError.new('Including specs must define #strategy')
      end
      
    end
      
  end
  
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
oa-core-0.2.4 lib/omniauth/test/strategy_test_case.rb
oa-core-0.2.3 lib/omniauth/test/strategy_test_case.rb
oa-core-0.2.2 lib/omniauth/test/strategy_test_case.rb
oa-core-0.2.1 lib/omniauth/test/strategy_test_case.rb
oa-core-0.2.0 lib/omniauth/test/strategy_test_case.rb
oa-core-0.2.0.beta5 lib/omniauth/test/strategy_test_case.rb
oa-core-0.2.0.beta4 lib/omniauth/test/strategy_test_case.rb