Module: ActionFigure::Testing

Defined in:
lib/action_figure/testing/statuses.rb,
lib/action_figure/testing/rspec.rb,
lib/action_figure/testing/minitest.rb,
sig/action_figure.rbs

Overview

Helpers shared by the Minitest and RSpec testing adapters.

Defined Under Namespace

Modules: Minitest, RSpec

Constant Summary collapse

SUCCESS_STATUSES =

Success-only statuses (Ok, Created, Accepted, NoContent).

Returns:

  • (Hash[Symbol, Symbol])
{
  Ok: :ok,
  Created: :created,
  Accepted: :accepted,
  NoContent: :no_content
}.freeze

Class Method Summary collapse

Class Method Details

.contract_for(action_class) ⇒ Object

Resolves an action class's validation contract (RSpec adapter helper).

Parameters:

  • action_class (Object)

Returns:

  • (Object)


28
29
30
31
32
33
34
# File 'lib/action_figure/testing/statuses.rb', line 28

def self.contract_for(action_class)
  contract = action_class.contract
  return contract if contract

  raise ArgumentError,
        "#{action_class} defines no params_schema, so it has no contract to validate against"
end

.define_error_helper(name, status) ⇒ void

This method returns an undefined value.

Defines assert_/refute_ and be_ helpers for a dynamically registered status.

Parameters:

  • name (Symbol)
  • status (Symbol)


41
42
43
44
# File 'lib/action_figure/testing/statuses.rb', line 41

def self.define_error_helper(name, status)
  Minitest.define_status_assertions(name, status) if const_defined?(:Minitest, false)
  RSpec.define_status_matcher(name, status) if const_defined?(:RSpec, false)
end

.statusesHash[Symbol, Symbol]

Live map of status-helper names to status symbols: success statuses plus every registered error status.

Returns:

  • (Hash[Symbol, Symbol])


22
23
24
# File 'lib/action_figure/testing/statuses.rb', line 22

def self.statuses
  SUCCESS_STATUSES.merge(ActionFigure.error_statuses)
end