Skip to content

Instantly share code, notes, and snippets.

/calc.rb Secret

Created September 29, 2016 19:17
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 anonymous/479611af464177edf31b730cc38cd8ab to your computer and use it in GitHub Desktop.
Save anonymous/479611af464177edf31b730cc38cd8ab to your computer and use it in GitHub Desktop.
class Calculator
attr_reader :mode, :last
def initialize(mode=:real)
@mode = mode
@last = 0 # XXX why this? without @last == nil
end
def mode=(mode)
@mode = mode
@last = 0
end
def add(a, b)
@last = a + b
end
end
class CalculatorTest < MiniTest::Test
def test_store_last_result
calc = Calculator.new
assert_equal 0, calc.last
calc.add 1,2
assert_equal 3, calc.last
end
end
=begin
1) Failure:
CalculatorTest#test_store_last_result [calc.rb:22]:
Expected: 0
Actual: nil
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment