This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ruby-prof' | |
require 'ruby-prof/task' | |
RubyProf::ProfileTask.new(:integration) do |t| | |
t.test_files = FileList['test/integration/**/patients_test.rb'] | |
t.output_dir = File.join(Rails.root, 'tmp') | |
t.printer = :graph_html | |
t.min_percent = 10 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "delegate" | |
Foo = Class.new(SimpleDelegator) | |
Bar = Struct.new(:foo) | |
Foo.new(1) == Foo.new(1) # => true | |
Bar.new(1) == Bar.new(1) # => true | |
Foo.new(Bar.new(1)) == Foo.new(Bar.new(1)) # => false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require "delegate" | |
require "set" | |
# Hash that can only hold a certain number of keys, keys expire on a LRU basis | |
class BoundedHash < DelegateClass(Hash) | |
NO_OP = proc {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec::Matchers.define :be_uniq do | |
match do |actual| | |
values_match? actual.uniq, actual | |
end | |
failure_message do |actual| | |
diff = actual.dup | |
actual.uniq.each { |value| diff.delete_at diff.index(value) } | |
diff = diff.uniq | |
"expected that #{actual.inspect} to be uniq, but found the following repeated elements: #{diff.inspect}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Fluent | |
def fluent_accessor(*attr_names) | |
attr_names.each do |attr_name| | |
define_method attr_name do |*val| | |
return instance_variable_get("@#{attr_name}") if val.empty? | |
raise ArgumentError, "Expected 0..1 arguments, got #{val.size}" if val.size > 1 | |
value = val.first | |
value = yield(value) if block_given? | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ternary = foo ? !bar : bar | |
xor = !!(foo ^ bar) | |
neq = foo != bar | |
foo | bar | xor | ternary | neq | |
------------------------------------- | |
true | true | false | false | false | |
false | false | false | false | false | |
true | false | true | true | true | |
false | true | true | true | true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = function (grunt) { | |
require('load-grunt-tasks')(grunt); | |
require('time-grunt')(grunt); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
// configurable paths | |
var config = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Barator | |
def foo(*args) | |
"#{super(*args)}bar" | |
end | |
end | |
class Foo | |
prepend Barator | |
def foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Order rejecting an order sends reject email when status is updated | |
Failure/Error: Order.new.stub(:send_reject_email) | |
NoMethodError: | |
undefined method `method_defined?' for #<Order not initialized> | |
# /Users/matt/.rvm/gems/ruby-2.0.0-p247@uncommon-flow/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:436:in `method_missing' | |
# /Users/matt/.rvm/gems/ruby-2.0.0-p247@uncommon-flow/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:128:in `method_missing' | |
# /Users/matt/.rvm/gems/ruby-2.0.0-p247@uncommon-flow/gems/rspec-mocks-2.14.1/lib/rspec/mocks/instance_method_stasher.rb:34:in `method_defined_on_klass?' | |
# /Users/matt/.rvm/gems/ruby-2.0.0-p247@uncommon-flow/gems/rspec-mocks-2.14.1/lib/rspec/mocks/instance_method_stasher.rb:55:in `method_owned_by_klass?' | |
# /Users/matt/.rvm/gems/ruby-2.0.0-p247@uncommon-flow/gems/rspec-mocks-2.14.1/lib/rspec/mocks/instance_method_stasher.rb:29:in `method_defined_directly_on_klass?' | |
# /Users/matt/.rvm/gems/ruby-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support' | |
module TestConcern | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def test_class_method | |
puts "I gots class!" | |
end | |
end |