minilab 1.0.0-mswin32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +2 -0
- data/CHANGES +2 -0
- data/LICENSE +19 -0
- data/README +107 -0
- data/Rakefile +145 -0
- data/config/environment.rb +15 -0
- data/config/objects.yml +22 -0
- data/lib/analog_io.rb +30 -0
- data/lib/digital_auxport_io.rb +49 -0
- data/lib/digital_configuration.rb +66 -0
- data/lib/digital_port_io.rb +68 -0
- data/lib/extension/extconf.rb +4 -0
- data/lib/extension/minilab_hardware.c +235 -0
- data/lib/extension/minilab_hardware.so +0 -0
- data/lib/library_translator.rb +48 -0
- data/lib/minilab.rb +149 -0
- data/lib/minilab_context.rb +39 -0
- data/lib/result_verifier.rb +14 -0
- data/test/integration/analog_input_output_test.rb +43 -0
- data/test/integration/connect_to_hardware_test.rb +13 -0
- data/test/integration/digital_input_output_test.rb +114 -0
- data/test/integration/integration_test.rb +53 -0
- data/test/integration/require_minilab_test.rb +9 -0
- data/test/system/analog_input.test +3 -0
- data/test/system/analog_output.test +37 -0
- data/test/system/digital_port_input.test +5 -0
- data/test/system/digital_port_output.test +39 -0
- data/test/system/digital_port_read_byte.test +26 -0
- data/test/system/digital_screw_terminals_input.test +2 -0
- data/test/system/digital_screw_terminals_output.test +11 -0
- data/test/system/minilab_driver.rb +85 -0
- data/test/test_helper.rb +11 -0
- data/test/unit/analog_io_test.rb +87 -0
- data/test/unit/digital_auxport_io_test.rb +114 -0
- data/test/unit/digital_configuration_test.rb +136 -0
- data/test/unit/digital_port_io_test.rb +117 -0
- data/test/unit/library_translator_test.rb +100 -0
- data/test/unit/minilab_context_test.rb +82 -0
- data/test/unit/minilab_hardware_test.rb +83 -0
- data/test/unit/minilab_test.rb +131 -0
- data/test/unit/result_verifier_test.rb +33 -0
- data/vendor/behaviors/lib/behaviors.rb +50 -0
- data/vendor/behaviors/tasks/behaviors_tasks.rake +140 -0
- data/vendor/behaviors/test/behaviors_tasks_test.rb +71 -0
- data/vendor/behaviors/test/behaviors_test.rb +50 -0
- data/vendor/behaviors/test/tasks_test/Rakefile +16 -0
- data/vendor/behaviors/test/tasks_test/doc/behaviors.html +55 -0
- data/vendor/behaviors/test/tasks_test/lib/user.rb +2 -0
- data/vendor/behaviors/test/tasks_test/test/user_test.rb +17 -0
- data/vendor/constructor/Rakefile +44 -0
- data/vendor/constructor/config/environment.rb +12 -0
- data/vendor/constructor/lib/constructor.rb +132 -0
- data/vendor/constructor/test/constructor_test.rb +366 -0
- data/vendor/constructor/test/helper.rb +3 -0
- data/vendor/diy/README +26 -0
- data/vendor/diy/Rakefile +18 -0
- data/vendor/diy/lib/constructor.rb +114 -0
- data/vendor/diy/lib/diy.rb +329 -0
- data/vendor/diy/proto/context.rb +117 -0
- data/vendor/diy/proto/context.yml +20 -0
- data/vendor/diy/test/diy_test.rb +370 -0
- data/vendor/diy/test/files/broken_construction.yml +7 -0
- data/vendor/diy/test/files/cat/cat.rb +4 -0
- data/vendor/diy/test/files/cat/extra_conflict.yml +5 -0
- data/vendor/diy/test/files/cat/heritage.rb +2 -0
- data/vendor/diy/test/files/cat/needs_input.yml +3 -0
- data/vendor/diy/test/files/cat/the_cat_lineage.rb +1 -0
- data/vendor/diy/test/files/dog/dog_model.rb +4 -0
- data/vendor/diy/test/files/dog/dog_presenter.rb +4 -0
- data/vendor/diy/test/files/dog/dog_view.rb +2 -0
- data/vendor/diy/test/files/dog/file_resolver.rb +2 -0
- data/vendor/diy/test/files/dog/other_thing.rb +2 -0
- data/vendor/diy/test/files/dog/simple.yml +11 -0
- data/vendor/diy/test/files/donkey/foo.rb +8 -0
- data/vendor/diy/test/files/donkey/foo/bar/qux.rb +7 -0
- data/vendor/diy/test/files/fud/objects.yml +13 -0
- data/vendor/diy/test/files/fud/toy.rb +15 -0
- data/vendor/diy/test/files/gnu/objects.yml +14 -0
- data/vendor/diy/test/files/gnu/thinger.rb +8 -0
- data/vendor/diy/test/files/goat/base.rb +8 -0
- data/vendor/diy/test/files/goat/can.rb +6 -0
- data/vendor/diy/test/files/goat/goat.rb +6 -0
- data/vendor/diy/test/files/goat/objects.yml +12 -0
- data/vendor/diy/test/files/goat/paper.rb +6 -0
- data/vendor/diy/test/files/goat/plane.rb +8 -0
- data/vendor/diy/test/files/goat/shirt.rb +6 -0
- data/vendor/diy/test/files/goat/wings.rb +8 -0
- data/vendor/diy/test/files/horse/holder_thing.rb +4 -0
- data/vendor/diy/test/files/horse/objects.yml +7 -0
- data/vendor/diy/test/files/yak/core_model.rb +4 -0
- data/vendor/diy/test/files/yak/core_presenter.rb +4 -0
- data/vendor/diy/test/files/yak/core_view.rb +1 -0
- data/vendor/diy/test/files/yak/data_source.rb +1 -0
- data/vendor/diy/test/files/yak/fringe_model.rb +4 -0
- data/vendor/diy/test/files/yak/fringe_presenter.rb +4 -0
- data/vendor/diy/test/files/yak/fringe_view.rb +1 -0
- data/vendor/diy/test/files/yak/my_objects.yml +21 -0
- data/vendor/diy/test/test_helper.rb +40 -0
- data/vendor/hardmock/CHANGES +8 -0
- data/vendor/hardmock/LICENSE +7 -0
- data/vendor/hardmock/README +48 -0
- data/vendor/hardmock/Rakefile +100 -0
- data/vendor/hardmock/TODO +7 -0
- data/vendor/hardmock/config/environment.rb +12 -0
- data/vendor/hardmock/homepage/demo.rb +21 -0
- data/vendor/hardmock/homepage/hardmock_sample.png +0 -0
- data/vendor/hardmock/homepage/index.html +65 -0
- data/vendor/hardmock/init.rb +3 -0
- data/vendor/hardmock/lib/hardmock.rb +634 -0
- data/vendor/hardmock/lib/method_cleanout.rb +14 -0
- data/vendor/hardmock/rcov.rake +18 -0
- data/vendor/hardmock/test/functional/assert_error_test.rb +52 -0
- data/vendor/hardmock/test/functional/auto_verify_test.rb +192 -0
- data/vendor/hardmock/test/functional/direct_mock_usage_test.rb +396 -0
- data/vendor/hardmock/test/functional/hardmock_test.rb +380 -0
- data/vendor/hardmock/test/test_helper.rb +23 -0
- data/vendor/hardmock/test/unit/expectation_builder_test.rb +18 -0
- data/vendor/hardmock/test/unit/expector_test.rb +56 -0
- data/vendor/hardmock/test/unit/method_cleanout_test.rb +35 -0
- data/vendor/hardmock/test/unit/mock_control_test.rb +172 -0
- data/vendor/hardmock/test/unit/mock_test.rb +273 -0
- data/vendor/hardmock/test/unit/simple_expectation_test.rb +345 -0
- data/vendor/hardmock/test/unit/trapper_test.rb +60 -0
- data/vendor/hardmock/test/unit/verify_error_test.rb +34 -0
- data/vendor/systir/systir.rb +403 -0
- data/vendor/systir/test/unit/ui/xml/testrunner.rb +192 -0
- data/vendor/systir/test/unit/ui/xml/xmltestrunner.xslt +109 -0
- metadata +235 -0
@@ -0,0 +1,100 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
2
|
+
require 'library_translator'
|
3
|
+
require 'extension/minilab_hardware'
|
4
|
+
|
5
|
+
class LibraryTranslatorTest < Test::Unit::TestCase
|
6
|
+
include MinilabConstants
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@target = LibraryTranslator.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_pins_and_ports(low, high, port)
|
16
|
+
low.upto(high) do |pin|
|
17
|
+
assert_equal port, @target.get_port_for_pin(pin), "Didn't get #{port} for pin #{pin}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# tests
|
22
|
+
should "provide :porta when asked about numbered pins on the hardware's FIRSTPORTA" do
|
23
|
+
check_pins_and_ports(30, 37, :porta)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "provide :portb when asked about numbered pins on the hardware's FIRSTPORTB" do
|
27
|
+
check_pins_and_ports(3, 10, :portb)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "provide :portcl when asked about numbered pins on the hardware's FIRSTPORTCL" do
|
31
|
+
check_pins_and_ports(26, 29, :portcl)
|
32
|
+
end
|
33
|
+
|
34
|
+
should "provide :portch when asked about numbered pins on the hardware's FIRSTPORTCH" do
|
35
|
+
check_pins_and_ports(22, 25, :portch)
|
36
|
+
end
|
37
|
+
|
38
|
+
should "raise an error when asked about a pin number that does not map to a port (such as the pins for ground, 5v +ve, DIO1..3, etc)" do
|
39
|
+
[ 1, 2, "DIO0", "DIO2", nil, :thedude, 832].each do |bad_pin|
|
40
|
+
assert_raise(RuntimeError) { @target.get_port_for_pin(bad_pin) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
should "get the number the library uses for the pin when asked to translate from the numbers on the board (port a pins)" do
|
45
|
+
assert_equal 7, @target.get_library_pin_number(30)
|
46
|
+
assert_equal 6, @target.get_library_pin_number(31)
|
47
|
+
assert_equal 5, @target.get_library_pin_number(32)
|
48
|
+
assert_equal 4, @target.get_library_pin_number(33)
|
49
|
+
assert_equal 3, @target.get_library_pin_number(34)
|
50
|
+
assert_equal 2, @target.get_library_pin_number(35)
|
51
|
+
assert_equal 1, @target.get_library_pin_number(36)
|
52
|
+
assert_equal 0, @target.get_library_pin_number(37)
|
53
|
+
end
|
54
|
+
|
55
|
+
should "get the number the library uses for the pin when asked to translate from the numbers on the board (port b pins)" do
|
56
|
+
assert_equal 15, @target.get_library_pin_number(3)
|
57
|
+
assert_equal 14, @target.get_library_pin_number(4)
|
58
|
+
assert_equal 13, @target.get_library_pin_number(5)
|
59
|
+
assert_equal 12, @target.get_library_pin_number(6)
|
60
|
+
assert_equal 11, @target.get_library_pin_number(7)
|
61
|
+
assert_equal 10, @target.get_library_pin_number(8)
|
62
|
+
assert_equal 9, @target.get_library_pin_number(9)
|
63
|
+
assert_equal 8, @target.get_library_pin_number(10)
|
64
|
+
end
|
65
|
+
|
66
|
+
should "get the number the library uses for the pin when asked to translate from the numbers on the board (port cl pins)" do
|
67
|
+
assert_equal 19, @target.get_library_pin_number(26)
|
68
|
+
assert_equal 18, @target.get_library_pin_number(27)
|
69
|
+
assert_equal 17, @target.get_library_pin_number(28)
|
70
|
+
assert_equal 16, @target.get_library_pin_number(29)
|
71
|
+
end
|
72
|
+
|
73
|
+
should "get the number the library uses for the pin when asked to translate from the numbers on the board (port ch pins)" do
|
74
|
+
assert_equal 23, @target.get_library_pin_number(22)
|
75
|
+
assert_equal 22, @target.get_library_pin_number(23)
|
76
|
+
assert_equal 21, @target.get_library_pin_number(24)
|
77
|
+
assert_equal 20, @target.get_library_pin_number(25)
|
78
|
+
end
|
79
|
+
|
80
|
+
should "raise an error if the pin passed in to get_library_pin_number is invalid" do
|
81
|
+
[20, 21, nil, 12, :heynow, "uba"].each do |bad_pin|
|
82
|
+
assert_raise(RuntimeError) { @target.get_library_pin_number(bad_pin) }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
should "know the mapping between symbolic ports and ports in the library" do
|
87
|
+
assert_equal FIRSTPORTA, @target.get_library_port(:porta), "wrong port"
|
88
|
+
assert_equal FIRSTPORTB, @target.get_library_port(:portb), "wrong port"
|
89
|
+
assert_equal FIRSTPORTCL, @target.get_library_port(:portcl), "wrong port"
|
90
|
+
assert_equal FIRSTPORTCH, @target.get_library_port(:portch), "wrong port"
|
91
|
+
end
|
92
|
+
|
93
|
+
should "raise an error if asked about the library port that does not exist" do
|
94
|
+
[:portd, :portci, "cigarette butt", nil].each do |bad_port|
|
95
|
+
assert_error RuntimeError, "Port #{bad_port} is not a valid port." do
|
96
|
+
@target.get_library_port(bad_port)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
require "minilab_context"
|
3
|
+
require "minilab"
|
4
|
+
|
5
|
+
class MinilabContextTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
MinilabContext.clear
|
8
|
+
@target = MinilabContext.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_context
|
12
|
+
context = nil
|
13
|
+
|
14
|
+
assert_nothing_raised "should build without error" do
|
15
|
+
context = @target.build
|
16
|
+
end
|
17
|
+
assert_not_nil context, "should have gotten a context"
|
18
|
+
|
19
|
+
context
|
20
|
+
end
|
21
|
+
|
22
|
+
should "build minilab context" do
|
23
|
+
context = build_context
|
24
|
+
|
25
|
+
minilab = context[:minilab]
|
26
|
+
assert_not_nil minilab, "should have a minilab object in the context"
|
27
|
+
assert_kind_of Minilab, minilab, "should have gotten a Minilab object"
|
28
|
+
end
|
29
|
+
|
30
|
+
should "allow for the context to be cleared" do
|
31
|
+
first_context = @target.build
|
32
|
+
MinilabContext.clear
|
33
|
+
second_context = @target.build
|
34
|
+
|
35
|
+
assert_not_same first_context, second_context, "context should have been cleared and rebuilt"
|
36
|
+
end
|
37
|
+
|
38
|
+
should "return the same context when built more than once" do
|
39
|
+
first_context = build_context
|
40
|
+
second_context = build_context
|
41
|
+
|
42
|
+
assert_same first_context, second_context, "not the same context object"
|
43
|
+
end
|
44
|
+
|
45
|
+
should "allow arbitrary objects to be injected into the context before it is built" do
|
46
|
+
create_mock(:minilab_hardware)
|
47
|
+
MinilabContext.inject(:object => :minilab_hardware, :instance => @minilab_hardware)
|
48
|
+
|
49
|
+
context = build_context
|
50
|
+
minilab = context[:minilab_hardware]
|
51
|
+
assert_same @minilab_hardware, minilab, "not the same object was returned from the context as was injected"
|
52
|
+
|
53
|
+
create_mock(:kryll)
|
54
|
+
MinilabContext.inject(:object => :kryll, :instance => @kryll)
|
55
|
+
|
56
|
+
context = build_context
|
57
|
+
kryll = context[:kryll]
|
58
|
+
assert_same @kryll, kryll, "not the same object was returned from the context as was injected"
|
59
|
+
end
|
60
|
+
|
61
|
+
should "blow up if trying to inject an object without the appropriate parameters" do
|
62
|
+
assert_error RuntimeError, /missing parameter :object/i do
|
63
|
+
MinilabContext.inject(:instance => "foo")
|
64
|
+
end
|
65
|
+
|
66
|
+
assert_error RuntimeError, /missing parameter :instance/i do
|
67
|
+
MinilabContext.inject(:object => "foo")
|
68
|
+
end
|
69
|
+
|
70
|
+
assert_error RuntimeError, /parameters hash was nil/i do
|
71
|
+
MinilabContext.inject(nil)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
should "raise an error if trying to inject an object into the context after it has been built" do
|
76
|
+
@target.build
|
77
|
+
|
78
|
+
assert_error RuntimeError, /minilab_hardware/i do
|
79
|
+
MinilabContext.inject(:object => 'minilab_hardware', :instance => "kaboo")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
2
|
+
require 'extension/minilab_hardware'
|
3
|
+
|
4
|
+
# The intent of this test is to assert some basic properties on the extension.
|
5
|
+
# Typically I would not check these things, but this class is made from C code.
|
6
|
+
# Even though it's easy to create Ruby constants, methods, etc. with Ruby's C
|
7
|
+
# support, it's still more work than it takes in Ruby syntax. So here I'm
|
8
|
+
# trying to show that the stuff we expect to be there is actually there. It's
|
9
|
+
# also here to help pinpoint any problems that may not show up until system test
|
10
|
+
# time.
|
11
|
+
#
|
12
|
+
# Outside of the tests for checking hash parameters, I'm willing to discuss
|
13
|
+
# whether maintaining this set of tests is truly worthwhile. I may change my
|
14
|
+
# mind.
|
15
|
+
class MinilabHardwareTest < Test::Unit::TestCase
|
16
|
+
include MinilabConstants
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@target = MinilabHardware.new
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have expected constants" do
|
23
|
+
[
|
24
|
+
:DONTPRINT,
|
25
|
+
:STOPALL,
|
26
|
+
:CURRENTREVNUM,
|
27
|
+
:DIGITALIN,
|
28
|
+
:DIGITALOUT,
|
29
|
+
:FIRSTPORTA,
|
30
|
+
:FIRSTPORTB,
|
31
|
+
:FIRSTPORTCL,
|
32
|
+
:FIRSTPORTCH
|
33
|
+
].each do |constant|
|
34
|
+
assert MinilabConstants.const_defined?(constant), "#{constant} should exist as a constant in MinilabConstants"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
should "have the expected methods" do
|
39
|
+
expected_methods =
|
40
|
+
[
|
41
|
+
:setup_error_handling,
|
42
|
+
:declare_revision,
|
43
|
+
:get_revision,
|
44
|
+
:get_error_string,
|
45
|
+
|
46
|
+
:configure_auxport,
|
47
|
+
:configure_port,
|
48
|
+
|
49
|
+
:read_analog,
|
50
|
+
:read_digital_pin,
|
51
|
+
:read_auxport,
|
52
|
+
:read_port,
|
53
|
+
|
54
|
+
:write_analog,
|
55
|
+
:write_digital_pin,
|
56
|
+
:write_auxport,
|
57
|
+
]
|
58
|
+
|
59
|
+
expected_methods.each do |method|
|
60
|
+
assert @target.respond_to?(method), "Minilab hardware object does not respond to #{method.to_s}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
should "raise an error if auxport configuration isn't given the correct hash parameters" do
|
65
|
+
assert_error RuntimeError, ":direction is a required parameter" do
|
66
|
+
@target.configure_auxport(:pin => 3)
|
67
|
+
end
|
68
|
+
|
69
|
+
assert_error RuntimeError, ":pin is a required parameter" do
|
70
|
+
@target.configure_auxport(:direction => DIGITALIN)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
should "raise an error if port configuration isn't given the correct hash parameters" do
|
75
|
+
assert_error RuntimeError, ":direction is a required parameter" do
|
76
|
+
@target.configure_port(:port => FIRSTPORTA)
|
77
|
+
end
|
78
|
+
|
79
|
+
assert_error RuntimeError, ":port is a required parameter" do
|
80
|
+
@target.configure_port(:direction => DIGITALOUT)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
2
|
+
require 'Minilab'
|
3
|
+
require 'extension/minilab_hardware'
|
4
|
+
|
5
|
+
class MinilabTest < Test::Unit::TestCase
|
6
|
+
include MinilabConstants
|
7
|
+
|
8
|
+
def setup
|
9
|
+
mox = create_mocks(:minilab_hardware, :result_verifier, :analog_io,
|
10
|
+
:digital_auxport_io, :digital_port_io)
|
11
|
+
@minilab = Minilab.new(mox)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "allow the user to easily build the minilab object and its dependences" do
|
15
|
+
minilab = nil
|
16
|
+
|
17
|
+
assert_nothing_raised "should build without error" do
|
18
|
+
minilab = Minilab.build
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_not_nil minilab, "should have gotten an object"
|
22
|
+
assert_kind_of Minilab, minilab, "should have gotten a Minilab object"
|
23
|
+
end
|
24
|
+
|
25
|
+
should "connect to the hardware, setup the error handling, declare the library revision, and setup the db37 ports for input" do
|
26
|
+
connect
|
27
|
+
end
|
28
|
+
|
29
|
+
should "bomb out if trying to use a method but haven't connected yet" do
|
30
|
+
assert_not_connected_error { @minilab.read_analog(0) }
|
31
|
+
assert_not_connected_error { @minilab.write_analog(0, 2.2) }
|
32
|
+
assert_not_connected_error { @minilab.read_digital(6) }
|
33
|
+
assert_not_connected_error { @minilab.write_digital(6, 1) }
|
34
|
+
assert_not_connected_error { @minilab.read_digital_byte(:porta) }
|
35
|
+
assert_not_connected_error { @minilab.configure_input_port(:portcl) }
|
36
|
+
assert_not_connected_error { @minilab.configure_output_port(:portb) }
|
37
|
+
end
|
38
|
+
|
39
|
+
# IO tests
|
40
|
+
should "read analog input" do
|
41
|
+
connect
|
42
|
+
@analog_io.expects.read_analog(4).returns(1.1)
|
43
|
+
|
44
|
+
assert_equal 1.1, @minilab.read_analog(4)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "write analog output" do
|
48
|
+
connect
|
49
|
+
@analog_io.expects.write_analog(1, 5.9).returns(true)
|
50
|
+
|
51
|
+
@minilab.write_analog(1, 5.9)
|
52
|
+
end
|
53
|
+
|
54
|
+
should "read digital input from the DIO auxport terminals" do
|
55
|
+
connect
|
56
|
+
@digital_auxport_io.expects.read_digital('DIO1').returns(1)
|
57
|
+
|
58
|
+
assert_equal 1, @minilab.read_digital('DIO1')
|
59
|
+
end
|
60
|
+
|
61
|
+
should "write digital output to the DIO auxport terminals" do
|
62
|
+
connect
|
63
|
+
@digital_auxport_io.expects.write_digital('DIO3', 0).returns(true)
|
64
|
+
|
65
|
+
@minilab.write_digital('DIO3', 0)
|
66
|
+
end
|
67
|
+
|
68
|
+
should "use the digital port object when the pin is a numbered pin for read_digital" do
|
69
|
+
connect
|
70
|
+
@digital_port_io.expects.read_digital(7).returns(1)
|
71
|
+
|
72
|
+
assert_equal 1, @minilab.read_digital(7)
|
73
|
+
end
|
74
|
+
|
75
|
+
should "use the digital port object when the pin is a numbered pin for write_digital" do
|
76
|
+
connect
|
77
|
+
@digital_port_io.expects.write_digital(2, 1).returns(:yourmom)
|
78
|
+
|
79
|
+
assert_equal :yourmom, @minilab.write_digital(2, 1)
|
80
|
+
end
|
81
|
+
|
82
|
+
should "use the digital port object to read a byte from a digital port" do
|
83
|
+
connect
|
84
|
+
@digital_port_io.expects.read_port(:porta).returns(0x22)
|
85
|
+
assert_equal 0x22, @minilab.read_digital_byte(:porta)
|
86
|
+
|
87
|
+
@digital_port_io.expects.read_port(:portcl).returns("monitor")
|
88
|
+
assert_equal "monitor", @minilab.read_digital_byte(:portcl)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Configuration tests
|
92
|
+
should "use the digital port object for configuring a port for input" do
|
93
|
+
connect
|
94
|
+
@digital_port_io.expects.configure_input_port(:portch).returns(true)
|
95
|
+
|
96
|
+
assert @minilab.configure_input_port(:portch)
|
97
|
+
end
|
98
|
+
|
99
|
+
should "use the digital port object for configuring a port for output" do
|
100
|
+
connect
|
101
|
+
@digital_port_io.expects.configure_output_port(:porta).returns(true)
|
102
|
+
|
103
|
+
assert @minilab.configure_output_port(:porta)
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
def connect
|
108
|
+
result1 = { :skype => "good" }
|
109
|
+
result2 = { :button => "round" }
|
110
|
+
|
111
|
+
@minilab_hardware.expects.setup_error_handling(DONTPRINT, STOPALL).returns(result1)
|
112
|
+
@result_verifier.expects.verify(result1, "setup_error_handling")
|
113
|
+
|
114
|
+
@minilab_hardware.expects.declare_revision(CURRENTREVNUM).returns(result2)
|
115
|
+
@result_verifier.expects.verify(result2, "declare_revision")
|
116
|
+
|
117
|
+
ports = [:porta, :portb, "thedude", 54]
|
118
|
+
@digital_port_io.expects.get_valid_ports().returns(ports)
|
119
|
+
ports.each do |port|
|
120
|
+
@digital_port_io.expects.configure_input_port(port)
|
121
|
+
end
|
122
|
+
|
123
|
+
@minilab.connect
|
124
|
+
end
|
125
|
+
|
126
|
+
def assert_not_connected_error
|
127
|
+
error = "Cannot use any minilab methods without calling 'connect' first."
|
128
|
+
assert_error(RuntimeError, error) { yield }
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
2
|
+
require 'result_verifier'
|
3
|
+
|
4
|
+
class ResultVerifierTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
mox = create_mocks :minilab_hardware
|
7
|
+
@target = ResultVerifier.new(mox)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "return true when there is no error and not consult the hardware" do
|
11
|
+
result = { :value => 2 }
|
12
|
+
|
13
|
+
assert_equal true, @target.verify(result)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "raise an exception when there is an error" do
|
17
|
+
result = { :error => 1 }
|
18
|
+
@minilab_hardware.expect.get_error_string(1).returns("kaboom")
|
19
|
+
assert_error(RuntimeError, /kaboom/) { @target.verify(result) }
|
20
|
+
|
21
|
+
|
22
|
+
result = { :error => 2 }
|
23
|
+
@minilab_hardware.expect.get_error_string(2).returns("burn")
|
24
|
+
assert_error(RuntimeError, /burn/) { @target.verify(result) }
|
25
|
+
end
|
26
|
+
|
27
|
+
should "include the custom message passed in the exception that is raised" do
|
28
|
+
result = { :error => 1 }
|
29
|
+
@minilab_hardware.expect.get_error_string(1).returns("oy")
|
30
|
+
|
31
|
+
assert_error(RuntimeError, /argh/) { @target.verify(result, "argh") }
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
= Usage
|
3
|
+
Behaviors provides a single method: should.
|
4
|
+
|
5
|
+
Your test classes should <tt>extend Behaviors</tt>.
|
6
|
+
|
7
|
+
Instead of naming test methods like:
|
8
|
+
|
9
|
+
def test_something
|
10
|
+
end
|
11
|
+
|
12
|
+
You declare test methods like:
|
13
|
+
|
14
|
+
should "perform action" do
|
15
|
+
end
|
16
|
+
|
17
|
+
You also have the ability to declare flunking test methods as a way
|
18
|
+
to describe future tests:
|
19
|
+
|
20
|
+
should "perform other action"
|
21
|
+
|
22
|
+
= Motivation
|
23
|
+
Test methods typically focus on the name of the method under test instead of its behavior.
|
24
|
+
|
25
|
+
Creating test methods with <tt>should</tt> statements focuses on the behaviors of an object.
|
26
|
+
This enhances the TDD experience by provoking the developer to think about the role of the object under test.
|
27
|
+
|
28
|
+
Writing the tests first to declare an object's behaviors and then implementing those
|
29
|
+
behaviors through object methods produces the most value.
|
30
|
+
Using this behavior-driven approach prevents the dangers associated with assuming a one-to-one mapping of method names to
|
31
|
+
test method names.
|
32
|
+
|
33
|
+
For a more complete BDD framework, try RSpec http://rspec.rubyforge.org/
|
34
|
+
|
35
|
+
= Rake tasks
|
36
|
+
|
37
|
+
Behaviors includes a pair of Rake tasks, <tt>behaviors</tt> and <tt>behaviors_html</tt>. These tasks will output to the
|
38
|
+
console or an html file in the <tt>doc</tt> directory with a list all of your <tt>should</tt> tests.
|
39
|
+
Use these tasks to summarize the behavior of your project.
|
40
|
+
=end
|
41
|
+
module Behaviors
|
42
|
+
def should(behave,&block)
|
43
|
+
mname = "test_should_#{behave}"
|
44
|
+
if block
|
45
|
+
define_method mname, &block
|
46
|
+
else
|
47
|
+
puts ">>> UNIMPLEMENTED CASE: #{name.sub(/Test$/,'')} should #{behave}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|