Created
July 29, 2014 09:57
-
-
Save tooky/a75778f70499af2f9435 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Corey's challenge is to make the second test pass without ever making the first test fail. | |
# run ruby stack.rb to run the tests | |
# For more information see http://tooky.co.uk/kickstart-academy-podcast-with-corey-haines-and-sandi-metz/ | |
class Stack | |
def empty? | |
true | |
end | |
def push(element) | |
@empty = false | |
end | |
end | |
def assert(expected, actual, msg="FAIL!") | |
if expected != actual | |
raise "Failed test. #{expected} should have been #{actual}" | |
end | |
end | |
# a new stack is empty | |
s = Stack.new | |
assert(true, s.empty?) | |
# a stack is not empty after I push | |
s = Stack.new | |
s.push 5 | |
if false != s.empty? | |
raise "Stack should not have been empty" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't the
msg
argument to#assert
be used somewhere?