The Cucumber Book的笔记(18)

>我来写笔记

按有用程度 按页码先后 最新笔记

  • 糖罐86

    糖罐86

    5.4 Nesting Steps Now, use Cucumber’s built-in steps method to call out to the original three steps in the body of your high-level step’s definition: Given /^I have authenticated with the correct PIN$/ do steps %{ And I have pushed my card into the slot And I enter my PIN And I press "OK" } end The %{ ... } construct is just a way to tell Ruby that you have ...

    2015-03-22 22:46

  • 糖罐86

    糖罐86

    Anchors You might have noticed that the step definition snippets that Cucumber prints for undefined steps start with a ^ and end with a $. Perhaps you’ve become so used to seeing them that you’ve stopped noticing them altogether. These two metacharacters are called anchors, because they’re used to tie down each end of the regular expression to the beginning and end of the string that they match...

    2015-03-08 22:22

  • 糖罐86

    糖罐86

    When /I (?:visit|go to) the homepage/ do # TODO: code goes here end Notice that we’ve had to prefix the list of alternates with another bit of regular expression magic. The ?: at the start of the group marks it as noncapturing, meaning Cucumber won’t pass it as an argument to our block.

    2015-03-08 22:18

  • 糖罐86

    糖罐86

    The question mark modifier means zero or one times

    2015-03-08 22:11

  • 糖罐86

    糖罐86

    That’s no good. To fix this, we can use the modifier, which means at least once: Given /I have deposited \$(\d ) in my Account/ do |amount| # TODO: code goes here end

    2015-03-08 21:45

  • 糖罐86

    糖罐86

    For a digit, you can use \d as a shorthand for [0-9]: Given /I have deposited \$(\d*) in my Account/ do |amount| # TODO: code goes here end Here are the most useful shorthand character classes: \d stands for digit, or [0-9]. \w stands for word character, specifically [A-Za-z0-9_]. Notice that underscores and digits are included but not hyphens. \s stands for whitespace character, specifically [ \...

    2015-03-08 21:45

  • 糖罐86

    糖罐86

    Given /I have deposited \$(.*) in my Account/ do |amount| # TODO: code goes here end The star modifier means any number of times. So, with .* we’re capturing any character, any number of times. Now we’re getting somewhere. This will defi- nitely allow us to capture all those different amounts.

    2015-03-08 21:29

  • 糖罐86

    糖罐86

    p46 The dot is a metacharacter, meaning it has magical powers in a regular expression. Literally, a dot means match any single character. So, we can try this instead: Given /I have deposited \$(...) in my Account/ do |amount| # TODO: code goes here end

    2015-03-08 21:22

  • 糖罐86

    糖罐86

    p46 There are a few different ways to specify a wildcard in a regular expression. One of the simplest is alternation, where we express different options separated by a pipe character |, like this: Given /I have deposited \$(100|250) in my Account/ do |amount| # TODO: code goes here end

    2015-03-08 21:19

  • 糖罐86

    糖罐86

    Any $ signs—including any letter or number following it—will be interpreted as an argument. This step definition uses an argument: Given "I have $amount in my Account" do |amount| end This step definition would match both of the following Gherkin steps: Given I have 100 in my Account Given I have $100 in my Account

    2015-03-08 21:00

<前页 1 2 后页>

笔记是你写在书页留白边上的内容;是你阅读中的批注、摘抄及随感。

笔记必须是自己所写,不欢迎转载。摘抄原文的部分应该进行特殊标明。

The Cucumber Book

>The Cucumber Book