Skip to content

Commit

Permalink
To add test_alarm_is_on_when_pressure_out_of_range() and test_alarm_i…
Browse files Browse the repository at this point in the history
…s_off_when_pressure_within_range(), create customerized mock to isolate sensor, meanwhile, make sensor as public variable.
  • Loading branch information
mebusw committed Apr 30, 2014
1 parent 57af06a commit 67d8ac3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Expand Up @@ -3,7 +3,7 @@
class Alarm

attr_reader :alarm_on

attr_accessor :sensor
def initialize
@sensor = Sensor.new
@alarm_on = false
Expand Down
@@ -1,9 +1,39 @@
require 'test/unit'
require_relative '../alarm'
require_relative '../sensor'

class MockSensor < Sensor
def initialize psi_value
@psi_value = psi_value
end

def pop_next_pressure_psi_value
@psi_value
end
end

class AlarmTest < Test::Unit::TestCase
def test_alarm_is_off_after_it_initialized
alarm = Alarm.new
assert_equal false, alarm.alarm_on
end

def test_alarm_is_on_when_pressure_out_of_range
alarm = Alarm.new
alarm.sensor = MockSensor.new(10)

alarm.check

assert_equal true, alarm.alarm_on
end

def test_alarm_is_off_when_pressure_within_range
alarm = Alarm.new
alarm.sensor = MockSensor.new(20)

alarm.check

assert_equal false, alarm.alarm_on
end

end

0 comments on commit 67d8ac3

Please sign in to comment.