2014-10-28 50 views
0

我一直在使用rspec和guard來自動運行我的測試文件我保存文件,但守衛每次運行兩次,我不明白爲什麼,我在另一個帖子,這可能是因爲spec_helper.rb中有一個重複的配置選項,但我認爲不是我的情況。我離開我的spec_helper文件內容。希望知道如何解決這個問題,開始需要很長的時間來等待後衛運行兩次相同Rspec Guard始終運行兩次

感謝

# This file is copied to spec/ when you run 'rails generate rspec:install' 
ENV["RAILS_ENV"] ||= 'test' 
require File.expand_path("../../config/environment", __FILE__) 
require 'rspec/rails' 
# Requires supporting ruby files with custom matchers and macros, etc, 
# in spec/support/ and its subdirectories. 
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } 

# Checks for pending migrations before tests are run. 
# If you are not using ActiveRecord, you can remove this line. 
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) 

RSpec.configure do |config| 
    # ## Mock Framework 
    # 
    # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: 
    # 
    # config.mock_with :mocha 
    # config.mock_with :flexmock 
    # config.mock_with :rr 
    config.include Devise::TestHelpers, type: :controller 

    # If true, the base class of anonymous controllers will be inferred 
    # automatically. This will be the default behavior in future versions of 
    # rspec-rails. 
    config.infer_base_class_for_anonymous_controllers = false 

    config.include FactoryGirl::Syntax::Methods 

    config.before(:suite) do 
    FactoryGirl.lint 
    DatabaseCleaner.strategy = :transaction 
    DatabaseCleaner.clean_with(:truncation) 
    end 

    config.before(:all) do 
    DatabaseCleaner.start 
    end 

    config.before(:each) do 
    reset_email 
    end 

    config.after(:all) do 
    DatabaseCleaner.clean 
    end 

    config.include(MailerMacros) 
    config.include Rails.application.routes.url_helpers 
end 
+0

移除config.order = "random"顯示您Guardfile爲好。它是否總是重複所有規格?或只有一些? – Doon 2014-10-28 18:53:59

回答

0

當你有多個同名的文件,這通常發生。只需重命名您的rake文件,其中包含運行兩次的邏輯。

請記住,可能存在內部gem文件,您無法訪問哪些文件可能會與Guardfile發生衝突,從而導致重複執行。

0

我強烈建議你閱讀在Guard這個維基條目:https://github.com/guard/guard/wiki/Understanding-Guard

...只是因爲上面並沒有提供足夠的信息來找到原因(也有幾個可能的 - 就像編輯備份文件選項,缺少忽略規則,不受支持的編輯器,慢文件系統,不正確的延遲,Guardfile中的錯誤規則,多個監視規則匹配,Guard中的錯誤等)。

但是該Wiki頁面可以快速幫助您深入瞭解核心原因。

如果是Listen問題,看看這裏的維基:https://github.com/guard/listen/wiki (尤其是LISTEN_GEM_DEBUGGING=1環境變量,看看你得到多個事件或多個回調)。

一旦你有了這些信息,你可以在Guard提交問題,我們可以找出你的情況的原因。

1

嘗試從spec_helper.rb