Sha256: 90acb1c8b5053b59ad08e27ec7c7b69f2c45b97a4b633b8d1bd95e278317086b
Contents?: true
Size: 872 Bytes
Versions: 5
Compression:
Stored size: 872 Bytes
Contents
#!/usr/bin/env ruby #--- # Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org). # All rights reserved. # Permission is granted for use, copying, modification, distribution, # and distribution of modified versions of this work as long as the # above copyright notice is included. #+++ require 'test/unit' require 'flexmock' class TemperatureSampler def initialize(sensor) @sensor = sensor end def average_temp total = (0...3).collect { @sensor.read_temperature }.inject { |i, s| i + s } total / 3.0 end end class TestTemperatureSampler < Test::Unit::TestCase def test_tempurature_sampler readings = [10, 12, 14] mock_sensor = FlexMock.new mock_sensor.mock_handle(:read_temperature) { readings.shift } sampler = TemperatureSampler.new(mock_sensor) assert_equal 12, sampler.average_temp end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
flexmock-0.6.2 | test/test_example.rb |
flexmock-0.6.4 | test/test_example.rb |
flexmock-0.6.1 | test/test_example.rb |
flexmock-0.6.0 | test/test_example.rb |
flexmock-0.6.3 | test/test_example.rb |