0
У меня есть этот код, который я хочу, чтобы повторно использовать в нескольких спецификаций:RSpec 3,5 передача аргумента shared_context
RSpec.shared_context "a UserWorker" do |user|
let(:mock_context_user) {{
id: 1,
brand: user.brand,
backend_token: user.backend_token
}}
before(:each) do
allow(SomeClass).to receive(:some_method)
.with(user.id).and_return(mock_context_user)
end
before(:each, context: true) do
Sidekiq::Testing.inline!
end
after(:each, context: true) do
Sidekiq::Testing.fake!
end
end
И в файле спецификации, которая использует общий код:
let(:user) { build :user } # FactoryGirl
...
describe '#perform' do
# some lets here
include_context 'a UserWorker', user
context 'when something exists' do
it 'does some stuff' do
# test some stuff here
end
end
end
Но что дает me this error:
/.rvm/gems/[email protected]/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:724:in `method_missing': `user` is not available on an example group (e.g. a `describe` or `context` block). It is only available from within individual examples (e.g. `it` blocks) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). (RSpec::Core::ExampleGroup::WrongScopeError)
Предложения? Любая помощь приветствуется.
Спасибо. Я закончил установку user_id в shared_context 'let! (: User_id) {rand (0..9)}' вместо того, чтобы передавать его, и спецификации прошли! – mmichael