9

我正在使用 Rspec 功能规范,当我运行它们时,我会得到如下输出:

.............Started GET "/sign_up" for 127.0.0.1 at 2013-08-08 10:52:00 -0700
Started POST "/accounts" for 127.0.0.1 at 2013-08-08 10:52:01 -0700
Started GET "/" for 127.0.0.1 at 2013-08-08 10:52:01 -0700
.Started GET "/sign_in" for 127.0.0.1 at 2013-08-08 10:52:02 -0700
Started POST "/users/sign_in" for 127.0.0.1 at 2013-08-08 10:52:02 -0700
Started GET "/" for 127.0.0.1 at 2013-08-08 10:52:02 -0700
................................. (etc...)

如何在输出中抑制来自请求的消息?我试过设置日志级别无济于事。任何想法,将不胜感激。谢谢!

编辑:

这是一个使用 Ruby 2.0 的 Rails 4 项目。

规范/spec_helper.rb

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'factory_girl'
require 'capybara/rails'
require 'capybara/rspec'
require 'webmock/rspec'

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

RSpec.configure do |config|
  config.mock_with :mocha
  config.include FactoryGirl::Syntax::Methods
  config.use_transactional_fixtures = true
  config.infer_base_class_for_anonymous_controllers = false
  config.order = "random"
end

规格/功能/sign_in_spec.rb

require "spec_helper"
feature "Sign in" do
  background do
    account = create(:account)
    @admin = account.admin
  end
  scenario "User signs into the application" do
    visit sign_in_path
    fill_in "user_email", with: @admin.email
    fill_in "user_password", with: @admin.password
    click_button "Sign in"
    expect(page).to have_content "Signed in successfully"
  end
end
4

1 回答 1

13

我最近在将rails_12factor gem 添加到我的 Gemfile 以在 Heroku 上启用静态资产服务后遇到了这种情况。其中一个依赖项是rails_stdout_logging(顾名思义)将您的应用程序配置为记录到标准输出。解决此问题的一种方法是指定 gem(在您的 Gemfile 中)仅用于生产,如下所示:gem 'rails_12factor', group: :production或在您现有的生产组块中。

如果您没有使用 rails_12factor,或者不知道您的应用程序中正在使用 rails_stdout_logging gem,请打开您的 Gemfile.lock 并搜索“rails_stdout_logging”。确保此 gem 仅在您的生产环境中使用应该会在您运行规范时停止输出上述请求。

于 2013-08-10T19:14:35.207 回答