jeudi 20 août 2015

How do I pass a variable two levels in a nested Rspec shared example?

Basically, I have a bunch of shared examples. I thought this would work, but I'm getting stack level too deep on the variable that's being passed.

shared_examples 'Foo' do
  # top level shared example passes values
  # to a lower-level shared example.
  it_behaves_like 'Bar' do
    let(:variable) { variable }
  end

  it_behaves_like 'Baz'
end

shared_examples 'Bar' do
  it { expect(variable).to veq('value')
end

the spec:

describe SomeClass do
  it_behaves_like 'Foo' do
    let(:variable) { 'value' }
  end
end

I thought shared examples kept their own context, why is this causing an issue?

Aucun commentaire:

Enregistrer un commentaire