2011-06-07 161 views
14

我已經繼承了一個Rails(3)應用程序,並試圖抓住現有的黃瓜測試。我有在應用程序的「功能」文件夾下面的設置(我已經錯過了這是不相關的任何文件,如額外的功能和步驟)「耙」運行我所有的黃瓜測試罰款,但「黃瓜」沒有步驟

/features 
    /people 
    new-person.feature 
    /step_definitions 
    people_steps.rb 
    web_steps.rb 
    /support 
    env.rb 
    paths.rb 
    selectors.rb 

如果我運行「耙」,那麼它運行feature/people/new-person.feature中的所有功能,正確使用step_definitions中列出的步驟。

但是,我不想每次運行耙子,因爲它需要很長時間,我只想在黃瓜中運行特定的測試,例如, cucumber features/people/new-person.feature -l 8

當我這樣做,它運行該功能,但尚未加載的步驟。我回來了:

Using the default profile... 
Feature: Add a new person 
    In order to allocate tasks to people 
    As a community manager 
    I want to add a new person 

    Scenario: Secondary navigation should contain "Add new person" # features/people/new-person.feature:8 
    Given I am on the new person page       # features/people/new-person.feature:9 
     Undefined step: "I am on the new person page" (Cucumber::Undefined) 
     features/people/new-person.feature:9:in `Given I am on the new person page' 
    Then I should not see "Add new person"      # features/people/new-person.feature:10 
     Undefined step: "I should not see "Add new person"" (Cucumber::Undefined) 
     features/people/new-person.feature:10:in `Then I should not see "Add new person"' 

1 scenario (1 undefined) 
2 steps (2 undefined) 
0m0.005s 

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

Given /^I am on the new person page$/ do 
    pending # express the regexp above with the code you wish you had 
end 

Then /^I should not see "([^"]*)"$/ 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. 

爲什麼不是黃瓜加載的步驟?我猜想我需要在某個地方需要步驟,但我無法弄清楚在哪裏。

謝謝,最大

+0

對於參數的緣故將特徵文件移動到一個目錄中。我在我的各種.feature文件中沒有任何地方需要,我沒有看到任何配置goop在功能/支持/文件,似乎指向這一點。你確定你的people_steps.rb代碼是功能性的嗎?你有沒有犧牲一隻雞? – jaydel 2011-06-07 12:32:16

+0

@jaydel - 這一切工作正常,當我只用'耙子',即步驟都加載罰款。我想繼續追求我的特色,只是爲了將他們組織成合理的團體。 – 2011-06-07 14:34:40

+0

@jaydel - 但是,將功能文件移動到主要功能文件夾確實解決了問題...必須有一個需要某處,我需要添加額外的「../」我估計。 – 2011-06-07 14:37:12

回答

11

馬克斯·威廉姆斯找到了答案,他的問題:

編輯 - 找到了答案,在這裏:https://rspec.lighthouseapp.com/projects/16211/tickets/401-envrb-not-loaded-when-running-individual-features-in-sub-directories

在配置/ cucumber.yml有一條線,看起來像這樣:

std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags [email protected]"

將其更改爲

std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags [email protected] --require features/"

這就像在您的黃瓜測試運行結束時添加--require features/並使其正確加載一切。

+0

謝謝Sebastien :) – 2011-06-09 08:37:27

+0

@Max,你應該接受這個答案。 – nessur 2011-07-14 18:06:46

+0

另外,如果您不想添加默認選項,則可以在運行時將'-r features /'添加到黃瓜。 – nessur 2011-07-14 18:07:42

0

我沒有一個cucumber.yml文件來改變,無論出於何種原因。因此,只需創建一個空白的/config/cucumber.yml文件並將該行放入其中:

std_opts =「--format#{ENV ['CUCUMBER_FORMAT'] ||'pretty'} --strict --tags 〜@ wip --require features /「

沒有工作。 (這並不奇怪,我覺得那裏應該是比只是一條線更多了。)

我發現了一個完整的,工作,cucumber.yml示例文件在這裏的一個很好的例子:http://jdfrens.blogspot.com/2010/03/uh-yes-i-did-define-that-cucumber-step.html