Module: Rspec::SideEffects

Defined in:
lib/rspec/side_effects.rb,
lib/rspec/side_effects/version.rb

Overview

This module will allow the side effects of RSpec examples to be written more clearly and consistently.

Constant Summary collapse

VERSION =
'0.3.0'

Instance Method Summary collapse

Instance Method Details

#its_side_effects_are(*options, &block) ⇒ Object Also known as: it_has_side_effects, specify_side_effects



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rspec/side_effects.rb', line 11

def its_side_effects_are(*options, &block)
  its_caller = caller.grep_v(/its_side_effects/)
  if options.last.is_a?(Hash)
    options.last.merge(called: its_caller)
  else
    options.push(called: its_caller)
  end

  describe('side effects', *options) do
    if block
      # rubocop:disable Lint/RescueException, Lint/SuppressedException
      before do
        subject
      rescue Exception
      end
      # rubocop:enable Lint/RescueException, Lint/SuppressedException
      example(nil, :aggregate_failures, *options, &block)
    else
      example(nil, {}) { subject }
    end
  end
end