Sometimes I would like to use one shared examples in different controller actions, but how to share failed state where we are checking either user authenticated or not? Today I found out a pretty neat way of test suite organization using rspec shared examples. Let’s assume that we have a controller where non-authenticated user should be redirected to sign_in_path, and devise gem, for example, provides for us pretty good implementation of action before_action callback. How can I provide shared example for this case? Looking for some examples I found out a great idea of passing block to shared example group with distinct implementation of setup stage for any special context. In my example it would look like this:
and for our rspec controller we do something like this:
As you see we defined make_request method in context of shared example.