Module: Saharspec::Its::Call

Defined in:
lib/saharspec/its/call.rb

Instance Method Summary collapse

Instance Method Details

#its_call(*options, &block) ⇒ Object

Creates nested example which converts current subject to a block-subject.

Examples:


subject { calc_something(params) }

# without its_call
context 'with this params'
  it { expect { subject }.to change(some, :value).by(1) }
end

context 'with that params'
  it { expect { subject }.to raise_error(SomeError) }
end

# with its_call
context 'with this params'
  its_call { is_expected.to change(some, :value).by(1) }
end

context 'with that params'
  its_call { is_expected.to raise_error(SomeError) }
end

Parameters:

  • options

    Other options that can be passed to usual RSpec example.

  • block (Proc)

    The test itself. Inside it, is_expected (or are_expected) is analog of expect { subject }.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/saharspec/its/call.rb', line 32

def its_call(*options, &block)
  # rubocop:disable Lint/NestedMethodDefinition
  describe('call') do
    let(:__call_subject) do
      -> { subject }
    end

    def is_expected
      expect(__call_subject)
    end

    example(nil, *options, &block)
  end
  # rubocop:enable Lint/NestedMethodDefinition
end