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.2.0'.freeze

Instance Method Summary collapse

Instance Method Details

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



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

def its_side_effects_are(*options, &block)
  its_caller = caller.reject { |file_line| file_line =~ /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
      before do
        # rubocop:disable Lint/HandleExceptions, Lint/RescueException
        begin; subject; rescue Exception; end
        # rubocop:enable Lint/HandleExceptions, Lint/RescueException
      end
      example(nil, :aggregate_failures, *options, &block)
    else
      example(nil, {}) { subject }
    end
  end
end