Note that there are some explanatory texts on larger screens.

plurals
  1. POSession variables with Cucumber Stories
    primarykey
    data
    text
    <p>I am working on some Cucumber stories for a 'sign up' application which has a number of steps.</p> <p>Rather then writing a Huuuuuuuge story to cover all the steps at once, which would be <em>bad</em>, I'd rather work through each action in the controller like a regular user. My problem here is that I am storing the account ID which is created in the first step as a session variable, so when step 2, step 3 etc are visited the existing registration data is loaded.</p> <p>I'm aware of being able to access <code>controller.session[..]</code> within RSpec specifications however when I try to do this in Cucumber stories it fails with the following error (and, I've also read somewhere this is an anti-pattern etc...):</p> <p><em>Using controller.session[:whatever] or session[:whatever]</em></p> <pre><code>You have a nil object when you didn't expect it! The error occurred while evaluating nil.session (NoMethodError) </code></pre> <p><em>Using session(:whatever)</em></p> <pre><code>wrong number of arguments (1 for 0) (ArgumentError) </code></pre> <p>So, it seems accession the session store isn't really possible. What I'm wondering is if it might be possible to (and I guess which would be best..):</p> <ol> <li>Mock out the session store etc</li> <li>Have a method within the controller and stub that out (e.g. <code>get_registration</code> which assigns an instance variable...)</li> </ol> <p>I've looked through the RSpec book (well, skimmed) and had a look through WebRat etc, but I haven't really found an answer to my problem...</p> <p>To clarify a bit more, the signup process is more like a state machine - e.g. the user progresses through four steps before the registration is complete - hence 'logging in' isn't really an option (it breaks the model of how the site works)...</p> <p>In my spec for the controller I was able to stub out the call to the method which loads the model based on the session var - but I'm not sure if the 'antipattern' line also applies to stubs as well as mocks?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload