2016-08-05 2 views
0

은 내가 여러 사양에 재사용 할이 코드가 shared_context하기 이 오류 :RSpec에 3.5 패스 인수는

/.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) 

제안 사항? 어떤 도움을 주셔서 감사합니다. 항상 같은 mock_context_user를 반환하기 때문에

답변

1

것은, 당신이 같은 더 일반적인 뭔가 시도 할 수 있습니다 :

allow(SomeClass) 
.to receive(:some_method) 
.with(an_instance_of(Fixnum)) 
.and_return(mock_context_user) 

을하지만 실제로 an_instance_of이 RSpec에 3.5 사용할 수 있는지 확실하지 않습니다, 그것은 RSpec에 3.3에 있습니다.

+0

감사합니다. shared_context'let! (: user_id) {rand (0..9)}'에서 user_id를 넘겨주는 대신에 지나치고 스펙이 넘어갔습니다! – mmichael