Created
August 19, 2014 23:56
-
-
Save ebalcomb/a4429aae53994a3be9f7 to your computer and use it in GitHub Desktop.
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
# 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