---
title: "cucumber test \u00a0小心得"
author: "夜鸣猪"
date: "2012-03-17T02:07:03Z"
tags: []
categories: ["编程语言"]
slug: "cucumber-test"
draft: false
lastmod: "2012-03-17T02:07:03Z"
id: 1455779
url: "https://hlee.iteye.com/blog/1455779"
---

最近，有时间在参考UC berkeley一个免费在线Ruby学习课程
<https://www.coursera.org/saas/class/index>
写了点Cucumber测试有些心得

```ruby

When /^I make all my stuff shiny$/
  step "I polish my first thing"
end

When /^I make all my stuff shiny$/
  steps %Q{
    When I polish my first thing
    When I shine my second thing
  }
end

```

如果有如下的类似错误，是因为使用了steps

>     Then I should not see any movie            # features/step_definitions/movie_steps.rb:22
>       Lexing error on line 1: 'I should not see "Aladdin"'. See http://wiki.github.com/cucumber/gherkin/lexingerror for more information. (Gherkin::Lexer::LexingError)


另外一个例子

```ruby

Feature: Test case

  As a cucumber user
  I want to crash MRI 1.9.3
  So I can provide a small failing test case

  Scenario: successfully crash MRI
    Given a nested task
    When I call another nested task
    Then everything fails
#==========================
require 'capybara'
require 'capybara/dsl'
require 'capybara-webkit'

Capybara.default_driver = :selenium
Capybara.app_host = 'http://www.google.com'

include Capybara::DSL

Given /^a nested task$/ do
  steps %Q{
    Given I call "first" nested task
    And "second" nested task
  }
end

When /^I call another nested task$/ do
  steps %Q{
    When I call subtask "1"
    And I call subtask "2"
    And "third" nested task
  }
end

Then /^everything fails$/ do
end

Given /^I call "([^"]*)" nested task$/ do |arg1|
  Kernel.puts "Nested task " + arg1
  visit '/'
end

Given /^"([^"]*)" nested task$/ do |arg1|
  Kernel.puts arg1 + " nested task"
end

When /^I call subtask "([^"]*)"$/ do |arg1|
  Kernel.puts "subtask " + arg1
end

```

错误提示

> Given a nested task             # step_definitions/test_steps.rb:10
>   Lexing error on line 4: ''. See http://wiki.github.com/cucumber/gherkin/lexingerror for more information. (Gherkin::Lexer::LexingError)
>   ./step_definitions/test_steps.rb:14:in `/^a nested task$/'
>   ./test_case.feature:8:in `Given a nested task'
> When I call another nested task # step_definitions/test_steps.rb:17
> Then everything fails           # step_definitions/test_steps.rb:25

一种解决办法重现编译1.9.3 with 
```java
CC=clang ./configure
```
 and  
```java
$ gem pristine ffi
```