Skip to content

Instantly share code, notes, and snippets.

@dpaluy
Last active December 2, 2018 06:41
Show Gist options
  • Select an option

  • Save dpaluy/9f9d3982c1dab07d869564358734be16 to your computer and use it in GitHub Desktop.

Select an option

Save dpaluy/9f9d3982c1dab07d869564358734be16 to your computer and use it in GitHub Desktop.
Bullet in RSpec
# spec/controllers/my_controller_spec.rb
context 'N+1' do
bulletify { get :index }
end
# spec/rails_helper.rb
require_relative "support"
config.alias_example_to :bulletify, bullet: true
# spec/support.rb
shared_context "bullet", bullet: true do
before(:each) do
Bullet.enable = true
Bullet.bullet_logger = true
Bullet.raise = true # raise an error if N+1 query occurs
Bullet.start_request
end
after(:each) do
Bullet.perform_out_of_channel_notifications if Bullet.notification?
Bullet.end_request
Bullet.enable = false
Bullet.bullet_logger = false
Bullet.raise = false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment