This repository has been archived by the owner on Oct 27, 2021. It is now read-only.
/
create_matcher.feature
155 lines (134 loc) · 4.51 KB
/
create_matcher.feature
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
Feature: custom matcher shortcut
In order to express my domain clearly in my code examples
As an RSpec user
I want a shortcut for create custom matchers
Scenario: creating a matcher with default messages
Given the following spec:
"""
Spec::Matchers.create :be_a_multiple_of do |expected|
match do |actual|
actual % expected == 0
end
end
describe 9 do
it {should be_a_multiple_of(3)}
end
describe 9 do
it {should_not be_a_multiple_of(4)}
end
# fail intentionally to generate expected output
describe 9 do
it {should be_a_multiple_of(4)}
end
# fail intentionally to generate expected output
describe 9 do
it {should_not be_a_multiple_of(3)}
end
"""
When I run it with the spec command --format specdoc
Then the exit code should be 256
And the stdout should match "should be a multiple of 3"
And the stdout should match "should not be a multiple of 4"
And the stdout should match "should be a multiple of 4 (FAILED - 1)"
And the stdout should match "should not be a multiple of 3 (FAILED - 2)"
And the stdout should match "4 examples, 2 failures"
And the stdout should match "expected 9 to be a multiple of 4"
And the stdout should match "expected 9 not to be a multiple of 3"
Scenario: overriding the failure_message_for_should
Given the following spec:
"""
Spec::Matchers.create :be_a_multiple_of do |expected|
match do |actual|
actual % expected == 0
end
failure_message_for_should do |actual|
"expected that #{actual} would be a multiple of #{expected}"
end
end
# fail intentionally to generate expected output
describe 9 do
it {should be_a_multiple_of(4)}
end
"""
When I run it with the spec command
Then the exit code should be 256
And the stdout should match "1 example, 1 failure"
And the stdout should match "expected that 9 would be a multiple of 4"
Scenario: overriding the failure_message_for_should_not
Given the following spec:
"""
Spec::Matchers.create :be_a_multiple_of do |expected|
match do |actual|
actual % expected == 0
end
failure_message_for_should_not do |actual|
"expected that #{actual} would not be a multiple of #{expected}"
end
end
# fail intentionally to generate expected output
describe 9 do
it {should_not be_a_multiple_of(3)}
end
"""
When I run it with the spec command
Then the exit code should be 256
And the stdout should match "1 example, 1 failure"
And the stdout should match "expected that 9 would not be a multiple of 3"
Scenario: overriding the description
Given the following spec:
"""
Spec::Matchers.create :be_a_multiple_of do |expected|
match do |actual|
actual % expected == 0
end
description do
"be multiple of #{expected}"
end
end
describe 9 do
it {should be_a_multiple_of(3)}
end
describe 9 do
it {should_not be_a_multiple_of(4)}
end
"""
When I run it with the spec command --format specdoc
Then the exit code should be 0
And the stdout should match "2 examples, 0 failures"
And the stdout should match "should be multiple of 3"
And the stdout should match "should not be multiple of 4"
Scenario: with no args
Given the following spec:
"""
Spec::Matchers.create :have_7_fingers do
match do |thing|
thing.fingers.length == 7
end
end
class Thing
def fingers; (1..7).collect {"finger"}; end
end
describe Thing do
it {should have_7_fingers}
end
"""
When I run it with the spec command --format specdoc
Then the exit code should be 0
And the stdout should match "1 example, 0 failures"
And the stdout should match "should have 7 fingers"
Scenario: with multiple args
Given the following spec:
"""
Spec::Matchers.create :be_the_sum_of do |a,b,c,d|
match do |sum|
a + b + c + d == sum
end
end
describe 10 do
it {should be_the_sum_of(1,2,3,4)}
end
"""
When I run it with the spec command --format specdoc
Then the exit code should be 0
And the stdout should match "1 example, 0 failures"
And the stdout should match "should be the sum of 1, 2, 3, and 4"