jeudi 30 août 2018

Pass let parameter to shared context

I have a shared context and want to pass some variable outside to this shared example. I currently make it like this:

shared_context "test" do |param1, param2|
    before :each do
      puts "context:"
      puts param1
      puts param2
    end
  end

  describe 'test' do
    let(:name1) { "name_1" }
    include_context "test", name_1, "name_2"
    ...
  end

But I got error:

An error occurred while loading ./spec/car_spec.rb.
Failure/Error: include_context "test", name_1, "name_2"

NameError:
  undefined local variable or method `name_1' for RSpec::ExampleGroups::Car::Test:Class
  Did you mean?  name
                 name

It can't recognize the variable defined in let, how should I pass a variable defined outside of a shared context into it? Thanks!

Aucun commentaire:

Enregistrer un commentaire