module Saharspec::Its::Block

Public Instance Methods

is_expected() click to toggle source
# File lib/saharspec/its/block.rb, line 41
def is_expected
  expect(__call_subject)
end
its_block(*options, &block) click to toggle source

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

@example

subject { calc_something(params) }

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

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

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

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

@param options Options (metadata) that can be passed to usual RSpec example. @param block [Proc] The test itself. Inside it, `is_expected` is a synonom

for `expect { subject }`.
# File lib/saharspec/its/block.rb, line 34
def its_block(*options, &block)
  # rubocop:disable Lint/NestedMethodDefinition
  describe('as block') do
    let(:__call_subject) do
      -> { subject }
    end

    def is_expected
      expect(__call_subject)
    end

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