Module: ActionFigure::Testing::RSpec

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

Overview

RSpec custom matchers: status matchers (be_Ok, ...), have_action_json, and the contract matchers accept_params / reject_params are registered globally via RSpec::Matchers.define and so are not module methods.

Class Method Summary collapse

Class Method Details

.define_status_matcher(name, status) ⇒ void

This method returns an undefined value.

Parameters:

  • name (Symbol)
  • status (Symbol)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/action_figure/testing/rspec.rb', line 21

def self.define_status_matcher(name, status)
  ::RSpec::Matchers.define :"be_#{name}" do
    match { |result| result.is_a?(Hash) && result[:status] == status }
    failure_message do |result|
      next "expected an ActionFigure result hash, got #{result.inspect}" unless result.is_a?(Hash)

      "expected result status to be #{status.inspect}, but got #{result[:status].inspect}"
    end
    failure_message_when_negated do
      "expected result not to have status #{status.inspect}"
    end
  end
end