How to test shared contexts

15 views
Skip to first unread message

Samuel Williams

unread,
May 21, 2017, 10:44:05 PM5/21/17
to rspec
I'd like to make a gem, which includes several `RSpec.shared_context` definitions. These are useful for other gems which share the same testing environment but do different things, to use the same shared examples/contexts.

However, I'd also like to test that my shared contexts are doing the right thing. In some cases, they simply ensure that some stuff has been set up correctly. In other cases, they check pre- and post- invariants.

1/ What is the best way to make a gem containing shared contexts/examples

2/ In the gem that's making these available, what's the best way to test them? I'm assuming... I'm going to write a test case and, then, another test case which invokes the first test case. In the case of setup, I'd like to ensure that the given `let` variables exist, and in the case of the invariant check, to detect success/failure, and confirm that the invariant is firing correctly.

Thanks for any help/input.

Jon Rowe

unread,
May 22, 2017, 1:47:21 AM5/22/17
to rs...@googlegroups.com
> 1/ What is the best way to make a gem containing shared contexts/examples

You’re probably going to want to create a bunch of modules that define the shared examples when included, the benefit of this is that it will allow you to control which scopes they are defined in without risking stomping over any existing examples at the top level.

For 2) I’d just test the shared examples in the gems own test suite, given whatever context they should pass, you could use the `pending` flag for contexts that are expected to fail. If you wanted to go fully comprehensive you’ll need to go down the smoke test / sand boxed route with running the suites within rspec itself, you can see how we’ve done this in the main test suites but its a lot more complex.

Cheers
Jon Rowe
---------------------------

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/fa5dd6e0-4008-4bfc-a760-855bd3b0502c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages