Skip to content
This repository
Newer
Older
100644 180 lines (154 sloc) 5.617 kb
045fa962 »
2009-04-08 deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
1 Feature: define matcher
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
2
3 In order to express my domain clearly in my code examples
4 As an RSpec user
045fa962 »
2009-04-08 deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
5 I want a shortcut to define custom matchers
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
6
045fa962 »
2009-04-08 deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
7 Scenario: define a matcher with default messages
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
8 Given a file named "matcher_with_default_message_spec.rb" with:
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
9 """
045fa962 »
2009-04-08 deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
10 Spec::Matchers.define :be_a_multiple_of do |expected|
e14eb28c »
2009-03-03 Fixed bug caught by cucumber scenarios (CUCUMBER FTW)
11 match do |actual|
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
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 """
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
35 When I run "spec matcher_with_default_message_spec.rb --format specdoc"
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
36 Then the exit code should be 256
37
0b2caa75 »
2009-08-23 stdout should include (in cukes)
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)"
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
42
0b2caa75 »
2009-08-23 stdout should include (in cukes)
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"
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
46
bac659bc »
2009-03-03 refactor Matcher
47 Scenario: overriding the failure_message_for_should
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
48 Given a file named "matcher_with_failure_message_spec.rb" with:
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
49 """
045fa962 »
2009-04-08 deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
50 Spec::Matchers.define :be_a_multiple_of do |expected|
e14eb28c »
2009-03-03 Fixed bug caught by cucumber scenarios (CUCUMBER FTW)
51 match do |actual|
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
52 actual % expected == 0
53 end
819ecf59 »
2009-03-03 simplify matcher DSL
54 failure_message_for_should do |actual|
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
55 "expected that #{actual} would be a multiple of #{expected}"
56 end
57 end
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
58
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
59 # fail intentionally to generate expected output
60 describe 9 do
61 it {should be_a_multiple_of(4)}
62 end
63 """
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
64 When I run "spec matcher_with_failure_message_spec.rb"
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
65 Then the exit code should be 256
0b2caa75 »
2009-08-23 stdout should include (in cukes)
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"
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
68
bac659bc »
2009-03-03 refactor Matcher
69 Scenario: overriding the failure_message_for_should_not
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
70 Given a file named "matcher_with_failure_for_message_spec.rb" with:
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
71 """
045fa962 »
2009-04-08 deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
72 Spec::Matchers.define :be_a_multiple_of do |expected|
e14eb28c »
2009-03-03 Fixed bug caught by cucumber scenarios (CUCUMBER FTW)
73 match do |actual|
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
74 actual % expected == 0
75 end
819ecf59 »
2009-03-03 simplify matcher DSL
76 failure_message_for_should_not do |actual|
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
77 "expected that #{actual} would not be a multiple of #{expected}"
78 end
79 end
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
80
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
81 # fail intentionally to generate expected output
82 describe 9 do
83 it {should_not be_a_multiple_of(3)}
84 end
85 """
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
86 When I run "spec matcher_with_failure_for_message_spec.rb"
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
87 Then the exit code should be 256
0b2caa75 »
2009-08-23 stdout should include (in cukes)
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"
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
90
bac659bc »
2009-03-03 refactor Matcher
91 Scenario: overriding the description
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
92 Given a file named "matcher_overriding_description_spec.rb" with:
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
93 """
045fa962 »
2009-04-08 deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
94 Spec::Matchers.define :be_a_multiple_of do |expected|
e14eb28c »
2009-03-03 Fixed bug caught by cucumber scenarios (CUCUMBER FTW)
95 match do |actual|
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
96 actual % expected == 0
97 end
98 description do
99 "be multiple of #{expected}"
100 end
101 end
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
102
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
103 describe 9 do
104 it {should be_a_multiple_of(3)}
105 end
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
106
5190185e »
2009-03-02 refine create matcher cuc features
107 describe 9 do
108 it {should_not be_a_multiple_of(4)}
109 end
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
110 """
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
111 When I run "spec matcher_overriding_description_spec.rb --format specdoc"
f0a78ab0 »
2009-03-02 more thorough cucumber feature for matcher creation
112 Then the exit code should be 0
0b2caa75 »
2009-08-23 stdout should include (in cukes)
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"
d2efb4bc »
2009-03-16 added support for 0 to n args in matcher DSL
116
117 Scenario: with no args
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
118 Given a file named "matcher_with_no_args_spec.rb" with:
d2efb4bc »
2009-03-16 added support for 0 to n args in matcher DSL
119 """
045fa962 »
2009-04-08 deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
120 Spec::Matchers.define :have_7_fingers do
d2efb4bc »
2009-03-16 added support for 0 to n args in matcher DSL
121 match do |thing|
122 thing.fingers.length == 7
123 end
124 end
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
125
d2efb4bc »
2009-03-16 added support for 0 to n args in matcher DSL
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 """
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
134 When I run "spec matcher_with_no_args_spec.rb --format specdoc"
d2efb4bc »
2009-03-16 added support for 0 to n args in matcher DSL
135 Then the exit code should be 0
0b2caa75 »
2009-08-23 stdout should include (in cukes)
136 And the stdout should include "1 example, 0 failures"
137 And the stdout should include "should have 7 fingers"
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
138
d2efb4bc »
2009-03-16 added support for 0 to n args in matcher DSL
139 Scenario: with multiple args
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
140 Given a file named "matcher_with_multiple_args_spec.rb" with:
d2efb4bc »
2009-03-16 added support for 0 to n args in matcher DSL
141 """
045fa962 »
2009-04-08 deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
142 Spec::Matchers.define :be_the_sum_of do |a,b,c,d|
d2efb4bc »
2009-03-16 added support for 0 to n args in matcher DSL
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 """
e3a75241 »
2009-03-31 converted create_matcher.feature to new step style
152 When I run "spec matcher_with_multiple_args_spec.rb --format specdoc"
d2efb4bc »
2009-03-16 added support for 0 to n args in matcher DSL
153 Then the exit code should be 0
0b2caa75 »
2009-08-23 stdout should include (in cukes)
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"
133c40ae »
2009-04-06 add examples to show helper methods in examples
156
157 Scenario: with helper methods
158 Given a file named "matcher_with_internal_helper_spec.rb" with:
159 """
9437a0a4 »
2009-04-08 better name
160 Spec::Matchers.define :have_same_elements_as do |sample|
133c40ae »
2009-04-06 add examples to show helper methods in examples
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
9437a0a4 »
2009-04-08 better name
172 [1,2,3].should have_same_elements_as([2,3,1])
133c40ae »
2009-04-06 add examples to show helper methods in examples
173 end
174 end
175 """
176 When I run "spec matcher_with_internal_helper_spec.rb"
177 Then the exit code should be 0
0b2caa75 »
2009-08-23 stdout should include (in cukes)
178 And the stdout should include "1 example, 0 failures"
045fa962 »
2009-04-08 deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
179
Something went wrong with that request. Please try again.