Module: Jbr::Mocking

Included in:
Jbr
Defined in:
lib/jbr/mocking.rb

Overview

The switch an app under test throws to answer Jobber without a network. Touching #mock once turns every entry point below over to its Mock counterpart.

Instance Method Summary collapse

Instance Method Details

#create_oauth(params = {}) ⇒ OAuth

Returns credentials for the account that authorized the app.

Parameters:

  • params (Hash) (defaults to: {})

    the code and redirect_uri to exchange.

Returns:

  • (OAuth)

    credentials for the account that authorized the app.



12
13
14
# File 'lib/jbr/mocking.rb', line 12

def create_oauth(params = {})
  (@mock ? Mock::OAuth : OAuth).create(**params)
end

#mockMock

Returns the answers this process gives, created on first use.

Returns:

  • (Mock)

    the answers this process gives, created on first use.



6
7
8
# File 'lib/jbr/mocking.rb', line 6

def mock
  @mock ||= Jbr::Mock.new
end

#oauth_for(params = {}) ⇒ OAuth

Returns those credentials, ready to read and write with.

Parameters:

  • params (Hash) (defaults to: {})

    credentials already on file.

Returns:

  • (OAuth)

    those credentials, ready to read and write with.



24
25
26
# File 'lib/jbr/mocking.rb', line 24

def oauth_for(params = {})
  (@mock ? Mock::OAuth : OAuth).new(params)
end

#oauth_url_for(params = {}) ⇒ String

Returns the URL a Jobber user authorizes the app on.

Parameters:

  • params (Hash) (defaults to: {})

    the redirect_uri and state to come back with.

Returns:

  • (String)

    the URL a Jobber user authorizes the app on.



18
19
20
# File 'lib/jbr/mocking.rb', line 18

def oauth_url_for(params = {})
  (@mock ? Mock::URL : URL).for(**params)
end