Module: Saharspec::Metadata::Lets

Defined in:
lib/saharspec/metadata/lets.rb

Overview

Is included in contexts and describes that have lets: Hash defined, as a shortcut to define simple lets in a simple one-line way:

let(:user) { create(:user, role: role) }

# before: a lot of code to say simple things:
context 'when admin' do
  let(:role) { :admin }

  it { is_expected.to be_allowed }
end

context 'when user' do
  let(:role) { :user }

  it { is_expected.to be_denied }
end

# after
context 'when admin', lets: {role: :admin} do
  it { is_expected.to be_allowed }
end

context 'when user', lets: {role: :user} do
  it { is_expected.to be_denied }
end

# you can also give empty descriptions, then they would be auto-generated

# generates a context with description "with role=:admin"
context '', lets: {role: :admin} do
  it { is_expected.to be_allowed }
end