Skip to content

Instantly share code, notes, and snippets.

@palkan
Created Sep 7, 2020
Embed
What would you like to do?
Bulletify: RSpec helpers to run Bullet in tests
RSpec.shared_context "bullet" 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
RSpec.configure do |config|
config.include_context "bullet", bullet: true
config.alias_example_to :bulletify, bullet: true
end
# spec/controllers/my_controller_spec.rb
context "N+1" do
bulletify { get :index }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment