Sha256: 61eb7f24ae4b836a41940dcd1f4c67b8605daecbca472607edfa57b517245f0d

Contents?: true

Size: 1.56 KB

Versions: 20

Compression:

Stored size: 1.56 KB

Contents

##############################################################################
#                             OmniAuth Plugin
##############################################################################

begin
  require 'omniauth'
  require 'rspectacular/mock_authentications/omniauth'

  ###
  # Tell OmniAuth to just return whatever hash we want for each auth type
  #
  OmniAuth.configure do |config|
    config.test_mode            = true
    config.mock_auth[:facebook] = OmniAuth::MockAuthentications::Facebook.authentication
    config.mock_auth[:twitter]  = OmniAuth::MockAuthentications::Twitter.authentication
    config.mock_auth[:ebay]     = OmniAuth::MockAuthentications::Ebay.authentication
  end

  ###
  # Except we don't want OmniAuth to fake anything when doing live tests
  #
  RSpec.configure do |config|
    config.around(:each, :js => true) do |example|
      previous_omniauth_test_mode = OmniAuth.config.test_mode
      OmniAuth.config.test_mode   = false

      example.metadata.fetch(:mock_oauth, {}).each do |auth_type, auth_hash|
        OmniAuth.config.add_mock(auth_type, auth_hash)
      end

      example.run

      OmniAuth.config.test_mode = previous_omniauth_test_mode
    end

    config.before(:each, type: :controller, mock_oauth: lambda { |v| !!v }) do |example|
      if example.metadata[:mock_oauth].is_a? Symbol
        request.env['omniauth.auth'] = OmniAuth.config.mock_auth[example.metadata[:mock_oauth]]
      else
        request.env['omniauth.auth'] = OmniAuth::AuthHash.new(example.metadata[:mock_oauth])
      end
    end
  end
rescue LoadError
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rspectacular-0.62.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.61.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.60.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.59.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.58.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.57.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.56.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.55.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.54.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.53.1 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.53.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.52.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.51.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.50.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.49.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.48.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.47.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.46.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.45.0 lib/rspectacular/plugins/omniauth.rb
rspectacular-0.44.0 lib/rspectacular/plugins/omniauth.rb