【问题标题】:Rspec Guard is running twice alwaysRspec Guard 总是运行两次
【发布时间】:2014-10-28 18:37:32
【问题描述】:

我一直在使用 rspec 和 guard 来自动运行我的测试 我保存了文件,但是 guard 每次运行两次我不知道为什么,我在另一篇文章中看到这可能是因为spec_helper.rb 中有一个重复的配置选项,但我认为这不是我的情况。我离开了我的 spec_helper 文件内容。希望知道如何解决这个问题,它开始需要很长时间等待警卫运行两次相同

谢谢

# 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

【问题讨论】:

  • 同时显示您的 Guardfile。它是否总是每次都重复所有规格?还是只有一些?

标签: ruby-on-rails rspec guard


【解决方案1】:

尝试从spec_helper.rb 中删除config.order = "random"

【讨论】:

    【解决方案2】:

    当您有多个同名文件时,通常会发生这种情况。只需重命名包含运行两次的逻辑的 rake 文件。

    请记住,可能存在您无权访问的内部 gem 文件,这些文件与您的 Guardfile 冲突可能会导致重复执行。

    【讨论】:

      【解决方案3】:

      我强烈推荐阅读Guard 中的这个 Wiki 条目:https://github.com/guard/guard/wiki/Understanding-Guard

      ...仅仅是因为上面没有提供足够的信息来找到原因(并且有一些可能的 - 比如带有备份文件选项的编辑器,缺少忽略规则,不受支持的编辑器,文件系统慢,不正确的延迟,错误的规则Guardfile 中,多个监视规则匹配,Guard 中的错误等)。

      但该 Wiki 页面可以快速帮助您深入了解核心原因。

      如果是 Listen 问题,请在此处查看 wiki:https://github.com/guard/listen/wiki (尤其是 LISTEN_GEM_DEBUGGING=1 环境变量,以查看您是否收到多个事件或多个回调)。

      获得该信息后,您可以在Guard 中提交问题,我们可以找出您遇到的原因。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-19
        • 2019-11-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多