ruby-on-rails – 运行Rspec功能规格时如何抑制请求中的噪音?

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 运行Rspec功能规格时如何抑制请求中的噪音?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用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

解决方法@H_403_20@
我最近经历了这个,将 rails_12factor宝石添加到我的Gemfile中,以在Heroku上启用静态资产服务.其中一个依赖是 rails_stdout_logging(顾名思义)将您的应用程序配置为登录到stdout.一种解决这个问题的方法是指定gem(在您的Gemfile中)仅用于生产,如:gem’rails_12factor’,group::production或现有的生产组块.

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

原文链接:https://www.f2er.com/ruby/265568.html

猜你在找的Ruby相关文章