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

  • SEARCH
  • Home
  • 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 265649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:47:18+00:00 2026-05-11T22:47:18+00:00

I am trying to do some Cucumber testing like the following: Given I am

  • 0

I am trying to do some Cucumber testing like the following:

Given I am logged in as admin
When I go to the article page
Then I should see "Edit Article"
And I should see "Article Title"

where the path to the article page is “articles/1” or some known id.The problem is that when I insert my data using my step definition

Article.create(:name => "Article Title")

I can’t know ahead of time what the id will be when the record is inserted.

Essentially, I either need

a) to be able to insert predictable ids. I’ve tried the method mentioned in the answer of this question but it doesn’t seem to work for me – it always inserts a different id.

or

b) write my cucumber steps in such a way that I can pass in a parameter for my Article id

All Cucumber tutorials I’ve seen sort of gloss over this type of scenario – it’s always going to the list of all Articles or whatever, never a specific detail page.

Any help would be appreciated. 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-11T22:47:18+00:00Added an answer on May 11, 2026 at 10:47 pm

    There are two ways to create predictable ID values. The first is to manually set the ID on create:

    model = Model.new(options)
    model.id = DESIRED_ID
    model.save
    

    The catch here is that options passed to either new, create, or update_attributes will not affect the id value which is why the call to model.id is, unfortunately, required.

    An alternative is to reset the whole table before running your tests. This can be altered to account for fixtures if required. For example:

    class Model < ActiveRecord::Base
      def self.reset!
        connection.execute("DELETE FROM #{table_name}")
        connection.execute("ALTER TABLE #{table_name} AUTO_INCREMENT=1")
      end
    end
    

    This will set the ID of the first row inserted to be a predictable 1.

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

Sidebar

Related Questions

I am trying to create some cucumber features with references to other objects. I
I've been trying to debug some super slow performance in running my cucumber features.
I’m thinking about trying some development for the iPhone, is it possible to install
I'm trying some of the ASP.NET MVC tutorials and one of them has the
I'm a beginner C++ programmer, and to stretch my mind I've been trying some
I've started with ASP.NET MVC recently, reading blogs, tutorials, trying some routes, etc. Now,
I have just started learning Erlang and am trying out some Project Euler problems
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Hey having some trouble trying to maintain transparency on a png when i create
When trying to link some well established tools to my company's active directory, I

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.