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 993103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:22:02+00:00 2026-05-16T06:22:02+00:00

Rails3 app with Rspec2 and Cucumber Cucumber Given /^that a user is logged in$/

  • 0

Rails3 app with Rspec2 and Cucumber

Cucumber

Given /^that a user is logged in$/ do
  current_user = User.first
  render new_user_post_path(current_user)
end

Routes.rb

map.resources :users do |users|
  users.resources :posts, :collection => {:view => :get}
end

posts_controller_spec

describe PostsController do
  describe "#new" do
    it "should be successful" do
      get :new
      response.should be_success
    end
  end
end

My first big epic Fail

(::) failed steps (::)

No route matches {:controller=>"posts", :action=>"new"} (ActionController::RoutingError)
./features/step_definitions/tasklist_steps.rb:3:in `/^that a user is logged in$/'
features/tasklist.feature:7:in `Given that a user is logged in'

Failing Scenarios:
cucumber features/tasklist.feature:6 # Scenario: List SubmitLink

1 scenario (1 failed)
3 steps (1 failed, 2 skipped)
0m0.147s
rake aborted!

Sorry, I’m too newb. This is my first ever attempt at cucumber. 🙁

  • 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-16T06:22:03+00:00Added an answer on May 16, 2026 at 6:22 am

    Well first off map is deprecated in Rails 3 routes, you should probably have something like this.

    resources :users do 
        resources :posts
    end
    

    The way I normally write my givens, I follow the path that the user would actually take, create the user in the test db, and then actually going to the login page and signing in, so everything gets set correctly in the app.

    Given /^I have one user "([^\"]*)" with email "([^\"]*)" and password "([^\"]*)"$/ do |username,email, password|
      @user = User.new(:email => email,
                       :username=>username,
                       :password => password,
                       :password_confirmation => password)
       @user.save!
    end
    
    Given /^I am an authenticated user$/ do
      name = 'exmample'
      email = 'example@example.com'
      password = 'secret!'
    
      Given %{I have one user "#{name}" with email "#{email}" and password "#{password}"}
      And %{I go to the user login page}
      And %{I fill in "user_username" with "#{name}"}
      And %{I fill in "user_password" with "#{password}"}
      And %{I press "Sign in"}
    end
    

    I use it the following way:

    Feature: 
      In order to reboot my crappy/POS equipment without bothering the awesome Noc Monkeys
      I would like to login to a webpage and see the status of and control the outlets on my equipment
    
      Background: Valid and authenticated user with at least one outlet to control
        Given I am an authenticated user
    
      @ok
      Scenario: Viewing All outlets
        Given I am able to control an outlet with index "1"
        And I am on the home page
        Then I should see "server_1"
    

    Also, normally I don’t call render inside a cucumber step. Since you are working with a simulated browser (assuming webrat/capybara) you would visit path_to(page_name).

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

Sidebar

Related Questions

I recently installed the Rails3.1-Devise-Rspec-Cucumber Starter App with the Gemfile listed below. This created
I have a Rails 3 app that uses RSpec2 as my testing framework, and
So I'm writing my app doing feature-first BDD with Rails, Cucumber, RSpec. My client
Its a rails 2.3.5 app. I'm using the rspec and cucumber for testing. When
I have a rails app that I have serving up XML on an infrequent
I have a Rails app that I have successfully tested with Mongrel and Webkit.
I have a Rails app that I need to deploy. Here are the facts:
I'm developing a Rails app, and I was just talking with my colleague that
I am using selenium and Rails3 Rspec to do a test for an app
I'm using Rails 3.0.3, Rspec2 , Cucumber , Capybara How should a scenario look

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.