2011-07-04 40 views
1

我剛剛在github上發佈了一個gem,並且我用aruba gem寫了集成測試。但是我無法運行功能,因爲它的行爲與命令行不同。用黃瓜和阿魯巴測試發電機

如果我運行的功能軌道找不到我的發電機,如果我重複命令行上的相同步驟,他們完美地運行。

這是一個失敗的功能

Background: A new rails application has been created with my gem 
    Given a rails application named "my_app" exists 
    And this gem is installed in that application 

@announce 
Scenario: Installation using default values 
    When I successfully run `rails generate google_authentication:install` 
    # this is needed because rails g returns 0 when can't find the generator 
    And the output should not contain "Could not find generator" 

這是實現背景步驟

Given /^a rails application named "([^\"]*)" exists$/ do |app_name| 
    @app_name = app_name 
    Given "I successfully run `rm -rf #{app_name}`" # added to ensure that the working directory is clean 
    And "a directory named \"#{app_name}\" should not exist" 
    And "I successfully run `rails new #{app_name}`" 
    And "I cd to \"#{app_name}\"" 
end 

When /^this gem is installed in that application$/ do 
    gempath = File.expand_path('../../../', __FILE__) 
    Given "I append to \"Gemfile\" with \"gem 'gem-name', :path => '#{gempath}'\"" 
    And "I successfully run `bundle check`" 
end 

我試圖調試,我發現的代碼,如果我改變bundle check命令bundle install和我捕獲輸出,我的寶石沒有在捆綁中列出。因此,如果我編寫rails g --help步驟,我的發生器不在那裏。然而,設計寶石和發電機在那裏(設計被列爲需求在我的寶石。因此,似乎bundler/rails是不是加載所有內部阿魯巴臺階。

我認爲這是一個錯誤與阿魯巴或Bundler,我打開an issue for aruba但仍然沒有答案。

完整的代碼上Github

最後一件事我已經看到,並試圖this solution,但沒有運氣

+0

如果由於某些原因#{app_name}變成空白字符串,我不願意看到測試失敗... – corroded

+0

遇到類似問題。我保持一個古老的寶石來支持導軌3.1>。問題是bundle install命令失敗。雖然輸出顯示它已安裝,但當我檢查Gemfile.lock時,它不存在!這也不是一個阿魯巴問題,因爲我沒有使用阿魯巴寶石。 – kgpdeveloper

+0

我意識到我一直在做錯誤的方式。看看我寫我的測試:https://github.com/bridgeutopia/textile_editor_helper。謝謝。 – kgpdeveloper

回答

2

取而代之的是你寫的那些步驟,這是有點過時的在黃瓜裏。

嘗試是這樣的:

Given /^a rails application named "([^\"]*)" exists$/ do |app_name| 
    FileUtils.mkdir_p("tmp") 
    system("rm -rf tmp/#{app_name}") 
    system("rails new tmp/#{app_name}") 
    system("ln -s ../../../lib/generators tmp/#{app_name}/lib") 
    @current_directory = File.expand_path("tmp/#{app_name}") 
end 

你必須創建一個鏈接到該目錄。它比做捆綁安裝更有意義,你不應該嘗試使用黃瓜進行測試。

+0

我會試着讓你知道 – Fabio