2011-08-01 66 views
0

我在使用黃瓜時遇到了一些問題。如何讓黃瓜獲得javascript?

這裏是我的樹狀

-- app1 
    |-- features 
    | |-- addition.feature 
    | |-- step_definitions 
    | `-- support 
    |  `-- env.js 
    |-- public 
    | `-- javascripts 
    |  |-- Player.js 
    |  `-- Song.js 
    |-- Rakefile 
    `-- spec 
     `-- javascripts 
      |-- helpers 
      | `-- SpecHelper.js 
      |-- PlayerSpec.js 
      `-- support 
       |-- jasmine_config.rb 
       |-- jasmine_runner.rb 
       `-- jasmine.yml 

這裏是我的文件 「addition.feature」

Feature: Addition 
    In order to avoid silly mistakes 
    As a math idiot 
    I want to be told the sum of two numbers 

    Scenario: Add two numbers 
    Given I have entered 50 into the calculator 
    And I have entered 70 into the calculator 
    When press add 
    Then the result should be 120 on the screen 

當我運行

黃瓜功能/ addition.feature

我得到

Feature: Addition 
    In order to avoid silly mistakes 
    As a math idiot 
    I want to be told the sum of two numbers 

    Scenario: Add two numbers      # features/addition.feature:6 
    Given I have entered 50 into the calculator # features/addition.feature:7 
    And I have entered 70 into the calculator # features/addition.feature:8 
    When press add        # features/addition.feature:9 
    Then the result should be 120 on the screen # features/addition.feature:10 

1 scenario (1 undefined) 
4 steps (4 undefined) 
0m0.003s 

You can implement step definitions for undefined steps with these snippets: 

Given /^I have entered (\d+) into the calculator$/ do |arg1| 
    pending # express the regexp above with the code you wish you had 
end 

When /^press add$/ do 
    pending # express the regexp above with the code you wish you had 
end 

Then /^the result should be (\d+) on the screen$/ do |arg1| 
    pending # express the regexp above with the code you wish you had 
end 

If you want snippets in a different programming language, just make sure a file 
with the appropriate file extension exists where cucumber looks for step definitions. 

爲什麼在Ruby語言的輸出,我是不應該得到的JavaScript,考慮到我在‘支持/’目錄「的.js」文件?

+0

我發現解決方案,寶石「therubyracer」失蹤。 謝謝邁克爾科佩爾 – michaelSc

回答

0

發現您可能感興趣的Cucumber.js。它是Cucumber到JavaScript的官方端口。

請記住,它仍然缺少黃瓜 - 紅寶石(背景,表格,標籤等)的幾個功能。

雖然你在這裏公開的場景應該對cucumber.js運行得很好。

-1

如果您使用Windows 10,則可以安裝CukeTest。只需在Windows Store中搜索CukeTest,即可自動編輯小黃瓜文件並生成JavaScript函數。

+0

OP有一個特定的問題,並找到了解決辦法。提供一個可以做類似的程序不會有幫助。 – Oleg