我正在使用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
答案 0 :(得分:13)
我最近在将rails_12factor gem添加到我的Gemfile中以在Heroku上启用静态资源服务后遇到了这种情况。其中一个依赖项是rails_stdout_logging(顾名思义),它将您的应用程序配置为登录到stdout。解决此问题的一种方法是指定gem(在Gemfile中)仅用于生产,如:gem 'rails_12factor', group: :production
或现有生产组块。
如果您没有使用rails_12factor,或者不知道应用程序中使用的rails_stdout_logging gem,请打开Gemfile.lock并搜索“rails_stdout_logging”。确保此gem只在您的生产环境中使用,应该在运行规范时停止输出上述请求。