Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress noise from requests when running Rspec feature specs?

I'm using Rspec feature specs and when I run them I get output such as:

.............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...)

How can I suppress the messages from the requests in my output? I've tried setting log levels to no avail. Any ideas would be appreciated. Thanks!

Edit:

This is a Rails 4 project using Ruby 2.0.

spec/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

spec/features/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
like image 570
user1647525 Avatar asked Aug 08 '13 18:08

user1647525


1 Answers

I recently experienced this after adding the rails_12factor gem to my Gemfile to enable static asset serving on Heroku. One of the dependencies is rails_stdout_logging which (as the name suggests) configures your application to log to stdout. One way to solve this issue it to specify the gem (in your Gemfile) for use in production only, like so: gem 'rails_12factor', group: :production or in your existing production group block.

If you aren't using rails_12factor, or aren't aware of the rails_stdout_logging gem being used in your application, open up your Gemfile.lock and do a search for 'rails_stdout_logging'. Ensuring this gem is only used in your production environment should stop the aforementioned requests being output when you run your specs.

like image 106
james Avatar answered Oct 23 '22 15:10

james