Skip to content

Instantly share code, notes, and snippets.

View rewinfrey's full-sized avatar
🏄‍♂️
fix f = let x = f x in x

Rick Winfrey rewinfrey

🏄‍♂️
fix f = let x = f x in x
View GitHub Profile
@rewinfrey
rewinfrey / procsvlambdas
Created February 19, 2014 16:25
procs vs. lambdas
def some_method
some_method2
puts "here"
end
def another_method
puts "in another method"
return
end
@rewinfrey
rewinfrey / lambda_closure_scope.rb
Last active August 29, 2015 13:56
Determining if the closure of a lambda referencing an ivar is defined at time of creation, or time of calling.
class Creator
def initialize(input1)
@input1 = input1
end
def create_lambda
->() {
puts @input1
}
end
@rewinfrey
rewinfrey / procvlambda
Last active August 29, 2015 13:56
testing syntax highlighting
def some_method
some_method
puts "here"
end
def another_method
puts "in another method"
return
end
def hello
puts "hello"
end
@rewinfrey
rewinfrey / recoli.rb
Last active August 29, 2015 13:57
Repositories, Contexts (Use Cases), Context Library
# Establishing a top level namespace for a given module (Context Library),
# that serves as the internal API for a component of a system
# is a great way to begin the process of extracting that component
# from its containing environment.
# Benefits include:
# A well defined boundary of responsibilities
# More DRY (less duplicated knowledge of the way a component works)
# Isolates points of contact between component and containing system
# Expresses a clear and simple definition of the component's responsibilities defined by use case
@rewinfrey
rewinfrey / mock_example_spec.rb
Last active August 29, 2015 13:57
A mock example to illustrate the difference between mocks and dummies
describe AmazonDrone do
it "collects order inventory from warehouse" do
warehouse = double(:warehouse)
order = double(:order) # dummy
inventory = double(:inventory) # dummy
# set expectations on behavior of warehouse "mock"
warehouse.should_receive(:fill_inventory).with(order).and_return(inventory)
@rewinfrey
rewinfrey / large_classical_spec_file.rb
Last active August 29, 2015 13:57
Large test example
shared_examples_for 'a user search engine' do
let(:payment_service) { service_factory.create(:payment) }
let(:db) { search_repository }
def ids(users)
users.map { |user| user[:id] }
end
def user_search(options)
@rewinfrey
rewinfrey / setup_test_example_with_opaque_input_params.rb
Created March 14, 2014 05:16
Interesting use of setup for constructing tests
describe Acme::MessageQueue::SqsMessageQueue do
def setup(payload, &block)
config = {
:access_key => 'first',
:secret_key => 'second'
}
mock_queue = double(:mock_queue)
mock_queues = double(:mock_queues)
@rewinfrey
rewinfrey / setup_example_with_descriptive_inputs.rb
Created March 14, 2014 05:23
Interesting setup example with more descriptive input paramaters
describe Acme::MessageQueue::SqsMessageQueue do
def setup(payload, &block)
config = {
:access_key => 'first',
:secret_key => 'second'
}
mock_queue = double(:mock_queue)
mock_queues = double(:mock_queues)
@rewinfrey
rewinfrey / large_spec.rb
Created March 14, 2014 05:31
Updated large spec
shared_examples_for 'a user search engine' do
let(:payment_service) { service_factory.create(:payment) }
let(:db) { search_memory_repository }
def ids(users)
users.map { |user| user[:id] }
end
def user_search(options)