Module: Moarspec::Its::With

Defined in:
lib/moarspec/its/with.rb

Instance Method Summary collapse

Instance Method Details

#it_with(**lets, &block) ⇒ Object

Creates a nested context + example with ‘let` values defined from the arguments.

See also #its_block_with for a block form, and #instant_context for inline ‘context`+`let` definitions.

Examples:


subject { x + y }

it_with(x: 1, y: 2) { is_expected.to eq 3 }

# is equivalent to

context "with x=1, y=2" do
  let(:x) { 1 }
  let(:y) { 2 }

  it { is_expected.to eq 3 }
end


25
26
27
28
29
30
31
32
# File 'lib/moarspec/its/with.rb', line 25

def it_with(**lets, &block)
  context "with #{lets.map { "#{_1}=#{_2.inspect}" }.join(', ')}" do
    lets.each do |name, val|
      let(name) { val }
    end
    example(nil, &block)
  end
end