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