Module: PadlockAuth::Matchers

Defined in:
lib/padlock_auth/rspec_support.rb

Overview

This module provides matchers for testing PadlockAuth access_token and strategy classes.

In your implementations, use these shared examples to ensure that your classes are compliant with the PadlockAuth API.

Examples:

require "padlock_auth/rspec_support"

RSpec.describe MyAccessToken do
  it { is_expected.to be_a_padlock_auth_access_token }
end
require "padlock_auth/rspec_support"

RSpec.describe MyStrategy do
  it { is_expected.to be_a_padlock_auth_strategy }
end

Instance Method Summary collapse

Instance Method Details

#be_a_padlock_auth_access_tokenRSpec::Matchers::BuiltIn::BaseMatcher

Asserts that the subject matches the expected interface for a PadlockAuth access token.

Returns:

  • (RSpec::Matchers::BuiltIn::BaseMatcher)


25
26
27
28
29
30
31
# File 'lib/padlock_auth/rspec_support.rb', line 25

def be_a_padlock_auth_access_token
  respond_to(:acceptable?).with(1).arguments
    .and(respond_to(:accessible?).with(0).arguments)
    .and(respond_to(:includes_scope?).with(1).arguments)
    .and(respond_to(:invalid_token_reason).with(0).arguments)
    .and(respond_to(:forbidden_token_reason).with(0).arguments)
end

#be_a_padlock_auth_strategyRSpec::Matchers::BuiltIn::BaseMatcher

Asserts that the subject matches the expected interface for a PadlockAuth strategy.

Returns:

  • (RSpec::Matchers::BuiltIn::BaseMatcher)


37
38
39
40
41
# File 'lib/padlock_auth/rspec_support.rb', line 37

def be_a_padlock_auth_strategy
  respond_to(:build_access_token).with(1).arguments
    .and(respond_to(:build_invalid_token_response).with(1).arguments)
    .and(respond_to(:build_forbidden_token_response).with(2).arguments)
end