rspec-expectations 2.0.0.beta.22 → 2.6.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/.gitignore +1 -1
- data/.travis.yml +7 -0
- data/Gemfile +35 -13
- data/Guardfile +5 -0
- data/License.txt +1 -1
- data/README.md +43 -0
- data/Rakefile +51 -9
- data/cucumber.yml +9 -2
- data/features/.nav +29 -0
- data/features/Changelog.md +101 -0
- data/features/README.markdown +45 -8
- data/features/built_in_matchers/README.md +71 -0
- data/features/built_in_matchers/be.feature +135 -0
- data/features/built_in_matchers/be_within.feature +43 -0
- data/features/built_in_matchers/cover.feature +45 -0
- data/features/{matchers → built_in_matchers}/equality.feature +16 -13
- data/features/built_in_matchers/exist.feature +43 -0
- data/features/built_in_matchers/expect_change.feature +59 -0
- data/features/built_in_matchers/expect_error.feature +105 -0
- data/features/built_in_matchers/have.feature +103 -0
- data/features/built_in_matchers/include.feature +121 -0
- data/features/built_in_matchers/match.feature +50 -0
- data/features/built_in_matchers/operators.feature +221 -0
- data/features/built_in_matchers/predicates.feature +128 -0
- data/features/built_in_matchers/respond_to.feature +78 -0
- data/features/built_in_matchers/satisfy.feature +31 -0
- data/features/built_in_matchers/throw_symbol.feature +85 -0
- data/features/built_in_matchers/types.feature +114 -0
- data/features/{matchers → custom_matchers}/access_running_example.feature +2 -2
- data/features/{matchers → custom_matchers}/define_diffable_matcher.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher.feature +91 -9
- data/features/{matchers → custom_matchers}/define_matcher_outside_rspec.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher_with_fluent_interface.feature +8 -11
- data/features/customized_message.feature +22 -0
- data/features/{expectations/diffing.feature → diffing.feature} +16 -16
- data/features/{expectations/implicit_docstrings.feature → implicit_docstrings.feature} +4 -4
- data/features/step_definitions/additional_cli_steps.rb +22 -0
- data/features/support/env.rb +5 -1
- data/features/test_frameworks/test_unit.feature +46 -0
- data/lib/rspec/expectations/backward_compatibility.rb +22 -1
- data/lib/rspec/expectations/deprecation.rb +36 -0
- data/lib/rspec/expectations/extensions.rb +0 -1
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +2 -1
- data/lib/rspec/matchers/be.rb +4 -4
- data/lib/rspec/matchers/be_close.rb +2 -17
- data/lib/rspec/matchers/be_within.rb +40 -0
- data/lib/rspec/matchers/block_aliases.rb +19 -0
- data/lib/rspec/matchers/change.rb +74 -49
- data/lib/rspec/matchers/cover.rb +35 -0
- data/lib/rspec/matchers/exist.rb +13 -3
- data/lib/rspec/matchers/has.rb +15 -11
- data/lib/rspec/matchers/have.rb +5 -5
- data/lib/rspec/matchers/include.rb +14 -5
- data/lib/rspec/matchers/matcher.rb +39 -13
- data/lib/rspec/matchers/method_missing.rb +6 -3
- data/lib/rspec/matchers/operator_matcher.rb +12 -3
- data/lib/rspec/matchers/respond_to.rb +23 -9
- data/lib/rspec/matchers/satisfy.rb +4 -0
- data/lib/rspec/matchers/throw_symbol.rb +43 -26
- data/lib/rspec/matchers.rb +15 -3
- data/rspec-expectations.gemspec +2 -6
- data/spec/rspec/matchers/be_close_spec.rb +11 -39
- data/spec/rspec/matchers/be_spec.rb +8 -8
- data/spec/rspec/matchers/be_within_spec.rb +64 -0
- data/spec/rspec/matchers/change_spec.rb +88 -9
- data/spec/rspec/matchers/cover_spec.rb +65 -0
- data/spec/rspec/matchers/description_generation_spec.rb +41 -25
- data/spec/rspec/matchers/exist_spec.rb +90 -51
- data/spec/rspec/matchers/has_spec.rb +2 -2
- data/spec/rspec/matchers/have_spec.rb +291 -291
- data/spec/rspec/matchers/include_spec.rb +318 -65
- data/spec/rspec/matchers/matcher_spec.rb +91 -0
- data/spec/rspec/matchers/matchers_spec.rb +29 -0
- data/spec/rspec/matchers/method_missing_spec.rb +23 -0
- data/spec/rspec/matchers/operator_matcher_spec.rb +36 -10
- data/spec/rspec/matchers/respond_to_spec.rb +177 -1
- data/spec/rspec/matchers/satisfy_spec.rb +4 -0
- data/spec/rspec/matchers/throw_symbol_spec.rb +27 -10
- data/spec/spec_helper.rb +10 -35
- data/spec/support/classes.rb +1 -1
- data/spec/support/matchers.rb +22 -0
- data/spec/support/ruby_version.rb +10 -0
- metadata +95 -114
- data/History.md +0 -16
- data/README.markdown +0 -23
- data/features/expectations/attribute_of_subject.feature +0 -19
- data/features/expectations/customized_message.feature +0 -54
- data/features/matchers/expect_change.feature +0 -65
- data/features/matchers/expect_error.feature +0 -44
- data/lib/rspec/expectations/extensions/rspec/core/example_group.rb +0 -19
- data/spec/suite.rb +0 -1
- /data/{Upgrade.markdown → features/Upgrade.md} +0 -0
|
@@ -9,42 +9,42 @@ describe "Matchers should be able to generate their own descriptions" do
|
|
|
9
9
|
"this".should == "this"
|
|
10
10
|
RSpec::Matchers.generated_description.should == "should == \"this\""
|
|
11
11
|
end
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
it "should not == expected" do
|
|
14
14
|
"this".should_not == "that"
|
|
15
15
|
RSpec::Matchers.generated_description.should == "should not == \"that\""
|
|
16
16
|
end
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
it "should be empty (arbitrary predicate)" do
|
|
19
19
|
[].should be_empty
|
|
20
20
|
RSpec::Matchers.generated_description.should == "should be empty"
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
it "should not be empty (arbitrary predicate)" do
|
|
24
24
|
[1].should_not be_empty
|
|
25
25
|
RSpec::Matchers.generated_description.should == "should not be empty"
|
|
26
26
|
end
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
it "should be true" do
|
|
29
29
|
true.should be_true
|
|
30
30
|
RSpec::Matchers.generated_description.should == "should be true"
|
|
31
31
|
end
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
it "should be false" do
|
|
34
34
|
false.should be_false
|
|
35
35
|
RSpec::Matchers.generated_description.should == "should be false"
|
|
36
36
|
end
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
it "should be nil" do
|
|
39
39
|
nil.should be_nil
|
|
40
40
|
RSpec::Matchers.generated_description.should == "should be nil"
|
|
41
41
|
end
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
it "should be > n" do
|
|
44
44
|
5.should be > 3
|
|
45
45
|
RSpec::Matchers.generated_description.should == "should be > 3"
|
|
46
46
|
end
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
it "should be predicate arg1, arg2 and arg3" do
|
|
49
49
|
5.0.should be_between(0,10)
|
|
50
50
|
RSpec::Matchers.generated_description.should == "should be between 0 and 10"
|
|
@@ -55,42 +55,58 @@ describe "Matchers should be able to generate their own descriptions" do
|
|
|
55
55
|
expected.should equal(expected)
|
|
56
56
|
RSpec::Matchers.generated_description.should == "should equal \"expected\""
|
|
57
57
|
end
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
it "should_not equal" do
|
|
60
60
|
5.should_not equal(37)
|
|
61
61
|
RSpec::Matchers.generated_description.should == "should not equal 37"
|
|
62
62
|
end
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
it "should eql" do
|
|
65
65
|
"string".should eql("string")
|
|
66
66
|
RSpec::Matchers.generated_description.should == "should eql \"string\""
|
|
67
67
|
end
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
it "should not eql" do
|
|
70
70
|
"a".should_not eql(:a)
|
|
71
71
|
RSpec::Matchers.generated_description.should == "should not eql :a"
|
|
72
72
|
end
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
it "should have_key" do
|
|
75
75
|
{:a => "a"}.should have_key(:a)
|
|
76
76
|
RSpec::Matchers.generated_description.should == "should have key :a"
|
|
77
77
|
end
|
|
78
|
-
|
|
78
|
+
|
|
79
|
+
it "should have_some_method" do
|
|
80
|
+
object = Object.new
|
|
81
|
+
def object.has_eyes_closed?; true; end
|
|
82
|
+
|
|
83
|
+
object.should have_eyes_closed
|
|
84
|
+
RSpec::Matchers.generated_description.should == 'should have eyes closed'
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "should have_some_method(args*)" do
|
|
88
|
+
object = Object.new
|
|
89
|
+
def object.has_taste_for?(*args); true; end
|
|
90
|
+
|
|
91
|
+
object.should have_taste_for("wine", "cheese")
|
|
92
|
+
RSpec::Matchers.generated_description.should == 'should have taste for "wine", "cheese"'
|
|
93
|
+
end
|
|
94
|
+
|
|
79
95
|
it "should have n items" do
|
|
80
96
|
team.should have(3).players
|
|
81
97
|
RSpec::Matchers.generated_description.should == "should have 3 players"
|
|
82
98
|
end
|
|
83
|
-
|
|
99
|
+
|
|
84
100
|
it "should have at least n items" do
|
|
85
101
|
team.should have_at_least(2).players
|
|
86
102
|
RSpec::Matchers.generated_description.should == "should have at least 2 players"
|
|
87
103
|
end
|
|
88
|
-
|
|
104
|
+
|
|
89
105
|
it "should have at most n items" do
|
|
90
106
|
team.should have_at_most(4).players
|
|
91
107
|
RSpec::Matchers.generated_description.should == "should have at most 4 players"
|
|
92
108
|
end
|
|
93
|
-
|
|
109
|
+
|
|
94
110
|
it "should include" do
|
|
95
111
|
[1,2,3].should include(3)
|
|
96
112
|
RSpec::Matchers.generated_description.should == "should include 3"
|
|
@@ -100,42 +116,42 @@ describe "Matchers should be able to generate their own descriptions" do
|
|
|
100
116
|
[1,2,3].should =~ [1,2,3]
|
|
101
117
|
RSpec::Matchers.generated_description.should == "should contain exactly 1, 2 and 3"
|
|
102
118
|
end
|
|
103
|
-
|
|
119
|
+
|
|
104
120
|
it "should match" do
|
|
105
121
|
"this string".should match(/this string/)
|
|
106
122
|
RSpec::Matchers.generated_description.should == "should match /this string/"
|
|
107
123
|
end
|
|
108
|
-
|
|
124
|
+
|
|
109
125
|
it "should raise_error" do
|
|
110
126
|
lambda { raise }.should raise_error
|
|
111
127
|
RSpec::Matchers.generated_description.should == "should raise Exception"
|
|
112
128
|
end
|
|
113
|
-
|
|
129
|
+
|
|
114
130
|
it "should raise_error with type" do
|
|
115
131
|
lambda { raise }.should raise_error(RuntimeError)
|
|
116
132
|
RSpec::Matchers.generated_description.should == "should raise RuntimeError"
|
|
117
133
|
end
|
|
118
|
-
|
|
134
|
+
|
|
119
135
|
it "should raise_error with type and message" do
|
|
120
136
|
lambda { raise "there was an error" }.should raise_error(RuntimeError, "there was an error")
|
|
121
137
|
RSpec::Matchers.generated_description.should == "should raise RuntimeError with \"there was an error\""
|
|
122
138
|
end
|
|
123
|
-
|
|
139
|
+
|
|
124
140
|
it "should respond_to" do
|
|
125
141
|
[].should respond_to(:insert)
|
|
126
142
|
RSpec::Matchers.generated_description.should == "should respond to #insert"
|
|
127
143
|
end
|
|
128
|
-
|
|
144
|
+
|
|
129
145
|
it "should throw symbol" do
|
|
130
146
|
lambda { throw :what_a_mess }.should throw_symbol
|
|
131
147
|
RSpec::Matchers.generated_description.should == "should throw a Symbol"
|
|
132
148
|
end
|
|
133
|
-
|
|
149
|
+
|
|
134
150
|
it "should throw symbol (with named symbol)" do
|
|
135
151
|
lambda { throw :what_a_mess }.should throw_symbol(:what_a_mess)
|
|
136
152
|
RSpec::Matchers.generated_description.should == "should throw :what_a_mess"
|
|
137
153
|
end
|
|
138
|
-
|
|
154
|
+
|
|
139
155
|
def team
|
|
140
156
|
Class.new do
|
|
141
157
|
def players
|
|
@@ -152,7 +168,7 @@ describe "a Matcher with no description" do
|
|
|
152
168
|
def failure_message; ""; end
|
|
153
169
|
end.new
|
|
154
170
|
end
|
|
155
|
-
|
|
171
|
+
|
|
156
172
|
it "provides a helpful message when used in a string-less example block" do
|
|
157
173
|
5.should matcher
|
|
158
174
|
RSpec::Matchers.generated_description.should =~ /When you call.*description method/m
|
|
@@ -1,65 +1,104 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@description = description
|
|
7
|
-
end
|
|
8
|
-
def exist?(arg=nil)
|
|
9
|
-
@exists
|
|
10
|
-
end
|
|
11
|
-
def inspect
|
|
12
|
-
@description
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
class SubstanceTester
|
|
17
|
-
include RSpec::Matchers
|
|
18
|
-
def initialize substance
|
|
19
|
-
@substance = substance
|
|
20
|
-
end
|
|
21
|
-
def should_exist
|
|
22
|
-
@substance.should exist
|
|
23
|
-
end
|
|
24
|
-
end
|
|
3
|
+
describe "exist matcher" do
|
|
4
|
+
context "when the object does not respond to #exist? or #exists?" do
|
|
5
|
+
subject { mock }
|
|
25
6
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
7
|
+
[:should, :should_not].each do |should_method|
|
|
8
|
+
describe "#{should_method} exist" do
|
|
9
|
+
it "raises an error" do
|
|
10
|
+
expect {
|
|
11
|
+
subject.send(should_method, exist)
|
|
12
|
+
}.to raise_error(NoMethodError)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
31
16
|
end
|
|
32
17
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
18
|
+
[:exist?, :exists?].each do |predicate|
|
|
19
|
+
context "when the object responds to ##{predicate}" do
|
|
20
|
+
describe "should exist" do
|
|
21
|
+
it "passes if #{predicate}" do
|
|
22
|
+
mock(predicate => true).should exist
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "fails if not #{predicate}" do
|
|
26
|
+
expect {
|
|
27
|
+
mock(predicate => false).should exist
|
|
28
|
+
}.to fail_with(/expected .* to exist/)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "should not exist" do
|
|
33
|
+
it "passes if not #{predicate}" do
|
|
34
|
+
mock(predicate => false).should_not exist
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "fails if #{predicate}" do
|
|
38
|
+
expect {
|
|
39
|
+
mock(predicate => true).should_not exist
|
|
40
|
+
}.to fail_with(/expected .* not to exist/)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
53
43
|
end
|
|
54
44
|
end
|
|
55
45
|
|
|
56
|
-
|
|
46
|
+
context "when the object responds to #exist? and #exists?" do
|
|
47
|
+
context "when they both return falsey values" do
|
|
48
|
+
subject { mock(:exist? => false, :exists? => nil) }
|
|
49
|
+
|
|
50
|
+
describe "should_not exist" do
|
|
51
|
+
it "passes" do
|
|
52
|
+
subject.should_not exist
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "should exist" do
|
|
57
|
+
it "fails" do
|
|
58
|
+
expect {
|
|
59
|
+
subject.should exist
|
|
60
|
+
}.to fail_with(/expected .* to exist/)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context "when they both return truthy values" do
|
|
66
|
+
subject { mock(:exist? => true, :exists? => "something true") }
|
|
67
|
+
|
|
68
|
+
describe "should_not exist" do
|
|
69
|
+
it "fails" do
|
|
70
|
+
expect {
|
|
71
|
+
subject.should_not exist
|
|
72
|
+
}.to fail_with(/expected .* not to exist/)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
57
75
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
76
|
+
describe "should exist" do
|
|
77
|
+
it "passes" do
|
|
78
|
+
subject.should exist
|
|
79
|
+
end
|
|
80
|
+
end
|
|
61
81
|
end
|
|
62
82
|
|
|
83
|
+
context "when they return values with different truthiness" do
|
|
84
|
+
subject { mock(:exist? => true, :exists? => false) }
|
|
85
|
+
|
|
86
|
+
[:should, :should_not].each do |should_method|
|
|
87
|
+
describe "#{should_method} exist" do
|
|
88
|
+
it "raises an error" do
|
|
89
|
+
expect {
|
|
90
|
+
subject.send(should_method, exist)
|
|
91
|
+
}.to raise_error(/#exist\? and #exists\? returned different values/)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
63
96
|
end
|
|
64
97
|
|
|
98
|
+
it 'passes any provided arguments to the call to #exist?' do
|
|
99
|
+
object = mock
|
|
100
|
+
object.should_receive(:exist?).with(:foo, :bar) { true }
|
|
101
|
+
|
|
102
|
+
object.should exist(:foo, :bar)
|
|
103
|
+
end
|
|
65
104
|
end
|
|
@@ -26,7 +26,7 @@ describe "should have_sym(*args)" do
|
|
|
26
26
|
Object.new.should have_key(:a)
|
|
27
27
|
}.should raise_error(NoMethodError)
|
|
28
28
|
end
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
it "reraises an exception thrown in #has_sym?(*args)" do
|
|
31
31
|
o = Object.new
|
|
32
32
|
def o.has_sym?(*args)
|
|
@@ -60,7 +60,7 @@ describe "should_not have_sym(*args)" do
|
|
|
60
60
|
Object.new.should have_key(:a)
|
|
61
61
|
}.should raise_error(NoMethodError)
|
|
62
62
|
end
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
it "reraises an exception thrown in #has_sym?(*args)" do
|
|
65
65
|
o = Object.new
|
|
66
66
|
def o.has_sym?(*args)
|