2013-08-21 40 views
1

因此,我的團隊使用Cucumber,Rspec和使用這些測試框架所必需的所有寶石來驅動我們的Rails應用程序(一個調查和lite電子記錄系統)。我正在建立一個Jenkins CI服務器,並希望在我們的測試,開發和臨時環境中對數據庫進行標準化(我們最終選擇了MySQL)。數據庫吸塵器不清洗一個黃瓜場景

將測試環境從SQlite切換到MySQL後,我們發現了一些與緩存相關的測試錯誤,我們使用相對ID而不是硬編碼來解決這些錯誤。例如:

describe "#instance_method" do 
    before(:each) do 
    @survey = FactoryGirl.create(:survey) 
    @question_1 = FactoryGirl.create(:question) 
    @question_2 = FactoryGirl.create(:question) 
    .... 
    end 
    context "question has no requirements" do 
    it "should match" do 
     # below breaks under MySQL (and postgres), but not SQlite 
     expect { @survey.present_question?(2) }.to be_true 
     # always works 
     expect { @survey.present_question?(@question_2.id) }.to be_true 
    end 
    end 
end 

解決這一失敗的一個天賦後,我解決那些困擾永遠我們的測試套件一些無關的AJAX的問題。考慮到我終於掌握了測試的藝術,我自信地跑了rake。我遇到了這個不友好的景象:

screen shot 2013-08-20 at 8 12 42 pm

現在當然cucumber features/presenting_default_questions.feature降雨綠色時孤立運行。

失敗場景:

@javascript 
Feature: Dynamic Presentation of Questions 
    In order to only answer questions that are relevant considering previously answered  questions 
    As a patient 
    I want to not be presented questions that illogical given my previously answered question on the survey 

    Scenario: Answering a question that does not depend on any other questions 
    Given I have the following questions: 
     | prompt    | datatype | options | parent_id | requirement | 
     | Do you like cars? | bool  |   |   |    | 
     | Do you like fruit? | bool  |   |   |    | 
    When I visit the patient sign in page 
    And I fill out the form with the name "Jim Dog", date of birth "1978-03-30", and gender "male" 
    And I accept the waiver 
    Then I should see the question "Do you like cars" 
    When I respond to the boolean question with "Yes" 
    Then I should see the question "Do you like fruit?" 
    When I respond to the boolean question with "No" 
    Given I wait for the ajax request to finish 
    Then I should be on the results page 

相關步驟:

Then(/^I should be on the results page$/) do 
    # fails under ``rake`` passes when run in isolation 
    current_path.should == results_survey_path(1) 
end 

Then(/^I should be on the results page$/) do 
    # passes in isolation and under ``rake`` 
    current_path.should == results_survey_path(Survey.last.id) 
end 
使用 Capybara.javascript_driver = :webkit

此外,黃瓜/數據庫清潔器配置是從rails g cucumber:install未修改。

看起來rspec和cucumber測試失敗都會遇到同樣的索引問題。雖然上面提出的解決方案可行,但它超級笨拙並引發了一個問題,爲什麼一個簡單的絕對索引不起作用(在每個場景和功能之間清理完所有數據庫之後)。我的測試有什麼問題嗎?用database_cleaner?

請讓我知道如果更多的代碼會有幫助!

Relavent寶石版本:

  • activemodel的(3.2.14)
  • 黃瓜(1.3.6)
  • 黃瓜導軌(1.3.1)
  • database_cleaner(1.0.1)
  • 水豚(2.1.0)
  • 水豚-WebKit的(1.0.0)
  • mysql2(0.3.13)
  • rspec的(2.13.0)
+0

從版本1.1.2更新到1.1.0後,我們立即遇到類似問題。此前,所有的綠色測試。之後,當我們重新運行場景時,測試數據庫會穩定地受到更多污染 – xxjjnn

+0

對此有何更新?我看到一個類似的問題(黃瓜場景通過孤立,整個套件失敗),我試圖把它的螺絲。 – pjmorse

+0

@pjmorse @ClothSword您是否嘗試將'database_cleaner'的版本升級到'1.3.0'? – etagwerker

回答

1

這個問題似乎是你缺少你Cucumber情景database_cleaner代碼。

你提到你有你的RSpec情景database_cleaner代碼,但似乎你失去了一些東西像這樣Cucumber的env.rb:

begin 
    require 'database_cleaner' 
    require 'database_cleaner/cucumber' 

    DatabaseCleaner.strategy = :truncation 
rescue NameError 
    raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it." 
end 

Around do |scenario, block| 
    DatabaseCleaner.cleaning(&block) 
end 

你在那裏有這樣的代碼?

+1

很久以前,這個問題已經解決了,但是這充實了黃瓜配置,似乎是在正確的軌道上。現在我的(工作)黃瓜配置僅僅是 ''' 開始 DatabaseCleaner.strategy =:交易 救援NameError 加薪「你需要database_cleaner添加到您的Gemfile(中:試驗組),如果你想使用它。」 結束 Cucumber :: Rails :: Database.javascript_strategy =:截斷 ''' @pjmorse幫助你嗎?如果是這樣,我會接受答案。 – dleve123