Skip to content

Instantly share code, notes, and snippets.

@palkan
Created September 7, 2020 17:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palkan/1652e91e061afb9eeebdfc7ccce0c937 to your computer and use it in GitHub Desktop.
Save palkan/1652e91e061afb9eeebdfc7ccce0c937 to your computer and use it in GitHub Desktop.
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