-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_set_spec.rb
107 lines (81 loc) · 3.16 KB
/
example_set_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require 'example_set'
describe "An ExampleSet" do
before(:each) do
@example_set = ExampleSet.new
end
context "when it has many inputs and an equal number of expected outputs" do
it "should offer some flexibility in the way that the user adds inputs and outputs" do
@example_set.inputs = [:a, :b, :c]
@example_set.inputs.should == [:a, :b, :c]
@example_set.outputs = :a, :b, :c
@example_set.outputs.should == [:a, :b, :c]
@example_set.outputs = :a
@example_set.outputs.should == [:a]
end
it "should allow users to define their and outputs using a hash" do
examples = { :a => :x, :b => :y, :c => :z }
@example_set = ExampleSet.new(examples)
@example_set.compare do |input, expected_output|
expected_output.should == examples[input]
end
end
it "should iterate over each input / expected output as a set of pairs in matched sequence" do
inputs = [:a, :b, :c]
outputs = [:x, :y, :z]
@example_set.inputs = inputs
@example_set.outputs = outputs
current_index = 0
@example_set.compare do |input, expected_output|
input.should == inputs[current_index]
expected_output.should == outputs[current_index]
current_index = current_index + 1
end
end
it "should allow comparisons to nil" do
@example_set.inputs = nil
@example_set.outputs = nil
@example_set.compare do |input, expected_output|
input.should == nil
expected_output.should == nil
end
end
end
context "when it has many inputs and a single expected output" do
it "should iterate over each input and compare it to the single expected output" do
inputs = [:a, :b, :c]
output = :z
@example_set.inputs = inputs
@example_set.outputs = output
current_index = 0
@example_set.compare do |input, expected_output|
input.should == inputs[current_index]
expected_output.should == output
current_index = current_index + 1
end
end
end
context "when it has many inputs and a many-but-mismatched number of expected outputs" do
it "should raise an exception" do
@example_set.inputs = [:a, :b, :c]
@example_set.outputs = [:x, :y]
lambda { @example_set.compare { |input, output| true } }.should raise_error(ArgumentError)
end
end
context "when it has more expected outputs than inputs" do
it "should raise an exception" do
@example_set.inputs = [:a, :b, :c]
@example_set.outputs = [:x, :y, :z, :fink]
lambda { @example_set.compare { |input, output| true } }.should raise_error(ArgumentError)
end
end
context "when it has either 0 inputs or outputs" do
it "should raise an exception" do
@example_set.inputs = []
@example_set.outputs = [:x, :y, :z]
lambda { @example_set.compare { |input, output| true } }.should raise_error(ArgumentError)
@example_set.inputs = [:a, :b, :c]
@example_set.outputs = []
lambda { @example_set.compare { |input, output| true } }.should raise_error(ArgumentError)
end
end
end