Skip to content

Instantly share code, notes, and snippets.

@ebalcomb
Created August 19, 2014 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebalcomb/a4429aae53994a3be9f7 to your computer and use it in GitHub Desktop.
Save ebalcomb/a4429aae53994a3be9f7 to your computer and use it in GitHub Desktop.
# Please write *complete* RSpec tests for each of the following make_maru methods.
# - Each example assumes a different interface to Kitten.new
# - #set_name is an instance method, defined ONLY on the Kitten class
# - #make_maru must *always* return the kitten instance
# Example 1
def make_maru
kitten = Kitten.new
kitten.set_name('Maru')
kitten
end
# Example 2
def make_maru
Kitten.new do |kitten|
kitten.set_name('Maru')
end
end
# Example 3
def make_maru
Kitten.new do
set_name('Maru')
end
end
# * * Extra Credit * * - rewrite the #make_maru from Example 1 to use #tap
# HINT
# While our tests don't care about the implementation of Kitten.new, here's an example
# of what an implementation might look like, in case it helps.
class Kitten
def initialize(&block)
instance_eval(&block)
end
private
def set_name(name)
puts "Setting name to #{name}"
end
end
Kitten.new do
set_name 'Maru'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment