From 048f7c9b73aa3e7e6b94397dfad177e787a4c896 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 26 Aug 2015 17:24:08 +0200 Subject: [PATCH] Adds bullet to dev & test, but makes it visible only on-demmand The logs are always stored in log/bullet.log If you run the specs with `BULLET=true bin/rspec`: * Any feature test which makes bullet angry will fail If you run rails with `BULLET=true bin/rails s`: * It will print the bullet logs in both the rails log and the bullet log * It will show a footer on each page with the N+1 queries etc. --- config/environments/development.rb | 9 +++++++++ config/environments/test.rb | 9 +++++++++ spec/spec_helper.rb | 11 +++++++++++ 3 files changed, 29 insertions(+) diff --git a/config/environments/development.rb b/config/environments/development.rb index acf67286d..d2f4d1c4b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -44,4 +44,13 @@ Rails.application.configure do # config.action_view.raise_on_missing_translations = true config.cache_store = :null_store + + config.after_initialize do + Bullet.enable = true + Bullet.bullet_logger = true + if ENV['BULLET'] + Bullet.rails_logger = true + Bullet.add_footer = true + end + end end diff --git a/config/environments/test.rb b/config/environments/test.rb index a76376fe6..cef568af6 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -45,4 +45,13 @@ Rails.application.configure do # config.action_view.raise_on_missing_translations = true config.cache_store = :null_store + + config.after_initialize do + Bullet.enable = true + Bullet.bullet_logger = true + if ENV['BULLET'] + Bullet.raise = true # raise an error if n+1 query occurs + end + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0e0b14960..bf1a65776 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,6 +27,15 @@ RSpec.configure do |config| DatabaseCleaner.clean end + config.before(:each, type: :feature) do + Bullet.start_request + end + + config.after(:each, type: :feature) do + Bullet.perform_out_of_channel_notifications if Bullet.notification? + Bullet.end_request + end + # Allows RSpec to persist some state between runs in order to support # the `--only-failures` and `--next-failure` CLI options. config.example_status_persistence_file_path = "spec/examples.txt" @@ -57,4 +66,6 @@ RSpec.configure do |config| # test failures related to randomization by passing the same `--seed` value # as the one that triggered the failure. Kernel.srand config.seed + + end