Skip to content

Instantly share code, notes, and snippets.

View murbanski's full-sized avatar

Marcin Urbański murbanski

  • Wroclaw, Poland
View GitHub Profile
@murbanski
murbanski / api_clients_controller_spec.rb
Last active February 27, 2024 19:53
RSpec 3.1 and Rails 4 HTTP Digest Auth testing
# spec/controllers/api_clients_controller_spec.rb
RSpec.describe APIClientsController, type: :controller do
let(:api_client) { mock_model(APIClient) }
context "when HTTP Digest auth credentials are invalid" do
before do
authenticate_with_http_digest("invalid_login", "invalid_password") do
get :index
end
end
@murbanski
murbanski / whatwedeploy.sh
Created October 16, 2013 10:41
What will we deploy?
#!/usr/bin/env sh
git log origin/production..master --no-merges --pretty=format:%s |
egrep -o "[0-9]{6,}" |
xargs -n1 -I :story_id echo "https://www.pivotaltracker.com/story/show/:story_id"
@murbanski
murbanski / spec_helper.rb
Last active December 15, 2015 17:49
FactoryGirl bottlenecks
require 'rspec/rails'
# ...
$factories_speed = Hash.new {|h, k| h[k] = {calls: 0, duration: 0} }
ActiveSupport::Notifications.subscribe("factory_girl.run_factory") do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
key = "#{event.payload[:strategy]}_#{event.payload[:name]}"
$factories_speed[key][:calls] += 1
$factories_speed[key][:duration] += event.duration
end