Module: RSpecMagic::Stable::UseLetset

Defined in:
lib/rspec_magic/stable/use_letset.rb

Overview

Define a method to create let variables, which comprise a Hash collection.

describe do
  # Method is `let_a`. Collection is `attrs`.
  use_letset :let_a, :attrs

  # Declare `attrs` elements.
  let_a(:age)
  let_a(:name)

  subject { attrs }

  # None of the elements is set yet.
  it { is_expected.to eq({}) }

  # Set `name` and see it in the collection.
  context_when name: "Joe" do
    it { is_expected.to eq(name: "Joe") }

    # Add `age` and see both in the collection.
    context_when age: 25 do
      it { is_expected.to eq(name: "Joe", age: 25) }
    end
  end
end

When used with a block, let_a behaves like a regular let:

describe do
  use_letset :let_a, :attrs

  let_a(:age) { 25 }
  let_a(:name) { "Joe" }

  it { expect(attrs).to eq(name: "Joe", age: 25) }
end

Defined Under Namespace

Modules: Exports