Optional parameter in cucumber

前端 未结 2 1854
有刺的猬
有刺的猬 2020-12-16 11:25

I have a step definition in which I\'d like to have an optional parameter. I believe an example of two calls to this step explains better than anything else what I\'m after

2条回答
  •  臣服心动
    2020-12-16 11:35

    optional.feature:

    Feature: Optional parameter
    
      Scenario: Use optional parameter
        When I check the favorite color count
        When I check the favorite color count for email address 'john@anywhere.com'
    

    optional_steps.rb

    When /^I check the favorite color count(?: for email address (.*))?$/ do |email|
      email ||= "default@domain.com"
      puts 'using ' + email
    end
    

    output

    Feature: Optional parameter
    
      Scenario: Use optional parameter
        When I check the favorite color count
          using default@domain.com
        When I check the favorite color count for email address 'john@anywhere.com'
          using 'john@anywhere.com'
    
    1 scenario (1 passed)
    2 steps (2 passed)
    0m0.047s
    

提交回复
热议问题