Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created September 29, 2016 18:02
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/7d85de129207afa820e3bc42552a9199 to your computer and use it in GitHub Desktop.
Save anonymous/7d85de129207afa820e3bc42552a9199 to your computer and use it in GitHub Desktop.
class Calculator
attr_reader :mode, :last
def initialize(mode=:real)
@mode = mode
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