nathanl / authority

*CURRENTLY UNMAINTAINED*. Authority helps you authorize actions in your Rails app. It's ORM-neutral and has very little fancy syntax; just group your models under one or more Authorizer classes and write plain Ruby methods on them.
MIT License
1.21k stars 67 forks source link

Hide warnings in capybara feature specs? #67

Closed johnrees closed 10 years ago

johnrees commented 10 years ago

If I have this feature spec spec/features/brands/adding_a_brand.rb

require 'spec_helper'

feature "Adding a brand" do

  scenario "as a visitor" do
    visit new_brand_path
    expect(page.status_code).to eq(403)
  end

end

It will pass, but I will get the following WARN message in my logs

Adding a brand
W, [2013-12-01T20:37:55.842741 #45068]  WARN -- :   is not authorized to create this resource: #<Brand:0x007fc2f7c0d980>
  as a visitor

Is there a way to suppress these warnings?

nathanl commented 10 years ago

@johnrees - Authority lets you give it a logger object and it uses that to call logger.warn, logger.info, etc. If you're using Rails, you'd do this in your config/initializers/authority.rb file, copied from this template when you run rails g authority:install: https://github.com/nathanl/authority/blob/master/lib/generators/templates/authority_initializer.rb

As the config file shows, you can use config.logger = Logger.new('/dev/null') to have Authority discard all such messages. In your case, you might want to wrap that in a conditional so it only happens in your test environment.

johnrees commented 10 years ago

Don't know how I missed that. Perfect. Thanks!