let
is not available in the scope of the shared example group definition, but only in the example (it, specify, scenario) scope.
To pass cassette_name
to the shared examples, you can use a method argument instead of let
. Here's how you can modify your shared examples and usage:
RSpec.shared_examples 'a vehicle' do |opts|
use_vcr_cassette(opts[:cassette_name])
end
And then use it like this:
it_behaves_like 'a vehicle', cassette_name: 'models/truck' do
let(:factory_name) { :truck }
end
In this way, 'models/truck'
is passed as an argument to the shared example group and can be used directly.