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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:32:59+00:00 2026-05-25T03:32:59+00:00

We have some configuration issues that we would like to solve by putting in

  • 0

We have some configuration issues that we would like to solve by putting in “special constants” in Cucumber. For example, we would like anywhere that the text "__USER__" is used in a step, that should be replaced with the current user running the app (so that we can test things like user permissions).

The strategy I was trying to take toward this was to do something like this:

BeforeStep do |step|
    domain = get_domain()
    username = get_username()
    step.text.gsub("__USER__", "#{domain}/#{username}")
end

However, there is no BeforeStep. I tried to use Before do |scenario| ... end but the scenario didn’t have anything I could use on it. How can we replace instances of "__USER__" in our code with the user (and instances of "__CURRENT_DATE__" with the current date, etc.)?

  • 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-25T03:32:59+00:00Added an answer on May 25, 2026 at 3:32 am

    I think this is a case for writing more declarative steps such as When the user logs in as opposed to such things as When I fill in "txt_user_name" with "fred". It would be easy to write your step definition in that case:

    When /^the user logs in$/ do
        domain = get_domain()
        username = get_username()
        fill_in "txt_user_name", :with => "#{domain}/#{username}"
    end
    

    You could even bring in a step argument transform to turn the text ‘the user’ into the username you need, so you don’t have to repeatedly make the change:

    CAPTURE_USER = Transform /^(the user)$/ do |this_isnt_used|
        domain = get_domain()
        username = get_username()
        "#{domain}/#{username}"
    end
    
    When /^(#{CAPTURE_USER }) logs in$/ do |user_name|
        puts "Logging in as #{user_name}"
    end
    

    This would match the step Given the user logs in and pass in the correct user name as a parameter.

    Also, looking back at your question, you could use a transform to accomplish exactly what you were trying to do and have it replace instances of __USER__, but I wouldn’t choose that option myself – it feels like it would impact the readability of the scenario too much. Your choice though!

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

Sidebar

Related Questions

I have some configuration data that I'd like to model in code as so:
I have some configuration data in a config file that I read off disk
I have a project where there are multiple applications that have some common configuration
I have some values in a configuration file (XML file) with some values like
I have some business objects which use: Web.Configuration.WebConfigurationManager.AppSettings.Item(SomeSetting) Now that I'm breaking those objects
I have a project that requires some configuration files. I want to keep the
I have an application that takes some input and generates configuration files as output.
I have some configuration values for an asp.net web app. They will be maintained
I am working on a small AIR desktop application and I have some configuration
I have added some settings to my c# application using the configuration editor. There

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.