rspec-expectations 2.13.0 → 2.99.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.
- checksums.yaml +15 -0
- data/Changelog.md +204 -23
- data/README.md +43 -87
- data/features/README.md +10 -10
- data/features/built_in_matchers/README.md +41 -41
- data/features/built_in_matchers/be.feature +40 -40
- data/features/built_in_matchers/be_within.feature +3 -3
- data/features/built_in_matchers/expect_change.feature +6 -6
- data/features/built_in_matchers/expect_error.feature +2 -2
- data/features/built_in_matchers/start_with.feature +1 -1
- data/features/built_in_matchers/throw_symbol.feature +11 -11
- data/features/built_in_matchers/yield.feature +18 -3
- data/features/custom_matchers/define_diffable_matcher.feature +1 -1
- data/features/custom_matchers/define_matcher_outside_rspec.feature +6 -6
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
- data/features/customized_message.feature +1 -1
- data/features/diffing.feature +1 -1
- data/features/step_definitions/additional_cli_steps.rb +10 -0
- data/features/support/env.rb +10 -1
- data/features/support/rubinius.rb +6 -0
- data/features/syntax_configuration.feature +3 -0
- data/features/test_frameworks/test_unit.feature +55 -17
- data/lib/rspec/expectations/caller_filter.rb +60 -0
- data/lib/rspec/{matchers → expectations}/configuration.rb +5 -3
- data/lib/rspec/expectations/deprecation.rb +20 -31
- data/lib/rspec/expectations/differ.rb +48 -9
- data/lib/rspec/expectations/expectation_target.rb +81 -15
- data/lib/rspec/expectations/extensions/object.rb +2 -12
- data/lib/rspec/expectations/fail_with.rb +11 -1
- data/lib/rspec/expectations/handler.rb +16 -7
- data/lib/rspec/expectations/syntax.rb +5 -7
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +28 -2
- data/lib/rspec/matchers/be_close.rb +4 -1
- data/lib/rspec/matchers/built_in/base_matcher.rb +17 -10
- data/lib/rspec/matchers/built_in/be.rb +69 -32
- data/lib/rspec/matchers/built_in/be_within.rb +9 -3
- data/lib/rspec/matchers/built_in/change.rb +49 -3
- data/lib/rspec/matchers/built_in/has.rb +40 -7
- data/lib/rspec/matchers/built_in/have.rb +170 -5
- data/lib/rspec/matchers/built_in/include.rb +3 -11
- data/lib/rspec/matchers/built_in/match.rb +5 -0
- data/lib/rspec/matchers/built_in/match_array.rb +1 -1
- data/lib/rspec/matchers/built_in/raise_error.rb +34 -8
- data/lib/rspec/matchers/built_in/respond_to.rb +7 -1
- data/lib/rspec/matchers/built_in/satisfy.rb +7 -1
- data/lib/rspec/matchers/built_in/throw_symbol.rb +10 -2
- data/lib/rspec/matchers/built_in/yield.rb +102 -5
- data/lib/rspec/matchers/built_in.rb +2 -2
- data/lib/rspec/matchers/differentiate_block_method_types.rb +55 -0
- data/lib/rspec/matchers/dsl.rb +2 -1
- data/lib/rspec/matchers/match_aliases.rb +22 -0
- data/lib/rspec/matchers/matcher.rb +131 -10
- data/lib/rspec/matchers/operator_matcher.rb +70 -66
- data/lib/rspec/matchers/pretty.rb +11 -1
- data/lib/rspec/matchers/test_unit_integration.rb +28 -0
- data/lib/rspec/matchers.rb +175 -146
- data/lib/rspec-expectations.rb +5 -0
- data/spec/rspec/{matchers → expectations}/configuration_spec.rb +78 -91
- data/spec/rspec/expectations/differ_spec.rb +65 -6
- data/spec/rspec/expectations/expectation_target_spec.rb +72 -3
- data/spec/rspec/expectations/extensions/kernel_spec.rb +9 -5
- data/spec/rspec/expectations/fail_with_spec.rb +19 -0
- data/spec/rspec/expectations/handler_spec.rb +43 -22
- data/spec/rspec/expectations/syntax_spec.rb +51 -9
- data/spec/rspec/expectations_spec.rb +71 -0
- data/spec/rspec/matchers/base_matcher_spec.rb +33 -18
- data/spec/rspec/matchers/be_close_spec.rb +9 -6
- data/spec/rspec/matchers/be_spec.rb +146 -45
- data/spec/rspec/matchers/be_within_spec.rb +8 -0
- data/spec/rspec/matchers/change_spec.rb +107 -7
- data/spec/rspec/matchers/description_generation_spec.rb +38 -20
- data/spec/rspec/matchers/differentiate_block_method_types_spec.rb +39 -0
- data/spec/rspec/matchers/eq_spec.rb +1 -1
- data/spec/rspec/matchers/equal_spec.rb +26 -0
- data/spec/rspec/matchers/exist_spec.rb +9 -9
- data/spec/rspec/matchers/has_spec.rb +25 -1
- data/spec/rspec/matchers/have_spec.rb +411 -3
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +2 -2
- data/spec/rspec/matchers/include_spec.rb +4 -4
- data/spec/rspec/matchers/match_array_spec.rb +1 -1
- data/spec/rspec/matchers/match_spec.rb +14 -1
- data/spec/rspec/matchers/matcher_spec.rb +213 -24
- data/spec/rspec/matchers/operator_matcher_spec.rb +56 -8
- data/spec/rspec/matchers/pretty_spec.rb +23 -0
- data/spec/rspec/matchers/raise_error_spec.rb +242 -102
- data/spec/rspec/matchers/respond_to_spec.rb +4 -4
- data/spec/rspec/matchers/satisfy_spec.rb +1 -1
- data/spec/rspec/matchers/start_with_end_with_spec.rb +2 -2
- data/spec/rspec/matchers/throw_symbol_spec.rb +14 -14
- data/spec/rspec/matchers/yield_spec.rb +81 -4
- data/spec/spec_helper.rb +5 -3
- data/spec/support/helper_methods.rb +42 -0
- data/spec/support/shared_examples.rb +42 -0
- metadata +40 -44
- data/spec/rspec/matchers/matchers_spec.rb +0 -37
|
@@ -2,10 +2,10 @@ require 'spec_helper'
|
|
|
2
2
|
require 'delegate'
|
|
3
3
|
|
|
4
4
|
module RSpec
|
|
5
|
-
module
|
|
5
|
+
module Expectations
|
|
6
6
|
describe "RSpec::Matchers.configuration" do
|
|
7
7
|
it 'returns a memoized configuration instance' do
|
|
8
|
-
expect(RSpec::Matchers.configuration).to be_a(RSpec::
|
|
8
|
+
expect(RSpec::Matchers.configuration).to be_a(RSpec::Expectations::Configuration)
|
|
9
9
|
expect(RSpec::Matchers.configuration).to be(RSpec::Matchers.configuration)
|
|
10
10
|
end
|
|
11
11
|
end
|
|
@@ -13,6 +13,25 @@ module RSpec
|
|
|
13
13
|
describe Configuration do
|
|
14
14
|
let(:config) { Configuration.new }
|
|
15
15
|
|
|
16
|
+
context "when accessing it using the old 2.x const name" do
|
|
17
|
+
it 'returns the new constant' do
|
|
18
|
+
allow_deprecation
|
|
19
|
+
expect(RSpec::Matchers::Configuration).to be(RSpec::Expectations::Configuration)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'issues a deprecation warning' do
|
|
23
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /RSpec::Matchers::Configuration/)
|
|
24
|
+
RSpec::Matchers::Configuration
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'allows other undefined constant to raise errors like normal' do
|
|
28
|
+
expect_no_deprecation
|
|
29
|
+
expect {
|
|
30
|
+
RSpec::Matchers::FooBarBazz
|
|
31
|
+
}.to raise_error(NameError, /RSpec::Matchers::FooBarBazz/)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
16
35
|
describe "#backtrace_formatter" do
|
|
17
36
|
let(:original_backtrace) { %w[ clean-me/a.rb other/file.rb clean-me/b.rb ] }
|
|
18
37
|
let(:cleaned_backtrace) { %w[ other/file.rb ] }
|
|
@@ -22,7 +41,12 @@ module RSpec
|
|
|
22
41
|
end
|
|
23
42
|
|
|
24
43
|
before do
|
|
25
|
-
RSpec.configuration.
|
|
44
|
+
@old_patterns = RSpec.configuration.backtrace_exclusion_patterns
|
|
45
|
+
RSpec.configuration.backtrace_exclusion_patterns = [/clean-me/]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
after do
|
|
49
|
+
RSpec.configuration.backtrace_exclusion_patterns = @old_patterns
|
|
26
50
|
end
|
|
27
51
|
|
|
28
52
|
it "defaults to rspec-core's backtrace formatter when rspec-core is loaded" do
|
|
@@ -36,7 +60,7 @@ module RSpec
|
|
|
36
60
|
end
|
|
37
61
|
|
|
38
62
|
it "can be set to another backtrace formatter" do
|
|
39
|
-
config.backtrace_formatter =
|
|
63
|
+
config.backtrace_formatter = double(:format_backtrace => ['a'])
|
|
40
64
|
expect(formatted_backtrace).to eq(['a'])
|
|
41
65
|
end
|
|
42
66
|
end
|
|
@@ -60,134 +84,97 @@ module RSpec
|
|
|
60
84
|
end
|
|
61
85
|
|
|
62
86
|
shared_examples_for "configuring the expectation syntax" do
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
# On jRuby we just re-enable both syntaxes at the end of the example;
|
|
70
|
-
# however, this is a generally inferior approach because it depends on
|
|
71
|
-
# the code-under-test working properly; if it doesn't work properly,
|
|
72
|
-
# it could leave things in a "broken" state where tons of other examples fail.
|
|
73
|
-
if RUBY_PLATFORM == "java"
|
|
74
|
-
def sandboxed
|
|
75
|
-
orig_syntax = RSpec::Matchers.configuration.syntax
|
|
76
|
-
yield
|
|
77
|
-
ensure
|
|
78
|
-
configure_syntax(orig_syntax)
|
|
79
|
-
end
|
|
80
|
-
else
|
|
81
|
-
include InSubProcess
|
|
82
|
-
alias sandboxed in_sub_process
|
|
87
|
+
before do
|
|
88
|
+
@orig_syntax = RSpec::Matchers.configuration.syntax
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
after do
|
|
92
|
+
configure_syntax(@orig_syntax)
|
|
83
93
|
end
|
|
84
94
|
|
|
85
95
|
it 'can limit the syntax to :should' do
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
configured_syntax.should eq([:should])
|
|
96
|
+
configure_syntax :should
|
|
97
|
+
configured_syntax.should eq([:should])
|
|
89
98
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
end
|
|
99
|
+
3.should eq(3)
|
|
100
|
+
3.should_not eq(4)
|
|
101
|
+
lambda { expect(6).to eq(6) }.should raise_error(NameError)
|
|
94
102
|
end
|
|
95
103
|
|
|
96
104
|
it 'is a no-op when configured to :should twice' do
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
stub(:method_added).
|
|
102
|
-
and_raise("no methods should be added here")
|
|
103
|
-
|
|
104
|
-
configure_syntax :should
|
|
105
|
-
end
|
|
105
|
+
configure_syntax :should
|
|
106
|
+
Expectations::Syntax.default_should_host.should_not_receive(:method_added)
|
|
107
|
+
configure_syntax :should
|
|
108
|
+
RSpec::Mocks.verify # because configure_syntax is called again in an after hook
|
|
106
109
|
end
|
|
107
110
|
|
|
108
111
|
it 'can limit the syntax to :expect' do
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
expect(configured_syntax).to eq([:expect])
|
|
112
|
+
configure_syntax :expect
|
|
113
|
+
expect(configured_syntax).to eq([:expect])
|
|
112
114
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
end
|
|
115
|
+
expect(3).to eq(3)
|
|
116
|
+
expect { 3.should eq(3) }.to raise_error(NameError)
|
|
117
|
+
expect { 3.should_not eq(3) }.to raise_error(NameError)
|
|
117
118
|
end
|
|
118
119
|
|
|
119
120
|
it 'is a no-op when configured to :expect twice' do
|
|
120
|
-
|
|
121
|
-
RSpec::Matchers.stub(:method_added).and_raise("no methods should be added here")
|
|
121
|
+
RSpec::Matchers.stub(:method_added).and_raise("no methods should be added here")
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
end
|
|
123
|
+
configure_syntax :expect
|
|
124
|
+
configure_syntax :expect
|
|
126
125
|
end
|
|
127
126
|
|
|
128
127
|
it 'can re-enable the :should syntax' do
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
configured_syntax.should eq([:should, :expect])
|
|
128
|
+
configure_syntax :expect
|
|
129
|
+
configure_syntax [:should, :expect]
|
|
130
|
+
configured_syntax.should eq([:should, :expect])
|
|
133
131
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
end
|
|
132
|
+
3.should eq(3)
|
|
133
|
+
3.should_not eq(4)
|
|
134
|
+
expect(3).to eq(3)
|
|
138
135
|
end
|
|
139
136
|
|
|
140
137
|
it 'can re-enable the :expect syntax' do
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
configured_syntax.should eq([:should, :expect])
|
|
138
|
+
configure_syntax :should
|
|
139
|
+
configure_syntax [:should, :expect]
|
|
140
|
+
configured_syntax.should eq([:should, :expect])
|
|
145
141
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
end
|
|
142
|
+
3.should eq(3)
|
|
143
|
+
3.should_not eq(4)
|
|
144
|
+
expect(3).to eq(3)
|
|
150
145
|
end
|
|
151
146
|
|
|
152
147
|
it 'does not add the deprecated #should to ExpectationTarget when only :should is enabled' do
|
|
153
148
|
et = Expectations::ExpectationTarget
|
|
154
149
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
et.new(Proc.new {}).should_not be_a(Proc)
|
|
159
|
-
end
|
|
150
|
+
configure_syntax :should
|
|
151
|
+
et.new(Proc.new {}).should be_an(et)
|
|
152
|
+
et.new(Proc.new {}).should_not be_a(Proc)
|
|
160
153
|
end
|
|
161
154
|
|
|
162
155
|
it 'does not add the deprecated #should to ExpectationTarget when only :expect is enabled' do
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
expect(expect(3)).not_to respond_to(:should_not)
|
|
167
|
-
end
|
|
156
|
+
configure_syntax :expect
|
|
157
|
+
expect(expect(3)).not_to respond_to(:should)
|
|
158
|
+
expect(expect(3)).not_to respond_to(:should_not)
|
|
168
159
|
end
|
|
169
160
|
|
|
170
161
|
context 'when both :expect and :should are enabled' do
|
|
171
|
-
before { RSpec.
|
|
162
|
+
before { allow(RSpec).to receive(:deprecate) }
|
|
172
163
|
|
|
173
164
|
it 'allows `expect {}.should` to be used' do
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
expect { }.should_not raise_error
|
|
178
|
-
end
|
|
165
|
+
configure_syntax [:should, :expect]
|
|
166
|
+
expect { raise "boom" }.should raise_error("boom")
|
|
167
|
+
expect { }.should_not raise_error
|
|
179
168
|
end
|
|
180
169
|
|
|
181
170
|
it 'prints a deprecation notice when `expect {}.should` is used' do
|
|
182
|
-
|
|
183
|
-
configure_syntax [:should, :expect]
|
|
171
|
+
configure_syntax [:should, :expect]
|
|
184
172
|
|
|
185
|
-
|
|
186
|
-
|
|
173
|
+
expect(RSpec).to receive(:deprecate)
|
|
174
|
+
expect { raise "boom" }.should raise_error("boom")
|
|
187
175
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
end
|
|
176
|
+
expect(RSpec).to receive(:deprecate)
|
|
177
|
+
expect { }.should_not raise_error
|
|
191
178
|
end
|
|
192
179
|
end
|
|
193
180
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
require 'ostruct'
|
|
3
4
|
|
|
@@ -13,10 +14,11 @@ module RSpec
|
|
|
13
14
|
# color disabled context
|
|
14
15
|
|
|
15
16
|
describe '#diff_as_string' do
|
|
17
|
+
subject { differ.diff_as_string(@expected, @actual) }
|
|
16
18
|
it "outputs unified diff of two strings" do
|
|
17
|
-
expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
|
|
18
|
-
actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
|
|
19
|
-
|
|
19
|
+
@expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
|
|
20
|
+
@actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
|
|
21
|
+
expect(subject).to eql(<<-'EOD')
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
@@ -1,6 +1,6 @@
|
|
@@ -35,8 +37,33 @@ module RSpec
|
|
|
35
37
|
line
|
|
36
38
|
EOD
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
end
|
|
41
|
+
if RUBY_VERSION.to_f > 1.9
|
|
42
|
+
it 'copes with encoded strings', :pending => (Diff::LCS::VERSION < '1.2.2') do
|
|
43
|
+
@expected="Tu avec carté {count} itém has".encode('UTF-16LE')
|
|
44
|
+
@actual="Tu avec carte {count} item has".encode('UTF-16LE')
|
|
45
|
+
expect(subject).to eql(<<-EOD.encode('UTF-16LE'))
|
|
46
|
+
|
|
47
|
+
@@ -1,2 +1,2 @@
|
|
48
|
+
-Tu avec carte {count} item has
|
|
49
|
+
+Tu avec carté {count} itém has
|
|
50
|
+
EOD
|
|
51
|
+
end
|
|
52
|
+
it 'copes with encoded strings', :pending => (Diff::LCS::VERSION >= '1.2.2') do
|
|
53
|
+
@expected="Tu avec carté {count} itém has".encode('UTF-16LE')
|
|
54
|
+
@actual="Tu avec carte {count} item has".encode('UTF-16LE')
|
|
55
|
+
expect(subject).to eql 'Could not produce a diff because of the encoding of the string (UTF-16LE)'
|
|
56
|
+
end
|
|
57
|
+
it 'handles differently encoded strings that are compatible' do
|
|
58
|
+
@expected = "강인철".encode('UTF-8')
|
|
59
|
+
@actual = "abc".encode('us-ascii')
|
|
60
|
+
expect(subject).to eql "\n@@ -1,2 +1,2 @@\n-abc\n+강인철\n"
|
|
61
|
+
end
|
|
62
|
+
it 'outputs a message when encountering differently encoded strings' do
|
|
63
|
+
@expected="Tu avec carté {count} itém has".encode('UTF-16LE')
|
|
64
|
+
@actual="Tu avec carte {count} item has"
|
|
65
|
+
expect(subject).to eql 'Could not produce a diff because the encoding of the actual string (UTF-8) differs from the encoding of the expected string (UTF-16LE)'
|
|
66
|
+
end
|
|
40
67
|
end
|
|
41
68
|
end
|
|
42
69
|
|
|
@@ -115,6 +142,39 @@ EOD
|
|
|
115
142
|
expect(diff).to eq expected_diff
|
|
116
143
|
end
|
|
117
144
|
|
|
145
|
+
it 'outputs unified diff message of two hashes with differing encoding' do
|
|
146
|
+
expected_diff = %Q{
|
|
147
|
+
@@ -1,2 +1,2 @@
|
|
148
|
+
-"a" => "a"
|
|
149
|
+
#{ (RUBY_VERSION.to_f > 1.8) ? %Q{+"ö" => "ö"} : '+"\303\266" => "\303\266"' }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
diff = differ.diff_as_object({'ö' => 'ö'}, {'a' => 'a'})
|
|
153
|
+
expect(diff).to eq expected_diff
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'outputs unified diff message of two hashes with encoding different to key encoding' do
|
|
157
|
+
expected_diff = %Q{
|
|
158
|
+
@@ -1,2 +1,2 @@
|
|
159
|
+
-:a => "a"
|
|
160
|
+
#{ (RUBY_VERSION.to_f > 1.8) ? %Q{+\"한글\" => \"한글2\"} : '+"\355\225\234\352\270\200" => "\355\225\234\352\270\2002"' }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
diff = differ.diff_as_object({ "한글" => "한글2"}, { :a => "a"})
|
|
164
|
+
expect(diff).to eq expected_diff
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it "outputs unified diff message of two hashes with object keys" do
|
|
168
|
+
expected_diff = %Q{
|
|
169
|
+
@@ -1,2 +1,2 @@
|
|
170
|
+
-["a", "c"] => "b"
|
|
171
|
+
+["d", "c"] => "b"
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
diff = differ.diff_as_object({ ['d','c'] => 'b'}, { ['a','c'] => 'b' })
|
|
175
|
+
expect(diff).to eq expected_diff
|
|
176
|
+
end
|
|
177
|
+
|
|
118
178
|
it "outputs unified diff of single line strings" do
|
|
119
179
|
expected = "this is one string"
|
|
120
180
|
actual = "this is another string"
|
|
@@ -167,4 +227,3 @@ EOD
|
|
|
167
227
|
end
|
|
168
228
|
end
|
|
169
229
|
end
|
|
170
|
-
|
|
@@ -22,6 +22,12 @@ module RSpec
|
|
|
22
22
|
}.to raise_error(ArgumentError)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
it 'raises a wrong number of args ArgumentError when given two args' do
|
|
26
|
+
expect {
|
|
27
|
+
expect(1, 2)
|
|
28
|
+
}.to raise_error(ArgumentError, /wrong number of arg/)
|
|
29
|
+
end
|
|
30
|
+
|
|
25
31
|
it 'raises an ArgumentError when given neither an argument nor a block' do
|
|
26
32
|
expect {
|
|
27
33
|
expect
|
|
@@ -37,10 +43,13 @@ module RSpec
|
|
|
37
43
|
end
|
|
38
44
|
|
|
39
45
|
it 'passes a valid negative expectation' do
|
|
40
|
-
expect(5).to_not eq(4)
|
|
41
46
|
expect(5).not_to eq(4)
|
|
42
47
|
end
|
|
43
48
|
|
|
49
|
+
it 'passes a valid negative expectation with a split infinitive' do
|
|
50
|
+
expect(5).to_not eq(4)
|
|
51
|
+
end
|
|
52
|
+
|
|
44
53
|
it 'fails an invalid positive expectation' do
|
|
45
54
|
expect {
|
|
46
55
|
expect(5).to eq(4)
|
|
@@ -50,10 +59,14 @@ module RSpec
|
|
|
50
59
|
it 'fails an invalid negative expectation' do
|
|
51
60
|
message = /expected 5 not to be a kind of Fixnum/
|
|
52
61
|
expect {
|
|
53
|
-
expect(5).
|
|
62
|
+
expect(5).not_to be_a(Fixnum)
|
|
54
63
|
}.to fail_with(message)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'fails an invalid negative expectation with a split infinitive' do
|
|
67
|
+
message = /expected 5 not to be a kind of Fixnum/
|
|
55
68
|
expect {
|
|
56
|
-
expect(5).
|
|
69
|
+
expect(5).to_not be_a(Fixnum)
|
|
57
70
|
}.to fail_with(message)
|
|
58
71
|
end
|
|
59
72
|
|
|
@@ -69,6 +82,62 @@ module RSpec
|
|
|
69
82
|
}.to raise_error(ArgumentError)
|
|
70
83
|
end
|
|
71
84
|
end
|
|
85
|
+
|
|
86
|
+
context "when passed a block" do
|
|
87
|
+
it 'can be used with a block matcher' do
|
|
88
|
+
expect { }.not_to raise_error
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
context 'when passed a value matcher' do
|
|
92
|
+
it 'issues a warning to instruct the user to use a value expression or fix the matcher (for `to`)' do
|
|
93
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /block expectation/)
|
|
94
|
+
expect { }.to be_an(Object)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'issues a warning to instruct the user to use a value expression or fix the matcher (for `not_to`)' do
|
|
98
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /block expectation/)
|
|
99
|
+
expect { }.not_to be_an(String)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'issues a warning to instruct the user to use a value expression or fix the matcher (for `to_not`)' do
|
|
103
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /block expectation/)
|
|
104
|
+
expect { }.to_not be_an(String)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'assumes a custom matcher that does not define `supports_block_expectations?` is not a block matcher (since it is relatively rare)' do
|
|
108
|
+
custom_matcher = Module.new do
|
|
109
|
+
def self.matches?(value); true; end
|
|
110
|
+
def self.description; "foo"; end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 2, /block expectation/)
|
|
114
|
+
expect(3).to custom_matcher # to show the custom matcher can be used as a matcher
|
|
115
|
+
expect { 3 }.to custom_matcher
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "uses the matcher's `description` in the warning" do
|
|
119
|
+
custom_matcher = Module.new do
|
|
120
|
+
def self.matches?(value); true; end
|
|
121
|
+
def self.description; "matcher-description"; end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
expect_deprecation_with_replacement(/\(matcher-description\)/)
|
|
125
|
+
expect { }.to custom_matcher
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
context 'when the matcher does not define `description` (since it is an optional part of the protocol)' do
|
|
129
|
+
it 'uses `inspect` in the warning instead' do
|
|
130
|
+
custom_matcher = Module.new do
|
|
131
|
+
def self.matches?(value); true; end
|
|
132
|
+
def self.inspect; "matcher-inspect"; end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
expect_deprecation_with_replacement(/\(matcher-inspect\)/)
|
|
136
|
+
expect { }.to custom_matcher
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
72
141
|
end
|
|
73
142
|
end
|
|
74
143
|
end
|
|
@@ -3,9 +3,9 @@ require 'spec_helper'
|
|
|
3
3
|
describe Object, "#should" do
|
|
4
4
|
before(:each) do
|
|
5
5
|
@target = "target"
|
|
6
|
-
@matcher =
|
|
7
|
-
@matcher.stub
|
|
8
|
-
@matcher.stub
|
|
6
|
+
@matcher = double("matcher")
|
|
7
|
+
@matcher.stub(:matches?).and_return(true)
|
|
8
|
+
@matcher.stub(:failure_message_for_should)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
it "accepts and interacts with a matcher" do
|
|
@@ -32,6 +32,10 @@ describe Object, "#should" do
|
|
|
32
32
|
true
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
def respond_to?(name, include_all=false)
|
|
36
|
+
super || name == :proxied? || @target.respond_to?(name, include_all)
|
|
37
|
+
end
|
|
38
|
+
|
|
35
39
|
def method_missing(name, *args)
|
|
36
40
|
@target.send(name, *args)
|
|
37
41
|
end
|
|
@@ -47,12 +51,12 @@ end
|
|
|
47
51
|
describe Object, "#should_not" do
|
|
48
52
|
before(:each) do
|
|
49
53
|
@target = "target"
|
|
50
|
-
@matcher =
|
|
54
|
+
@matcher = double("matcher")
|
|
51
55
|
end
|
|
52
56
|
|
|
53
57
|
it "accepts and interacts with a matcher" do
|
|
54
58
|
@matcher.should_receive(:matches?).with(@target).and_return(false)
|
|
55
|
-
@matcher.stub
|
|
59
|
+
@matcher.stub(:failure_message_for_should_not)
|
|
56
60
|
|
|
57
61
|
expect(@target).not_to @matcher
|
|
58
62
|
end
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
|
+
|
|
5
|
+
describe RSpec::Expectations, "#fail_with with diff of arrays" do
|
|
6
|
+
before { RSpec::Matchers.configuration.stub(:color? => false) }
|
|
7
|
+
|
|
8
|
+
it "splits items with newlines" do
|
|
9
|
+
expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+c\\nd\n"
|
|
10
|
+
expect {
|
|
11
|
+
RSpec::Expectations.fail_with("", [], ["a\nb", "c\nd"])
|
|
12
|
+
}.to fail_with(expected_diff)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "shows inner arrays on a single line" do
|
|
16
|
+
expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+[\"c\\nd\"]\n"
|
|
17
|
+
expect {
|
|
18
|
+
RSpec::Expectations.fail_with("", [], ["a\nb", ["c\nd"]])
|
|
19
|
+
}.to fail_with(expected_diff)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
4
23
|
describe RSpec::Expectations, "#fail_with with diff" do
|
|
5
24
|
let(:differ) { double("differ") }
|
|
6
25
|
|