rspec-expectations 2.11.3 → 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +1 -1
- data/Changelog.md +1026 -21
- data/{License.txt → LICENSE.md} +5 -3
- data/README.md +174 -78
- data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
- data/lib/rspec/expectations/configuration.rb +230 -0
- data/lib/rspec/expectations/expectation_target.rb +130 -55
- data/lib/rspec/expectations/fail_with.rb +17 -33
- data/lib/rspec/expectations/failure_aggregator.rb +212 -0
- data/lib/rspec/expectations/handler.rb +163 -29
- data/lib/rspec/expectations/minitest_integration.rb +58 -0
- data/lib/rspec/expectations/syntax.rb +68 -54
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +59 -24
- data/lib/rspec/matchers/aliased_matcher.rb +116 -0
- data/lib/rspec/matchers/built_in/all.rb +86 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +150 -20
- data/lib/rspec/matchers/built_in/be.rb +115 -109
- data/lib/rspec/matchers/built_in/be_between.rb +77 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +16 -1
- data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
- data/lib/rspec/matchers/built_in/be_within.rb +43 -17
- data/lib/rspec/matchers/built_in/change.rb +392 -75
- data/lib/rspec/matchers/built_in/compound.rb +290 -0
- data/lib/rspec/matchers/built_in/contain_exactly.rb +302 -0
- data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +26 -8
- data/lib/rspec/matchers/built_in/eql.rb +19 -8
- data/lib/rspec/matchers/built_in/equal.rb +56 -19
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +141 -22
- data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
- data/lib/rspec/matchers/built_in/include.rb +175 -20
- data/lib/rspec/matchers/built_in/match.rb +95 -1
- data/lib/rspec/matchers/built_in/operators.rb +128 -0
- data/lib/rspec/matchers/built_in/output.rb +207 -0
- data/lib/rspec/matchers/built_in/raise_error.rb +212 -38
- data/lib/rspec/matchers/built_in/respond_to.rb +155 -29
- data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
- data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
- data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
- data/lib/rspec/matchers/built_in/yield.rb +252 -98
- data/lib/rspec/matchers/built_in.rb +47 -33
- data/lib/rspec/matchers/composable.rb +171 -0
- data/lib/rspec/matchers/dsl.rb +530 -10
- data/lib/rspec/matchers/english_phrasing.rb +58 -0
- data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +82 -0
- data/lib/rspec/matchers/fail_matchers.rb +42 -0
- data/lib/rspec/matchers/generated_descriptions.rb +15 -10
- data/lib/rspec/matchers/matcher_delegator.rb +35 -0
- data/lib/rspec/matchers/matcher_protocol.rb +105 -0
- data/lib/rspec/matchers.rb +604 -252
- data.tar.gz.sig +0 -0
- metadata +178 -278
- metadata.gz.sig +0 -0
- data/features/README.md +0 -49
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -90
- data/features/built_in_matchers/be.feature +0 -173
- data/features/built_in_matchers/be_within.feature +0 -46
- data/features/built_in_matchers/cover.feature +0 -45
- data/features/built_in_matchers/end_with.feature +0 -46
- data/features/built_in_matchers/equality.feature +0 -145
- data/features/built_in_matchers/exist.feature +0 -43
- data/features/built_in_matchers/expect_change.feature +0 -59
- data/features/built_in_matchers/expect_error.feature +0 -138
- data/features/built_in_matchers/have.feature +0 -103
- data/features/built_in_matchers/include.feature +0 -121
- data/features/built_in_matchers/match.feature +0 -50
- data/features/built_in_matchers/operators.feature +0 -221
- data/features/built_in_matchers/predicates.feature +0 -128
- data/features/built_in_matchers/respond_to.feature +0 -78
- data/features/built_in_matchers/satisfy.feature +0 -31
- data/features/built_in_matchers/start_with.feature +0 -46
- data/features/built_in_matchers/throw_symbol.feature +0 -85
- data/features/built_in_matchers/types.feature +0 -114
- data/features/built_in_matchers/yield.feature +0 -146
- data/features/custom_matchers/access_running_example.feature +0 -53
- data/features/custom_matchers/define_diffable_matcher.feature +0 -27
- data/features/custom_matchers/define_matcher.feature +0 -340
- data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
- data/features/customized_message.feature +0 -22
- data/features/diffing.feature +0 -85
- data/features/implicit_docstrings.feature +0 -52
- data/features/step_definitions/additional_cli_steps.rb +0 -22
- data/features/support/env.rb +0 -5
- data/features/syntax_configuration.feature +0 -68
- data/features/test_frameworks/test_unit.feature +0 -46
- data/lib/rspec/expectations/deprecation.rb +0 -38
- data/lib/rspec/expectations/differ.rb +0 -81
- data/lib/rspec/expectations/errors.rb +0 -9
- data/lib/rspec/expectations/extensions/array.rb +0 -9
- data/lib/rspec/expectations/extensions/object.rb +0 -39
- data/lib/rspec/expectations/extensions.rb +0 -2
- data/lib/rspec/matchers/be_close.rb +0 -9
- data/lib/rspec/matchers/built_in/have.rb +0 -108
- data/lib/rspec/matchers/built_in/match_array.rb +0 -45
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
- data/lib/rspec/matchers/compatibility.rb +0 -14
- data/lib/rspec/matchers/configuration.rb +0 -66
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
- data/lib/rspec/matchers/matcher.rb +0 -299
- data/lib/rspec/matchers/method_missing.rb +0 -12
- data/lib/rspec/matchers/operator_matcher.rb +0 -84
- data/lib/rspec/matchers/pretty.rb +0 -60
- data/lib/rspec-expectations.rb +0 -1
- data/spec/rspec/expectations/differ_spec.rb +0 -153
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -65
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -70
- data/spec/rspec/expectations/handler_spec.rb +0 -206
- data/spec/rspec/matchers/base_matcher_spec.rb +0 -60
- data/spec/rspec/matchers/be_close_spec.rb +0 -22
- data/spec/rspec/matchers/be_instance_of_spec.rb +0 -40
- data/spec/rspec/matchers/be_kind_of_spec.rb +0 -37
- data/spec/rspec/matchers/be_spec.rb +0 -452
- data/spec/rspec/matchers/be_within_spec.rb +0 -80
- data/spec/rspec/matchers/change_spec.rb +0 -528
- data/spec/rspec/matchers/configuration_spec.rb +0 -202
- data/spec/rspec/matchers/cover_spec.rb +0 -69
- data/spec/rspec/matchers/description_generation_spec.rb +0 -176
- data/spec/rspec/matchers/dsl_spec.rb +0 -57
- data/spec/rspec/matchers/eq_spec.rb +0 -54
- data/spec/rspec/matchers/eql_spec.rb +0 -41
- data/spec/rspec/matchers/equal_spec.rb +0 -60
- data/spec/rspec/matchers/exist_spec.rb +0 -110
- data/spec/rspec/matchers/has_spec.rb +0 -118
- data/spec/rspec/matchers/have_spec.rb +0 -461
- data/spec/rspec/matchers/include_spec.rb +0 -367
- data/spec/rspec/matchers/match_array_spec.rb +0 -124
- data/spec/rspec/matchers/match_spec.rb +0 -61
- data/spec/rspec/matchers/matcher_spec.rb +0 -434
- data/spec/rspec/matchers/matchers_spec.rb +0 -31
- data/spec/rspec/matchers/method_missing_spec.rb +0 -24
- data/spec/rspec/matchers/operator_matcher_spec.rb +0 -221
- data/spec/rspec/matchers/raise_error_spec.rb +0 -344
- data/spec/rspec/matchers/respond_to_spec.rb +0 -295
- data/spec/rspec/matchers/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -182
- data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
- data/spec/rspec/matchers/yield_spec.rb +0 -402
- data/spec/spec_helper.rb +0 -27
- data/spec/support/classes.rb +0 -56
- data/spec/support/in_sub_process.rb +0 -31
- data/spec/support/matchers.rb +0 -22
- data/spec/support/ruby_version.rb +0 -10
- data/spec/support/shared_examples.rb +0 -13
@@ -1,202 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'delegate'
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
module Matchers
|
6
|
-
describe ".configuration" do
|
7
|
-
it 'returns a memoized configuration instance' do
|
8
|
-
RSpec::Matchers.configuration.should be_a(RSpec::Matchers::Configuration)
|
9
|
-
RSpec::Matchers.configuration.should be(RSpec::Matchers.configuration)
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'on an interpreter that does not provide BasicObject', :unless => defined?(::BasicObject) do
|
13
|
-
before { RSpec::Expectations::Syntax.disable_should(Delegator) }
|
14
|
-
|
15
|
-
let(:klass) do
|
16
|
-
Class.new(SimpleDelegator) do
|
17
|
-
def delegated?; true; end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:instance) { klass.new(Object.new) }
|
22
|
-
|
23
|
-
it 'provides a means to manually add it Delegator' do
|
24
|
-
instance.should_not respond_to(:delegated?) # because #should is being delegated...
|
25
|
-
RSpec::Matchers.configuration.add_should_and_should_not_to Delegator
|
26
|
-
instance.should respond_to(:delegated?) # now it should work!
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
shared_examples_for "configuring the expectation syntax" do
|
32
|
-
# We want a sandboxed method that ensures that we wind up with
|
33
|
-
# both syntaxes properly enabled when the example ends.
|
34
|
-
#
|
35
|
-
# On platforms that fork, using a sub process is the easiest,
|
36
|
-
# most robust way to achieve that.
|
37
|
-
#
|
38
|
-
# On jRuby we just re-enable both syntaxes at the end of the example;
|
39
|
-
# however, this is a generally inferior approach because it depends on
|
40
|
-
# the code-under-test working properly; if it doesn't work properly,
|
41
|
-
# it could leave things in a "broken" state where tons of other examples fail.
|
42
|
-
if RUBY_PLATFORM == "java"
|
43
|
-
def sandboxed
|
44
|
-
yield
|
45
|
-
ensure
|
46
|
-
configure_syntax([:should, :expect])
|
47
|
-
end
|
48
|
-
else
|
49
|
-
include InSubProcess
|
50
|
-
alias sandboxed in_sub_process
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'is configured to :should and :expect by default' do
|
54
|
-
configured_syntax.should eq([:should, :expect])
|
55
|
-
|
56
|
-
3.should eq(3)
|
57
|
-
3.should_not eq(4)
|
58
|
-
expect(3).to eq(3)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'can limit the syntax to :should' do
|
62
|
-
sandboxed do
|
63
|
-
configure_syntax :should
|
64
|
-
configured_syntax.should eq([:should])
|
65
|
-
|
66
|
-
3.should eq(3)
|
67
|
-
3.should_not eq(4)
|
68
|
-
lambda { expect(6).to eq(6) }.should raise_error(NameError)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'is a no-op when configured to :should twice' do
|
73
|
-
sandboxed do
|
74
|
-
::Kernel.stub(:method_added).and_raise("no methods should be added here")
|
75
|
-
|
76
|
-
configure_syntax :should
|
77
|
-
configure_syntax :should
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'can limit the syntax to :expect' do
|
82
|
-
sandboxed do
|
83
|
-
configure_syntax :expect
|
84
|
-
expect(configured_syntax).to eq([:expect])
|
85
|
-
|
86
|
-
expect(3).to eq(3)
|
87
|
-
expect { 3.should eq(3) }.to raise_error(NameError)
|
88
|
-
expect { 3.should_not eq(3) }.to raise_error(NameError)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'is a no-op when configured to :expect twice' do
|
93
|
-
sandboxed do
|
94
|
-
RSpec::Matchers.stub(:method_added).and_raise("no methods should be added here")
|
95
|
-
|
96
|
-
configure_syntax :expect
|
97
|
-
configure_syntax :expect
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'can re-enable the :should syntax' do
|
102
|
-
sandboxed do
|
103
|
-
configure_syntax :expect
|
104
|
-
configure_syntax [:should, :expect]
|
105
|
-
configured_syntax.should eq([:should, :expect])
|
106
|
-
|
107
|
-
3.should eq(3)
|
108
|
-
3.should_not eq(4)
|
109
|
-
expect(3).to eq(3)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'can re-enable the :expect syntax' do
|
114
|
-
sandboxed do
|
115
|
-
configure_syntax :should
|
116
|
-
configure_syntax [:should, :expect]
|
117
|
-
configured_syntax.should eq([:should, :expect])
|
118
|
-
|
119
|
-
3.should eq(3)
|
120
|
-
3.should_not eq(4)
|
121
|
-
expect(3).to eq(3)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'does not add the deprecated #should to ExpectationTarget when only :should is enabled' do
|
126
|
-
et = Expectations::ExpectationTarget
|
127
|
-
|
128
|
-
sandboxed do
|
129
|
-
configure_syntax :should
|
130
|
-
et.new(Proc.new {}).should be_an(et)
|
131
|
-
et.new(Proc.new {}).should_not be_a(Proc)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'does not add the deprecated #should to ExpectationTarget when only :expect is enabled' do
|
136
|
-
sandboxed do
|
137
|
-
configure_syntax :expect
|
138
|
-
expect(expect(3)).not_to respond_to(:should)
|
139
|
-
expect(expect(3)).not_to respond_to(:should_not)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
context 'when both :expect and :should are enabled' do
|
144
|
-
before { RSpec.stub(:warn) }
|
145
|
-
|
146
|
-
it 'allows `expect {}.should` to be used' do
|
147
|
-
sandboxed do
|
148
|
-
configure_syntax [:should, :expect]
|
149
|
-
expect { raise "boom" }.should raise_error("boom")
|
150
|
-
expect { }.should_not raise_error
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'prints a deprecation notice when `expect {}.should` is used' do
|
155
|
-
sandboxed do
|
156
|
-
configure_syntax [:should, :expect]
|
157
|
-
|
158
|
-
RSpec.should_receive(:warn).with(/please use `expect \{ \}.to.*instead/)
|
159
|
-
expect { raise "boom" }.should raise_error("boom")
|
160
|
-
|
161
|
-
RSpec.should_receive(:warn).with(/please use `expect \{ \}.to_not.*instead/)
|
162
|
-
expect { }.should_not raise_error
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
describe "configuring rspec-expectations directly" do
|
169
|
-
it_behaves_like "configuring the expectation syntax" do
|
170
|
-
def configure_syntax(syntax)
|
171
|
-
RSpec::Matchers.configuration.syntax = syntax
|
172
|
-
end
|
173
|
-
|
174
|
-
def configured_syntax
|
175
|
-
RSpec::Matchers.configuration.syntax
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
describe "configuring using the rspec-core config API" do
|
181
|
-
it_behaves_like "configuring the expectation syntax" do
|
182
|
-
def configure_syntax(syntax)
|
183
|
-
RSpec.configure do |rspec|
|
184
|
-
rspec.expect_with :rspec do |c|
|
185
|
-
c.syntax = syntax
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
def configured_syntax
|
191
|
-
RSpec.configure do |rspec|
|
192
|
-
rspec.expect_with :rspec do |c|
|
193
|
-
return c.syntax
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if (1..2).respond_to?(:cover?)
|
4
|
-
describe "should cover(expected)" do
|
5
|
-
it_behaves_like "an RSpec matcher", :valid_value => (1..10), :invalid_value => (20..30) do
|
6
|
-
let(:matcher) { cover(5) }
|
7
|
-
end
|
8
|
-
|
9
|
-
context "for a range target" do
|
10
|
-
it "passes if target covers expected" do
|
11
|
-
(1..10).should cover(5)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "fails if target does not cover expected" do
|
15
|
-
lambda {
|
16
|
-
(1..10).should cover(11)
|
17
|
-
}.should fail_with("expected 1..10 to cover 11")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "should cover(with, multiple, args)" do
|
23
|
-
context "for a range target" do
|
24
|
-
it "passes if target covers all items" do
|
25
|
-
(1..10).should cover(4, 6)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "fails if target does not cover any one of the items" do
|
29
|
-
lambda {
|
30
|
-
(1..10).should cover(4, 6, 11)
|
31
|
-
}.should fail_with("expected 1..10 to cover 4, 6, and 11")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "should_not cover(expected)" do
|
37
|
-
context "for a range target" do
|
38
|
-
it "passes if target does not cover expected" do
|
39
|
-
(1..10).should_not cover(11)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "fails if target covers expected" do
|
43
|
-
lambda {
|
44
|
-
(1..10).should_not cover(5)
|
45
|
-
}.should fail_with("expected 1..10 not to cover 5")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "should_not cover(with, multiple, args)" do
|
51
|
-
context "for a range target" do
|
52
|
-
it "passes if the target does not cover any of the expected" do
|
53
|
-
(1..10).should_not cover(11, 12, 13)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "fails if the target covers all of the expected" do
|
57
|
-
expect {
|
58
|
-
(1..10).should_not cover(4, 6)
|
59
|
-
}.to fail_with("expected 1..10 not to cover 4 and 6")
|
60
|
-
end
|
61
|
-
|
62
|
-
it "fails if the target covers some (but not all) of the expected" do
|
63
|
-
expect {
|
64
|
-
(1..10).should_not cover(5, 11)
|
65
|
-
}.to fail_with("expected 1..10 not to cover 5 and 11")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,176 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Matchers should be able to generate their own descriptions" do
|
4
|
-
after(:each) do
|
5
|
-
RSpec::Matchers.clear_generated_description
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should eq expected" do
|
9
|
-
"this".should eq "this"
|
10
|
-
RSpec::Matchers.generated_description.should eq "should eq \"this\""
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should not eq expected" do
|
14
|
-
"this".should_not eq "that"
|
15
|
-
RSpec::Matchers.generated_description.should eq "should not eq \"that\""
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should be empty (arbitrary predicate)" do
|
19
|
-
[].should be_empty
|
20
|
-
RSpec::Matchers.generated_description.should eq "should be empty"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should not be empty (arbitrary predicate)" do
|
24
|
-
[1].should_not be_empty
|
25
|
-
RSpec::Matchers.generated_description.should eq "should not be empty"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should be true" do
|
29
|
-
true.should be_true
|
30
|
-
RSpec::Matchers.generated_description.should eq "should be true"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should be false" do
|
34
|
-
false.should be_false
|
35
|
-
RSpec::Matchers.generated_description.should eq "should be false"
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should be nil" do
|
39
|
-
nil.should be_nil
|
40
|
-
RSpec::Matchers.generated_description.should eq "should be nil"
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should be > n" do
|
44
|
-
5.should be > 3
|
45
|
-
RSpec::Matchers.generated_description.should eq "should be > 3"
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should be predicate arg1, arg2 and arg3" do
|
49
|
-
5.0.should be_between(0,10)
|
50
|
-
RSpec::Matchers.generated_description.should eq "should be between 0 and 10"
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should equal" do
|
54
|
-
expected = "expected"
|
55
|
-
expected.should equal(expected)
|
56
|
-
RSpec::Matchers.generated_description.should eq "should equal \"expected\""
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should_not equal" do
|
60
|
-
5.should_not equal(37)
|
61
|
-
RSpec::Matchers.generated_description.should eq "should not equal 37"
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should eql" do
|
65
|
-
"string".should eql("string")
|
66
|
-
RSpec::Matchers.generated_description.should eq "should eql \"string\""
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should not eql" do
|
70
|
-
"a".should_not eql(:a)
|
71
|
-
RSpec::Matchers.generated_description.should eq "should not eql :a"
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should have_key" do
|
75
|
-
{:a => "a"}.should have_key(:a)
|
76
|
-
RSpec::Matchers.generated_description.should eq "should have key :a"
|
77
|
-
end
|
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 eq '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 eq 'should have taste for "wine", "cheese"'
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should have n items" do
|
96
|
-
team.should have(3).players
|
97
|
-
RSpec::Matchers.generated_description.should eq "should have 3 players"
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should have at least n items" do
|
101
|
-
team.should have_at_least(2).players
|
102
|
-
RSpec::Matchers.generated_description.should eq "should have at least 2 players"
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should have at most n items" do
|
106
|
-
team.should have_at_most(4).players
|
107
|
-
RSpec::Matchers.generated_description.should eq "should have at most 4 players"
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should include" do
|
111
|
-
[1,2,3].should include(3)
|
112
|
-
RSpec::Matchers.generated_description.should eq "should include 3"
|
113
|
-
end
|
114
|
-
|
115
|
-
it "array.should =~ [1,2,3]" do
|
116
|
-
[1,2,3].should =~ [1,2,3]
|
117
|
-
RSpec::Matchers.generated_description.should eq "should contain exactly 1, 2 and 3"
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should match" do
|
121
|
-
"this string".should match(/this string/)
|
122
|
-
RSpec::Matchers.generated_description.should eq "should match /this string/"
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should raise_error" do
|
126
|
-
lambda { raise }.should raise_error
|
127
|
-
RSpec::Matchers.generated_description.should eq "should raise Exception"
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should raise_error with type" do
|
131
|
-
lambda { raise }.should raise_error(RuntimeError)
|
132
|
-
RSpec::Matchers.generated_description.should eq "should raise RuntimeError"
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should raise_error with type and message" do
|
136
|
-
lambda { raise "there was an error" }.should raise_error(RuntimeError, "there was an error")
|
137
|
-
RSpec::Matchers.generated_description.should eq "should raise RuntimeError with \"there was an error\""
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should respond_to" do
|
141
|
-
[].should respond_to(:insert)
|
142
|
-
RSpec::Matchers.generated_description.should eq "should respond to #insert"
|
143
|
-
end
|
144
|
-
|
145
|
-
it "should throw symbol" do
|
146
|
-
lambda { throw :what_a_mess }.should throw_symbol
|
147
|
-
RSpec::Matchers.generated_description.should eq "should throw a Symbol"
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should throw symbol (with named symbol)" do
|
151
|
-
lambda { throw :what_a_mess }.should throw_symbol(:what_a_mess)
|
152
|
-
RSpec::Matchers.generated_description.should eq "should throw :what_a_mess"
|
153
|
-
end
|
154
|
-
|
155
|
-
def team
|
156
|
-
Class.new do
|
157
|
-
def players
|
158
|
-
[1,2,3]
|
159
|
-
end
|
160
|
-
end.new
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
describe "a Matcher with no description" do
|
165
|
-
def matcher
|
166
|
-
Class.new do
|
167
|
-
def matches?(ignore); true; end
|
168
|
-
def failure_message; ""; end
|
169
|
-
end.new
|
170
|
-
end
|
171
|
-
|
172
|
-
it "provides a helpful message when used in a string-less example block" do
|
173
|
-
5.should matcher
|
174
|
-
RSpec::Matchers.generated_description.should =~ /When you call.*description method/m
|
175
|
-
end
|
176
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "a matcher defined using the matcher DSL" do
|
4
|
-
def question?
|
5
|
-
:answer
|
6
|
-
end
|
7
|
-
|
8
|
-
def ok
|
9
|
-
"ok"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "supports calling custom matchers from within other custom matchers" do
|
13
|
-
RSpec::Matchers.define :be_ok do
|
14
|
-
match { |actual| actual == ok }
|
15
|
-
end
|
16
|
-
|
17
|
-
RSpec::Matchers.define :be_well do
|
18
|
-
match { |actual| actual.should be_ok }
|
19
|
-
end
|
20
|
-
|
21
|
-
ok.should be_well
|
22
|
-
end
|
23
|
-
|
24
|
-
it "has access to methods available in the scope of the example" do
|
25
|
-
RSpec::Matchers::define(:ignore) {}
|
26
|
-
ignore.question?.should eq(:answer)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "raises when method is missing from local scope as well as matcher" do
|
30
|
-
RSpec::Matchers::define(:ignore) {}
|
31
|
-
expect { ignore.i_dont_exist }.to raise_error(NameError)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "clears user instance variables between invocations" do
|
35
|
-
RSpec::Matchers::define(:be_just_like) do |expected|
|
36
|
-
match do |actual|
|
37
|
-
@foo ||= expected
|
38
|
-
@foo == actual
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
3.should be_just_like(3)
|
43
|
-
4.should be_just_like(4)
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#respond_to?" do
|
47
|
-
it "returns true for methods in example scope" do
|
48
|
-
RSpec::Matchers::define(:ignore) {}
|
49
|
-
ignore.should respond_to(:question?)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "returns false for methods not defined in matcher or example scope" do
|
53
|
-
RSpec::Matchers::define(:ignore) {}
|
54
|
-
ignore.should_not respond_to(:i_dont_exist)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Matchers
|
5
|
-
describe "eq" do
|
6
|
-
it_behaves_like "an RSpec matcher", :valid_value => 1, :invalid_value => 2 do
|
7
|
-
let(:matcher) { eq(1) }
|
8
|
-
end
|
9
|
-
|
10
|
-
it "is diffable" do
|
11
|
-
eq(1).should be_diffable
|
12
|
-
end
|
13
|
-
|
14
|
-
it "matches when actual == expected" do
|
15
|
-
1.should eq(1)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "does not match when actual != expected" do
|
19
|
-
1.should_not eq(2)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "compares by sending == to actual (not expected)" do
|
23
|
-
called = false
|
24
|
-
actual = Class.new do
|
25
|
-
define_method :== do |other|
|
26
|
-
called = true
|
27
|
-
end
|
28
|
-
end.new
|
29
|
-
|
30
|
-
actual.should eq :anything # to trigger the matches? method
|
31
|
-
called.should be_true
|
32
|
-
end
|
33
|
-
|
34
|
-
it "describes itself" do
|
35
|
-
matcher = eq(1)
|
36
|
-
matcher.matches?(1)
|
37
|
-
matcher.description.should eq "eq 1"
|
38
|
-
end
|
39
|
-
|
40
|
-
it "provides message, expected and actual on #failure_message" do
|
41
|
-
matcher = eq("1")
|
42
|
-
matcher.matches?(1)
|
43
|
-
matcher.failure_message_for_should.should eq "\nexpected: \"1\"\n got: 1\n\n(compared using ==)\n"
|
44
|
-
end
|
45
|
-
|
46
|
-
it "provides message, expected and actual on #negative_failure_message" do
|
47
|
-
matcher = eq(1)
|
48
|
-
matcher.matches?(1)
|
49
|
-
matcher.failure_message_for_should_not.should eq "\nexpected: value != 1\n got: 1\n\n(compared using ==)\n"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Matchers
|
5
|
-
describe "eql" do
|
6
|
-
it_behaves_like "an RSpec matcher", :valid_value => 1, :invalid_value => 2 do
|
7
|
-
let(:matcher) { eql(1) }
|
8
|
-
end
|
9
|
-
|
10
|
-
it "is diffable" do
|
11
|
-
eql(1).should be_diffable
|
12
|
-
end
|
13
|
-
|
14
|
-
it "matches when actual.eql?(expected)" do
|
15
|
-
1.should eql(1)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "does not match when !actual.eql?(expected)" do
|
19
|
-
1.should_not eql(2)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "describes itself" do
|
23
|
-
matcher = eql(1)
|
24
|
-
matcher.matches?(1)
|
25
|
-
matcher.description.should == "eql 1"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "provides message, expected and actual on #failure_message" do
|
29
|
-
matcher = eql("1")
|
30
|
-
matcher.matches?(1)
|
31
|
-
matcher.failure_message_for_should.should == "\nexpected: \"1\"\n got: 1\n\n(compared using eql?)\n"
|
32
|
-
end
|
33
|
-
|
34
|
-
it "provides message, expected and actual on #negative_failure_message" do
|
35
|
-
matcher = eql(1)
|
36
|
-
matcher.matches?(1)
|
37
|
-
matcher.failure_message_for_should_not.should == "\nexpected: value != 1\n got: 1\n\n(compared using eql?)\n"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
module RSpec
|
3
|
-
module Matchers
|
4
|
-
describe "equal" do
|
5
|
-
it_behaves_like "an RSpec matcher", :valid_value => :a, :invalid_value => :b do
|
6
|
-
let(:matcher) { equal(:a) }
|
7
|
-
end
|
8
|
-
|
9
|
-
def inspect_object(o)
|
10
|
-
"#<#{o.class}:#{o.object_id}> => #{o.inspect}"
|
11
|
-
end
|
12
|
-
|
13
|
-
it "matches when actual.equal?(expected)" do
|
14
|
-
1.should equal(1)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "does not match when !actual.equal?(expected)" do
|
18
|
-
"1".should_not equal("1")
|
19
|
-
end
|
20
|
-
|
21
|
-
it "describes itself" do
|
22
|
-
matcher = equal(1)
|
23
|
-
matcher.matches?(1)
|
24
|
-
matcher.description.should == "equal 1"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "provides message on #failure_message" do
|
28
|
-
expected, actual = "1", "1"
|
29
|
-
matcher = equal(expected)
|
30
|
-
matcher.matches?(actual)
|
31
|
-
|
32
|
-
matcher.failure_message_for_should.should == <<-MESSAGE
|
33
|
-
|
34
|
-
expected #{inspect_object(expected)}
|
35
|
-
got #{inspect_object(actual)}
|
36
|
-
|
37
|
-
Compared using equal?, which compares object identity,
|
38
|
-
but expected and actual are not the same object. Use
|
39
|
-
'actual.should eq(expected)' if you don't care about
|
40
|
-
object identity in this example.
|
41
|
-
|
42
|
-
MESSAGE
|
43
|
-
end
|
44
|
-
|
45
|
-
it "provides message on #negative_failure_message" do
|
46
|
-
expected = actual = "1"
|
47
|
-
matcher = equal(expected)
|
48
|
-
matcher.matches?(actual)
|
49
|
-
matcher.failure_message_for_should_not.should == <<-MESSAGE
|
50
|
-
|
51
|
-
expected not #{inspect_object(expected)}
|
52
|
-
got #{inspect_object(actual)}
|
53
|
-
|
54
|
-
Compared using equal?, which compares object identity.
|
55
|
-
|
56
|
-
MESSAGE
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|