Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 180 lines (154 sloc) 5.617 kb
045fa96 @dchelimsky deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
authored
1 Feature: define matcher
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
2
3 In order to express my domain clearly in my code examples
4 As an RSpec user
045fa96 @dchelimsky deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
authored
5 I want a shortcut to define custom matchers
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
6
045fa96 @dchelimsky deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
authored
7 Scenario: define a matcher with default messages
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
8 Given a file named "matcher_with_default_message_spec.rb" with:
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
9 """
045fa96 @dchelimsky deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
authored
10 Spec::Matchers.define :be_a_multiple_of do |expected|
e14eb28 @dchelimsky Fixed bug caught by cucumber scenarios (CUCUMBER FTW)
authored
11 match do |actual|
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
12 actual % expected == 0
13 end
14 end
15
16 describe 9 do
17 it {should be_a_multiple_of(3)}
18 end
19
20 describe 9 do
21 it {should_not be_a_multiple_of(4)}
22 end
23
24 # fail intentionally to generate expected output
25 describe 9 do
26 it {should be_a_multiple_of(4)}
27 end
28
29 # fail intentionally to generate expected output
30 describe 9 do
31 it {should_not be_a_multiple_of(3)}
32 end
33
34 """
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
35 When I run "spec matcher_with_default_message_spec.rb --format specdoc"
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
36 Then the exit code should be 256
37
0b2caa7 @dchelimsky stdout should include (in cukes)
authored
38 And the stdout should include "should be a multiple of 3"
39 And the stdout should include "should not be a multiple of 4"
40 And the stdout should include "should be a multiple of 4 (FAILED - 1)"
41 And the stdout should include "should not be a multiple of 3 (FAILED - 2)"
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
42
0b2caa7 @dchelimsky stdout should include (in cukes)
authored
43 And the stdout should include "4 examples, 2 failures"
44 And the stdout should include "expected 9 to be a multiple of 4"
45 And the stdout should include "expected 9 not to be a multiple of 3"
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
46
bac659b @dchelimsky refactor Matcher
authored
47 Scenario: overriding the failure_message_for_should
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
48 Given a file named "matcher_with_failure_message_spec.rb" with:
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
49 """
045fa96 @dchelimsky deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
authored
50 Spec::Matchers.define :be_a_multiple_of do |expected|
e14eb28 @dchelimsky Fixed bug caught by cucumber scenarios (CUCUMBER FTW)
authored
51 match do |actual|
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
52 actual % expected == 0
53 end
819ecf5 @dchelimsky simplify matcher DSL
authored
54 failure_message_for_should do |actual|
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
55 "expected that #{actual} would be a multiple of #{expected}"
56 end
57 end
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
58
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
59 # fail intentionally to generate expected output
60 describe 9 do
61 it {should be_a_multiple_of(4)}
62 end
63 """
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
64 When I run "spec matcher_with_failure_message_spec.rb"
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
65 Then the exit code should be 256
0b2caa7 @dchelimsky stdout should include (in cukes)
authored
66 And the stdout should include "1 example, 1 failure"
67 And the stdout should include "expected that 9 would be a multiple of 4"
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
68
bac659b @dchelimsky refactor Matcher
authored
69 Scenario: overriding the failure_message_for_should_not
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
70 Given a file named "matcher_with_failure_for_message_spec.rb" with:
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
71 """
045fa96 @dchelimsky deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
authored
72 Spec::Matchers.define :be_a_multiple_of do |expected|
e14eb28 @dchelimsky Fixed bug caught by cucumber scenarios (CUCUMBER FTW)
authored
73 match do |actual|
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
74 actual % expected == 0
75 end
819ecf5 @dchelimsky simplify matcher DSL
authored
76 failure_message_for_should_not do |actual|
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
77 "expected that #{actual} would not be a multiple of #{expected}"
78 end
79 end
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
80
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
81 # fail intentionally to generate expected output
82 describe 9 do
83 it {should_not be_a_multiple_of(3)}
84 end
85 """
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
86 When I run "spec matcher_with_failure_for_message_spec.rb"
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
87 Then the exit code should be 256
0b2caa7 @dchelimsky stdout should include (in cukes)
authored
88 And the stdout should include "1 example, 1 failure"
89 And the stdout should include "expected that 9 would not be a multiple of 3"
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
90
bac659b @dchelimsky refactor Matcher
authored
91 Scenario: overriding the description
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
92 Given a file named "matcher_overriding_description_spec.rb" with:
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
93 """
045fa96 @dchelimsky deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
authored
94 Spec::Matchers.define :be_a_multiple_of do |expected|
e14eb28 @dchelimsky Fixed bug caught by cucumber scenarios (CUCUMBER FTW)
authored
95 match do |actual|
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
96 actual % expected == 0
97 end
98 description do
99 "be multiple of #{expected}"
100 end
101 end
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
102
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
103 describe 9 do
104 it {should be_a_multiple_of(3)}
105 end
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
106
5190185 @dchelimsky refine create matcher cuc features
authored
107 describe 9 do
108 it {should_not be_a_multiple_of(4)}
109 end
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
110 """
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
111 When I run "spec matcher_overriding_description_spec.rb --format specdoc"
f0a78ab @dchelimsky more thorough cucumber feature for matcher creation
authored
112 Then the exit code should be 0
0b2caa7 @dchelimsky stdout should include (in cukes)
authored
113 And the stdout should include "2 examples, 0 failures"
114 And the stdout should include "should be multiple of 3"
115 And the stdout should include "should not be multiple of 4"
d2efb4b @dchelimsky added support for 0 to n args in matcher DSL
authored
116
117 Scenario: with no args
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
118 Given a file named "matcher_with_no_args_spec.rb" with:
d2efb4b @dchelimsky added support for 0 to n args in matcher DSL
authored
119 """
045fa96 @dchelimsky deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
authored
120 Spec::Matchers.define :have_7_fingers do
d2efb4b @dchelimsky added support for 0 to n args in matcher DSL
authored
121 match do |thing|
122 thing.fingers.length == 7
123 end
124 end
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
125
d2efb4b @dchelimsky added support for 0 to n args in matcher DSL
authored
126 class Thing
127 def fingers; (1..7).collect {"finger"}; end
128 end
129
130 describe Thing do
131 it {should have_7_fingers}
132 end
133 """
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
134 When I run "spec matcher_with_no_args_spec.rb --format specdoc"
d2efb4b @dchelimsky added support for 0 to n args in matcher DSL
authored
135 Then the exit code should be 0
0b2caa7 @dchelimsky stdout should include (in cukes)
authored
136 And the stdout should include "1 example, 0 failures"
137 And the stdout should include "should have 7 fingers"
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
138
d2efb4b @dchelimsky added support for 0 to n args in matcher DSL
authored
139 Scenario: with multiple args
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
140 Given a file named "matcher_with_multiple_args_spec.rb" with:
d2efb4b @dchelimsky added support for 0 to n args in matcher DSL
authored
141 """
045fa96 @dchelimsky deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
authored
142 Spec::Matchers.define :be_the_sum_of do |a,b,c,d|
d2efb4b @dchelimsky added support for 0 to n args in matcher DSL
authored
143 match do |sum|
144 a + b + c + d == sum
145 end
146 end
147
148 describe 10 do
149 it {should be_the_sum_of(1,2,3,4)}
150 end
151 """
e3a7524 @bmabey converted create_matcher.feature to new step style
bmabey authored
152 When I run "spec matcher_with_multiple_args_spec.rb --format specdoc"
d2efb4b @dchelimsky added support for 0 to n args in matcher DSL
authored
153 Then the exit code should be 0
0b2caa7 @dchelimsky stdout should include (in cukes)
authored
154 And the stdout should include "1 example, 0 failures"
155 And the stdout should include "should be the sum of 1, 2, 3, and 4"
133c40a @dchelimsky add examples to show helper methods in examples
authored
156
157 Scenario: with helper methods
158 Given a file named "matcher_with_internal_helper_spec.rb" with:
159 """
9437a0a @dchelimsky better name
authored
160 Spec::Matchers.define :have_same_elements_as do |sample|
133c40a @dchelimsky add examples to show helper methods in examples
authored
161 match do |actual|
162 similar?(sample, actual)
163 end
164
165 def similar?(a, b)
166 a.sort == b.sort
167 end
168 end
169
170 describe "these two arrays" do
171 specify "should be similar" do
9437a0a @dchelimsky better name
authored
172 [1,2,3].should have_same_elements_as([2,3,1])
133c40a @dchelimsky add examples to show helper methods in examples
authored
173 end
174 end
175 """
176 When I run "spec matcher_with_internal_helper_spec.rb"
177 Then the exit code should be 0
0b2caa7 @dchelimsky stdout should include (in cukes)
authored
178 And the stdout should include "1 example, 0 failures"
045fa96 @dchelimsky deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
authored
179
Something went wrong with that request. Please try again.