[c++][cucumber-cpp] Calling Steps from Step Definitions

98 views
Skip to first unread message

Victor Emilio Armengol Fernandez

unread,
Feb 2, 2018, 3:54:56 AM2/2/18
to Cukes
Hi guys, In the ruby documentation you can call a step from a step definition with this:

Given /^(.*) is logged in$/ do |name|
  step
"the user #{name} exists"
  step
"I log in as #{name}"
end

What is the equivalent "step" function in cucumber-cpp ?

Thanks in advance.

Andrew Premdas

unread,
Feb 3, 2018, 10:21:07 AM2/3/18
to cu...@googlegroups.com
Though you can do this, I'd advise strongly against it. Instead call helper methods instead. So with your example

module UserStepHelper
  def create_user(name:)
     ...
   end
   
   def log_in(user:
      ...
    end
end
World UserStepHelper

Given 'the user #{name} exists' do |name|
   @user = create_user

Given /^(.*) is logged in$/ do |name|
  login_user(create_user(name: name)
end

Treat each step definition as a call to a helper method. (solving simply problem of matching scenario statements to step definitions). Then solve the problem of having  a single method call do alot of stuff in your programming language (programming languages are designed for this task)

And now your question becomes how do I create helper methods in Cucumber CPP. A question I hope someone else can answer (I don't use CPP)

All best

Andrew

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
------------------------
Andrew Premdas

Victor Emilio Armengol Fernandez

unread,
Feb 6, 2018, 11:47:01 AM2/6/18
to Cukes
Thanks, this looks a good solution to reuse some code, and seems the only one, I was looking for a way to have a try-catch step that could handle any other step, i.e.

GIVEN("^try (.*)$"){
    REGEX_PARAM(string, otherStep);
    try{
        UNKNOWN_CODE_TO_CALL_OTHER_STEP(otherstep);
    }catch(Exception e){ ... }


but it seems the only way should be to have to versions of each step, one with try and the other whitout it, and call the helper methods from each one.

To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages