Optional parameter in cucumber

前端 未结 2 1855
有刺的猬
有刺的猬 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:40

    @larryq, you were closer to the solution than you thought...

    optional.feature:

    Feature: optional parameter
    
    Scenario: Parameter is not given
        Given xyz
        When I check the favorite color count
        Then foo
    
    Scenario: Parameter is given
        Given xyz
        When I check the favorite color count for email address 'john@anywhere.com'
        Then foo
    

    optional_steps.rb

    When /^I check the favorite color count( for email address \'(.*)\'|)$/ do |_, email|
        puts "using '#{email}'"
    end
    
    Given /^xyz$/ do
    end
    
    Then /^foo$/ do
    end
    

    output:

    Feature: optional parameter
    
    Scenario: Parameter is not given
        Given xyz
        When I check the favorite color count
            using ''
        Then foo
    
    Scenario: Parameter is given
        Given xyz                                                                   
        When I check the favorite color count for email address 'john@anywhere.com'
            using 'john@anywhere.com'
        Then foo                                                                    
    
    2 scenarios (2 passed)
    6 steps (6 passed)
    0m9.733s
    

提交回复
热议问题