문제

I am using RSpec/Capybara. I am writing shared examples in the same spec file. I want to place the shared examples after the feature as the shares examples are really long.

But if I place the shared examples below the feature, RSpec is complaining that it is not able to find the shared example. Is there any way to make it happen?

도움이 되었습니까?

해결책 2

a common practice is to define the code for your shared examples in a module and include it via the configuration. that way, you have a clear code separation and reuse.

in spec/support/xyz.rb

module SomeSharedExamples
  [...]
end

in your spec_helper.rb

config.include SomeSharedExamples

다른 팁

This question is a year old, but wanted to mention that rspecs shared examples are an alternative to using a normal module. Basically you define module ('concern') that can be included in any spec file using it_behaves_like "my_concern"

See this question for a good example of this in action.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top