rspec-expectations 2.1.0 → 2.2.0
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/Gemfile +1 -1
- data/History.markdown +4 -0
- data/License.txt +1 -1
- data/{README.markdown → README.md} +11 -3
- data/features/expectations/customized_message.feature +14 -46
- data/features/matchers/be.feature +149 -0
- data/features/matchers/match.feature +50 -0
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers/have.rb +3 -3
- data/lib/rspec/matchers/matcher.rb +4 -4
- data/lib/rspec/matchers/method_missing.rb +6 -3
- data/rspec-expectations.gemspec +1 -1
- metadata +12 -8
data/Gemfile
CHANGED
data/History.markdown
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## rspec-expectations release history (incomplete)
|
2
2
|
|
3
|
+
### 2.2.0 / 2010-11-28
|
4
|
+
|
5
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.1.0...v2.2.0)
|
6
|
+
|
3
7
|
### 2.1.0 / 2010-11-07
|
4
8
|
|
5
9
|
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.1...v2.1.0)
|
data/License.txt
CHANGED
@@ -5,13 +5,21 @@ RSpec::Matchers, a library of standard matchers.
|
|
5
5
|
|
6
6
|
## Documentation
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
The [Cucumber features](http://relishapp.com/rspec/rspec-expectations/v/2-1)
|
9
|
+
are the most comprehensive and up-to-date docs for end-users.
|
10
|
+
|
11
|
+
The [RDoc](http://rubydoc.info/gems/rspec-expectations/2.1/frames) provides
|
12
|
+
additional information for contributors and/or extenders.
|
13
|
+
|
14
|
+
All of the documentation is open source and a work in progress. If you find it
|
15
|
+
lacking or confusing, you can help improve it by submitting requests and
|
16
|
+
patches to the [rspec-expectations issue
|
17
|
+
tracker](https://github.com/rspec/rspec-expectations/issues).
|
10
18
|
|
11
19
|
## Install
|
12
20
|
|
13
21
|
gem install rspec # for rspec-core, rspec-expectations, rspec-mocks
|
14
|
-
gem install rspec-expecctations # for rspec-
|
22
|
+
gem install rspec-expecctations # for rspec-expectations only
|
15
23
|
|
16
24
|
## Matchers
|
17
25
|
|
@@ -1,54 +1,22 @@
|
|
1
1
|
Feature: customized message
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
RSpec tries to provide useful failure messages, but for cases in which you
|
4
|
+
want more specific information, you can define your own message right in the
|
5
|
+
example. This works for any matcher _other than the operator matchers_.
|
6
6
|
|
7
|
-
Scenario:
|
8
|
-
Given a file named "
|
7
|
+
Scenario: customize failure message
|
8
|
+
Given a file named "example_spec.rb" with:
|
9
9
|
"""
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
def waiting?
|
18
|
-
@state == :waiting
|
19
|
-
end
|
20
|
-
def started?
|
21
|
-
@state == :started
|
22
|
-
end
|
23
|
-
def start
|
24
|
-
@state = :started
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "a new Node" do
|
29
|
-
it "should be waiting" do
|
30
|
-
node = Node.new(:started) #start w/ started to trigger failure
|
31
|
-
node.should be_waiting, "node.state: #{node.state} (first example)"
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should not be started" do
|
35
|
-
node = Node.new(:started) #start w/ started to trigger failure
|
36
|
-
node.should_not be_started, "node.state: #{node.state} (second example)"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "node.start" do
|
41
|
-
it "should change the state" do
|
42
|
-
node = Node.new(:started) #start w/ started to trigger failure
|
43
|
-
lambda {node.start}.should change{node.state}, "expected a change"
|
10
|
+
describe Array do
|
11
|
+
context "when created with `new`" do
|
12
|
+
it "is empty" do
|
13
|
+
array = Array.new
|
14
|
+
array << 1 # trigger a failure to demonstrate the message
|
15
|
+
array.should be_empty, "expected empty array, got #{array.inspect}"
|
16
|
+
end
|
44
17
|
end
|
45
18
|
end
|
46
19
|
|
47
20
|
"""
|
48
|
-
When I run "rspec
|
49
|
-
Then the output should contain "
|
50
|
-
And the output should not contain "to return true, got false"
|
51
|
-
And the output should not contain "to return false, got true"
|
52
|
-
And the output should contain "node.state: started (first example)"
|
53
|
-
And the output should contain "node.state: started (second example)"
|
54
|
-
And the output should contain "expected a change"
|
21
|
+
When I run "rspec example_spec.rb --format documentation"
|
22
|
+
Then the output should contain "expected empty array, got [1]"
|
@@ -0,0 +1,149 @@
|
|
1
|
+
Feature: be matchers
|
2
|
+
|
3
|
+
There are several related "be" matchers:
|
4
|
+
|
5
|
+
* obj.should be_true # passes if obj is truthy (not nil or false)
|
6
|
+
* obj.should be_false # passes if obj is falsey (nil or false)
|
7
|
+
* obj.should be_nil # passes if obj is nil
|
8
|
+
* obj.should be # passes if obj is not nil
|
9
|
+
* obj.should be < expected # passes if obj < expected
|
10
|
+
* obj.should be > expected # passes if obj > expected
|
11
|
+
* obj.should be <= expected # passes if obj <= expected
|
12
|
+
* obj.should be >= expected # passes if obj >= expected
|
13
|
+
|
14
|
+
Scenario: be_true matcher
|
15
|
+
Given a file named "be_true_spec.rb" with:
|
16
|
+
"""
|
17
|
+
describe "be_true matcher" do
|
18
|
+
specify { true.should be_true }
|
19
|
+
specify { 7.should be_true }
|
20
|
+
specify { "foo".should be_true }
|
21
|
+
specify { nil.should_not be_true }
|
22
|
+
specify { false.should_not be_true }
|
23
|
+
|
24
|
+
# deliberate failures
|
25
|
+
specify { true.should_not be_true }
|
26
|
+
specify { 7.should_not be_true }
|
27
|
+
specify { "foo".should_not be_true }
|
28
|
+
specify { nil.should be_true }
|
29
|
+
specify { false.should be_true }
|
30
|
+
end
|
31
|
+
"""
|
32
|
+
When I run "rspec be_true_spec.rb"
|
33
|
+
Then the output should contain all of these:
|
34
|
+
| 10 examples, 5 failures |
|
35
|
+
| expected true not to be true |
|
36
|
+
| expected 7 not to be true |
|
37
|
+
| expected "foo" not to be true |
|
38
|
+
| expected nil to be true |
|
39
|
+
| expected false to be true |
|
40
|
+
|
41
|
+
Scenario: be_false matcher
|
42
|
+
Given a file named "be_false_spec.rb" with:
|
43
|
+
"""
|
44
|
+
describe "be_false matcher" do
|
45
|
+
specify { nil.should be_false }
|
46
|
+
specify { false.should be_false }
|
47
|
+
specify { true.should_not be_false }
|
48
|
+
specify { 7.should_not be_false }
|
49
|
+
specify { "foo".should_not be_false }
|
50
|
+
|
51
|
+
# deliberate failures
|
52
|
+
specify { nil.should_not be_false }
|
53
|
+
specify { false.should_not be_false }
|
54
|
+
specify { true.should be_false }
|
55
|
+
specify { 7.should be_false }
|
56
|
+
specify { "foo".should be_false }
|
57
|
+
end
|
58
|
+
"""
|
59
|
+
When I run "rspec be_false_spec.rb"
|
60
|
+
Then the output should contain all of these:
|
61
|
+
| 10 examples, 5 failures |
|
62
|
+
| expected nil not to be false |
|
63
|
+
| expected false not to be false |
|
64
|
+
| expected true to be false |
|
65
|
+
| expected 7 to be false |
|
66
|
+
| expected "foo" to be false |
|
67
|
+
|
68
|
+
Scenario: be_nil matcher
|
69
|
+
Given a file named "be_nil_spec.rb" with:
|
70
|
+
"""
|
71
|
+
describe "be_nil matcher" do
|
72
|
+
specify { nil.should be_nil }
|
73
|
+
specify { false.should_not be_nil }
|
74
|
+
specify { true.should_not be_nil }
|
75
|
+
specify { 7.should_not be_nil }
|
76
|
+
specify { "foo".should_not be_nil }
|
77
|
+
|
78
|
+
# deliberate failures
|
79
|
+
specify { nil.should_not be_nil }
|
80
|
+
specify { false.should be_nil }
|
81
|
+
specify { true.should be_nil }
|
82
|
+
specify { 7.should be_nil }
|
83
|
+
specify { "foo".should be_nil }
|
84
|
+
end
|
85
|
+
"""
|
86
|
+
When I run "rspec be_nil_spec.rb"
|
87
|
+
Then the output should contain all of these:
|
88
|
+
| 10 examples, 5 failures |
|
89
|
+
| expected not nil, got nil |
|
90
|
+
| expected nil, got false |
|
91
|
+
| expected nil, got true |
|
92
|
+
| expected nil, got 7 |
|
93
|
+
| expected nil, got "foo" |
|
94
|
+
|
95
|
+
Scenario: be matcher
|
96
|
+
Given a file named "be_spec.rb" with:
|
97
|
+
"""
|
98
|
+
describe "be_matcher" do
|
99
|
+
specify { true.should be }
|
100
|
+
specify { 7.should be }
|
101
|
+
specify { "foo".should be }
|
102
|
+
specify { nil.should_not be }
|
103
|
+
specify { false.should_not be }
|
104
|
+
|
105
|
+
# deliberate failures
|
106
|
+
specify { true.should_not be }
|
107
|
+
specify { 7.should_not be }
|
108
|
+
specify { "foo".should_not be }
|
109
|
+
specify { nil.should be }
|
110
|
+
specify { false.should be }
|
111
|
+
end
|
112
|
+
"""
|
113
|
+
When I run "rspec be_spec.rb"
|
114
|
+
Then the output should contain all of these:
|
115
|
+
| 10 examples, 5 failures |
|
116
|
+
| expected true to evaluate to false |
|
117
|
+
| expected 7 to evaluate to false |
|
118
|
+
| expected "foo" to evaluate to false |
|
119
|
+
| expected nil to evaluate to true |
|
120
|
+
| expected false to evaluate to true |
|
121
|
+
|
122
|
+
Scenario: be operator matchers
|
123
|
+
Given a file named "be_operators_spec.rb" with:
|
124
|
+
"""
|
125
|
+
describe 17 do
|
126
|
+
it { should be < 20 }
|
127
|
+
it { should be > 15 }
|
128
|
+
it { should be <= 17 }
|
129
|
+
it { should be >= 17 }
|
130
|
+
it { should_not be < 15 }
|
131
|
+
it { should_not be > 20 }
|
132
|
+
it { should_not be <= 16 }
|
133
|
+
it { should_not be >= 18 }
|
134
|
+
|
135
|
+
# deliberate failures
|
136
|
+
it { should be < 15 }
|
137
|
+
it { should be > 20 }
|
138
|
+
it { should be <= 16 }
|
139
|
+
it { should be >= 18 }
|
140
|
+
end
|
141
|
+
"""
|
142
|
+
When I run "rspec be_operators_spec.rb"
|
143
|
+
Then the output should contain all of these:
|
144
|
+
| 12 examples, 4 failures |
|
145
|
+
| expected < 15, got 17 |
|
146
|
+
| expected > 20, got 17 |
|
147
|
+
| expected <= 16, got 17 |
|
148
|
+
| expected >= 18, got 17 |
|
149
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
Feature: match matcher
|
2
|
+
|
3
|
+
The match matcher calls #match on the object, passing if #match returns a
|
4
|
+
truthy (not false or nil) value. Regexp and String both provide a #match
|
5
|
+
method.
|
6
|
+
|
7
|
+
"a string".should match(/str/) # passes
|
8
|
+
"a string".should match(/foo/) # fails
|
9
|
+
/foo/.should match("food") # passes
|
10
|
+
/foo/.should match("drinks") # fails
|
11
|
+
|
12
|
+
This is equivalent to using the =~ matcher (see the operator matchers
|
13
|
+
feature for more details).
|
14
|
+
|
15
|
+
Scenario: string usage
|
16
|
+
Given a file named "string_match_spec.rb" with:
|
17
|
+
"""
|
18
|
+
describe "a string" do
|
19
|
+
it { should match(/str/) }
|
20
|
+
it { should_not match(/foo/) }
|
21
|
+
|
22
|
+
# deliberate failures
|
23
|
+
it { should_not match(/str/) }
|
24
|
+
it { should match(/foo/) }
|
25
|
+
end
|
26
|
+
"""
|
27
|
+
When I run "rspec string_match_spec.rb"
|
28
|
+
Then the output should contain all of these:
|
29
|
+
| 4 examples, 2 failures |
|
30
|
+
| expected "a string" not to match /str/ |
|
31
|
+
| expected "a string" to match /foo/ |
|
32
|
+
|
33
|
+
Scenario: regular expression usage
|
34
|
+
Given a file named "regexp_match_spec.rb" with:
|
35
|
+
"""
|
36
|
+
describe /foo/ do
|
37
|
+
it { should match("food") }
|
38
|
+
it { should_not match("drinks") }
|
39
|
+
|
40
|
+
# deliberate failures
|
41
|
+
it { should_not match("food") }
|
42
|
+
it { should match("drinks") }
|
43
|
+
end
|
44
|
+
"""
|
45
|
+
When I run "rspec regexp_match_spec.rb"
|
46
|
+
Then the output should contain all of these:
|
47
|
+
| 4 examples, 2 failures |
|
48
|
+
| expected /foo/ not to match "food" |
|
49
|
+
| expected /foo/ to match "drinks" |
|
50
|
+
|
data/lib/rspec/matchers/have.rb
CHANGED
@@ -73,10 +73,10 @@ EOF
|
|
73
73
|
|
74
74
|
private
|
75
75
|
|
76
|
-
def method_missing(
|
77
|
-
@collection_name =
|
76
|
+
def method_missing(method, *args, &block)
|
77
|
+
@collection_name = method
|
78
78
|
if inflector = (defined?(ActiveSupport::Inflector) && ActiveSupport::Inflector.respond_to?(:pluralize) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
|
79
|
-
@plural_collection_name = inflector.pluralize(
|
79
|
+
@plural_collection_name = inflector.pluralize(method.to_s)
|
80
80
|
end
|
81
81
|
@args = args
|
82
82
|
@block = block
|
@@ -107,11 +107,11 @@ module RSpec
|
|
107
107
|
|
108
108
|
private
|
109
109
|
|
110
|
-
def method_missing(
|
111
|
-
if $matcher_execution_context.respond_to?(
|
112
|
-
$matcher_execution_context.send
|
110
|
+
def method_missing(method, *args, &block)
|
111
|
+
if $matcher_execution_context.respond_to?(method)
|
112
|
+
$matcher_execution_context.send method, *args, &block
|
113
113
|
else
|
114
|
-
super(
|
114
|
+
super(method, *args, &block)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -1,8 +1,11 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Matchers
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def method_missing(method, *args, &block) # :nodoc:
|
7
|
+
return Matchers::BePredicate.new(method, *args, &block) if method.to_s =~ /^be_/
|
8
|
+
return Matchers::Has.new(method, *args, &block) if method.to_s =~ /^have_/
|
6
9
|
super
|
7
10
|
end
|
8
11
|
end
|
data/rspec-expectations.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.files = `git ls-files`.split("\n")
|
19
19
|
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
-
s.extra_rdoc_files = [ "README.
|
21
|
+
s.extra_rdoc_files = [ "README.md" ]
|
22
22
|
s.rdoc_options = ["--charset=UTF-8"]
|
23
23
|
s.require_path = "lib"
|
24
24
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 2.
|
9
|
+
version: 2.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- David Chelimsky
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-28 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -40,14 +40,14 @@ executables: []
|
|
40
40
|
extensions: []
|
41
41
|
|
42
42
|
extra_rdoc_files:
|
43
|
-
- README.
|
43
|
+
- README.md
|
44
44
|
files:
|
45
45
|
- .document
|
46
46
|
- .gitignore
|
47
47
|
- Gemfile
|
48
48
|
- History.markdown
|
49
49
|
- License.txt
|
50
|
-
- README.
|
50
|
+
- README.md
|
51
51
|
- Rakefile
|
52
52
|
- Upgrade.markdown
|
53
53
|
- cucumber.yml
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- features/expectations/diffing.feature
|
58
58
|
- features/expectations/implicit_docstrings.feature
|
59
59
|
- features/matchers/access_running_example.feature
|
60
|
+
- features/matchers/be.feature
|
60
61
|
- features/matchers/be_within.feature
|
61
62
|
- features/matchers/define_diffable_matcher.feature
|
62
63
|
- features/matchers/define_matcher.feature
|
@@ -68,6 +69,7 @@ files:
|
|
68
69
|
- features/matchers/expect_error.feature
|
69
70
|
- features/matchers/have.feature
|
70
71
|
- features/matchers/include.feature
|
72
|
+
- features/matchers/match.feature
|
71
73
|
- features/matchers/operators.feature
|
72
74
|
- features/matchers/predicates.feature
|
73
75
|
- features/matchers/respond_to.feature
|
@@ -167,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
169
|
requirements:
|
168
170
|
- - ">="
|
169
171
|
- !ruby/object:Gem::Version
|
170
|
-
hash: -
|
172
|
+
hash: -833655942959929431
|
171
173
|
segments:
|
172
174
|
- 0
|
173
175
|
version: "0"
|
@@ -176,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
178
|
requirements:
|
177
179
|
- - ">="
|
178
180
|
- !ruby/object:Gem::Version
|
179
|
-
hash: -
|
181
|
+
hash: -833655942959929431
|
180
182
|
segments:
|
181
183
|
- 0
|
182
184
|
version: "0"
|
@@ -186,7 +188,7 @@ rubyforge_project: rspec
|
|
186
188
|
rubygems_version: 1.3.7
|
187
189
|
signing_key:
|
188
190
|
specification_version: 3
|
189
|
-
summary: rspec-expectations-2.
|
191
|
+
summary: rspec-expectations-2.2.0
|
190
192
|
test_files:
|
191
193
|
- features/README.markdown
|
192
194
|
- features/expectations/attribute_of_subject.feature
|
@@ -194,6 +196,7 @@ test_files:
|
|
194
196
|
- features/expectations/diffing.feature
|
195
197
|
- features/expectations/implicit_docstrings.feature
|
196
198
|
- features/matchers/access_running_example.feature
|
199
|
+
- features/matchers/be.feature
|
197
200
|
- features/matchers/be_within.feature
|
198
201
|
- features/matchers/define_diffable_matcher.feature
|
199
202
|
- features/matchers/define_matcher.feature
|
@@ -205,6 +208,7 @@ test_files:
|
|
205
208
|
- features/matchers/expect_error.feature
|
206
209
|
- features/matchers/have.feature
|
207
210
|
- features/matchers/include.feature
|
211
|
+
- features/matchers/match.feature
|
208
212
|
- features/matchers/operators.feature
|
209
213
|
- features/matchers/predicates.feature
|
210
214
|
- features/matchers/respond_to.feature
|