Skip to content

Instantly share code, notes, and snippets.

View anolson's full-sized avatar
👋

Andrew Olson anolson

👋
View GitHub Profile
# Re-try randomly failing examples
config.around(:each) do |ex|
attempts = [ENV["RSPEC_ATTEMPTS"].to_i, 1].max
attempts.times do |i|
example = RSpec.current_example
example.instance_variable_set("@exception", nil)
if i > 0
puts "Re-running rspec example #{example.location}. Attempt #{i + 1} of #{attempts}"
end
@anolson
anolson / spec_helper.rb
Last active March 21, 2020 02:53
Profile ActiveRecord queries with RSpec
RSpec.configure do |config|
config.before(:suite) do
Thread.current[:query_counter] = Hash.new(0)
end
config.around(:example) do |procsy|
callback = lambda do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
sql = event.payload[:sql].to_s.strip
operation = sql.split(' ', 2).first.to_s.downcase
@anolson
anolson / notes.md
Last active November 3, 2016 20:49
Confident Ruby Notes

Confident Ruby Notes

Chapter 1 – Introduction

Four parts of a method

  1. Collecting input
  2. Performing work
  3. Delivering output
  4. Handling failures