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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:17:28+00:00 2026-05-20T13:17:28+00:00

So this is a really newby question. I have a step that looks like

  • 0

So this is a really newby question.

I have a step that looks like this:

Then /^I should see ((phrase 1) | (phrase 2))$/ do
  #stuff
end

After that, I have a step that looks like this:

Then /^I should see phrase 3$/ do
  And %{I should see phrase 2}
end

I’m trying to test a registration flow.

phrase 1 describes the required information that needs to be filled out and I need to verify that they show up the in the user’s profile.

phrase 3 describes the required and optional information the user fills out. The optional information should aslo show up in the user’s profile and I wanna test that that also shows up.

I don’t want to copy and paste the stuff from the first step, so I re-phrased phrase 1 so that it makes sense to be called from the phrase 3 step, but I don’t know how to properly refer to it in the first step to get it to work. All I get from Cucumber is that I should see phrase 2 is undefined.

What’s the right way to get this work? Is there a better way to accomplish my goal?

  • 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-20T13:17:29+00:00Added an answer on May 20, 2026 at 1:17 pm

    Whitespace characters are very important in regex’s

    With whitespace at either end of the pipe you need to use this step:

    Then %{I should see phrase 1 }
    

    or

    Then %{I should see  phrase 2}
    

    (Note that extra space at the end on the first one, and between see and phrase2 on the second one). The regex is still looking for those space characters where you specified them to be.

    Your regex would need to be changed to:

    Then /^I should see (phrase 1|phrase 2)$/ do |phrase_name|
    
    end
    

    The | symbol in regex will match either all characters on the left side, or all characters on the right side (the parantheses of course bounds it so it doesn’t take the entire string).

    Also you have to pass the value to your block, as I did with phrase_name when you use parenthesis in this manner. Although I would probably rather see the step defined this way:

    Then /^I should see phrase ([\d]+)$/ do |phrase_number|
    
    end
    

    So that it will match for all three of your phrase types, and you wouldn’t need the phrase 1 definition anymore. [\d]+ will match any numerical character 1 or more times.

    Then you can do whatever you need to do based on the phrase_number that was sent. I’d be interested to see your scenario definition though, I’m not sure if you’re going about cuking it correctly based on this information. Maybe I could get some context if I saw the rest of the story.

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

Sidebar

Related Questions

This is a kind of a newb question but I'm really new to programming
This really, really urks me, so I hope that someone can give me a
This really seems like a bug to me, but perhaps some databinding gurus can
I've got this really simple piece of code that I thought was the correct
I've been having this really annoying thing happen the past few days, that has
I have a (Postgres) DB table that I'd like to add a manual 'sort'
I would like to sync my db (tasks on my db, that have a
Im learning javascript right now, so this might be a really newb question! I
I didn't find much in tutorials on this specific question.. So I have a
Sorry if this has been asked before or it's a really dumb question, but

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.