Module: CulpaHelpers
- Defined in:
- lib/culpa/test_helpers.rb
Defined Under Namespace
Classes: BrickCall
Instance Method Summary collapse
-
#call_brick(brick_name) ⇒ Object
Helper to call a brick.
-
#have_body ⇒ Object
expect(last_call).to have_body({a: ‘a’ … }) (Can be a JSON or anything else).
-
#have_envelope ⇒ Object
expect(last_call).to have_envelope({a: ‘a’ … }).
-
#have_headers ⇒ Object
expect(last_call).to have_headers({‘X-Header-1’ => ‘ASD’ .… }).
-
#have_status ⇒ Object
expect(last_call).to have_status(:i_am_a_teapot).
-
#last_call ⇒ Object
Helper to access the result of the last call.
Instance Method Details
#call_brick(brick_name) ⇒ Object
Helper to call a brick
15 16 17 |
# File 'lib/culpa/test_helpers.rb', line 15 def call_brick(brick_name) @@last_call = BrickCall.new(brick_name) end |
#have_body ⇒ Object
expect(last_call).to have_body({a: ‘a’ … }) (Can be a JSON or anything else)
87 88 89 90 91 92 93 |
# File 'lib/culpa/test_helpers.rb', line 87 RSpec::Matchers.define :have_body do |expected| match do |actual| actual.from(described_class) unless actual.from_done || described_class.nil? bc = actual.call bc[:to_render][:object] == expected end end |
#have_envelope ⇒ Object
expect(last_call).to have_envelope({a: ‘a’ … })
97 98 99 100 101 102 103 |
# File 'lib/culpa/test_helpers.rb', line 97 RSpec::Matchers.define :have_envelope do |expected| match do |actual| actual.from(described_class) unless actual.from_done || described_class.nil? bc = actual.call bc[:envelope] == Culpa::Envelope.new(expected) end end |
#have_headers ⇒ Object
expect(last_call).to have_headers({‘X-Header-1’ => ‘ASD’ .… })
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/culpa/test_helpers.rb', line 73 RSpec::Matchers.define :have_headers do |expected| match do |actual| expected.each do |k, _v| actual.from(described_class) unless actual.from_done || described_class.nil? bc = actual.call return false unless bc[:to_render][:headers].key?(k) && bc[:to_render][:headers][k] == expected[k] end true end end |
#have_status ⇒ Object
expect(last_call).to have_status(:i_am_a_teapot)
63 64 65 66 67 68 69 |
# File 'lib/culpa/test_helpers.rb', line 63 RSpec::Matchers.define :have_status do |expected| match do |actual| actual.from(described_class) unless actual.from_done || described_class.nil? bc = actual.call bc[:to_render][:status] == RendererDescriber::RETURN_CODES[expected] end end |
#last_call ⇒ Object
Helper to access the result of the last call
9 10 11 |
# File 'lib/culpa/test_helpers.rb', line 9 def last_call @@last_call end |