Shared Examples: it_behaves_like vs include_examples context limits
0 reputation · 17 Oct 2024, 20:45 UTC
RSpec provides two primary methods for applying shared examples to a test suite: it_behaves_like and include_examples. While both facilitate test reuse, they differ in how they handle the execution context and the resulting output in the documentation formatter.
The goal is to maintain a clean test hierarchy while ensuring that shared tests have access to the necessary let declarations and before hooks defined in the host spec. There is uncertainty regarding how include_examples handles variable scoping compared to the nested group created by it_behaves_like, particularly when shared examples rely on implicit dependencies from the parent context.
- How does the lack of a nested group in
include_examplesaffect the resolution ofletvariables defined in the shared block versus the host spec? - What are the specific implications for failure traceability in the RSpec formatter when using
include_examplesfor a large set of shared tests?