Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 313949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:09:19+00:00 2026-05-12T08:09:19+00:00

I am working on some Cucumber stories for a ‘sign up’ application which has

  • 0

I am working on some Cucumber stories for a ‘sign up’ application which has a number of steps.

Rather then writing a Huuuuuuuge story to cover all the steps at once, which would be bad, 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.

I’m aware of being able to access controller.session[..] 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…):

Using controller.session[:whatever] or session[:whatever]

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.session (NoMethodError)

Using session(:whatever)

wrong number of arguments (1 for 0) (ArgumentError)

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..):

  1. Mock out the session store etc
  2. Have a method within the controller and stub that out (e.g. get_registration which assigns an instance variable…)

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…

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)…

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?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:09:19+00:00Added an answer on May 12, 2026 at 8:09 am

    mocks are bad in cucumber scenarios – they’re almost kind of an antipattern.

    My suggestion is to write a step that actually logs a user in. I do it this way

    Given I am logged in as "auser@example.com"
    
    Given /^I am logged in as "(.*)"$/ do |email|
      @user = Factory(:user, :email => email)
      @user.activate!
      visit("/session/new")
      fill_in("email", :with => @user.email)
      fill_in("password", :with => @user.password)
      click_button("Sign In")
    end
    

    I realize that the instance variable @user is kind of bad form—but I think in the case of logging in/out, having @user is definitely helpful.

    Sometimes I call it @current_user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When working with some open source projects (in my case Joomla and Moodle), I've
I have been working on some legacy C++ code that uses variable length structures
I'm working on some production software, using C# on the .NET framework. I really
I'm working on some code to colorize an image in Java. Basically what I'd
I am working with some CSS that is poorly written to say the least.
I'm working on some code that uses the System.Diagnostics.Trace class and I'm wondering how
I'm working on some code for a loosely coupled cluster. To achieve optimal performance
I'm working with some code that is confusing me and I'm wondering if I'm
I am working with some input that is in the possible forms $1,200 20
I'm working through some homework and a question on a previous exam paper asks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.