Skip to content

Instantly share code, notes, and snippets.

@teancom
Created May 2, 2013 04:07
Show Gist options
  • Save teancom/5500095 to your computer and use it in GitHub Desktop.
Save teancom/5500095 to your computer and use it in GitHub Desktop.
# This one works
class DiceSet
def roll(size)
@dice = []
size.times do |x|
@dice[x] = rand(1..6)
end
end
def values
@dice
end
end
vs
# This one doesn't (i.e., the test fails) - when run from within the koan test
# It totally works fine when run in irb
class DiceSet
def initialize
@dice = []
end
def roll(size)
size.times do |x|
@dice[x] = rand(1..6)
end
end
def values
@dice
end
end
def test_dice_values_should_change_between_rolls
dice = DiceSet.new
dice.roll(5)
first_time = dice.values
dice.roll(5)
second_time = dice.values
assert_not_equal first_time, second_time,
"Two rolls should not be equal"
end
@teancom
Copy link
Author

teancom commented May 2, 2013

That makes a ton of sense, Carlo. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment