rspec-expectations 3.0.0.beta1 → 3.0.0.beta2
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.tar.gz.sig +2 -2
- data/.yardopts +1 -0
- data/Changelog.md +138 -0
- data/README.md +75 -8
- data/features/README.md +2 -2
- data/features/built_in_matchers/README.md +12 -9
- data/features/built_in_matchers/comparisons.feature +2 -2
- data/features/built_in_matchers/contain_exactly.feature +46 -0
- data/features/built_in_matchers/expect_change.feature +2 -2
- data/features/built_in_matchers/include.feature +0 -48
- data/features/built_in_matchers/output.feature +70 -0
- data/features/composing_matchers.feature +250 -0
- data/features/compound_expectations.feature +45 -0
- data/features/custom_matchers/access_running_example.feature +1 -1
- data/features/custom_matchers/define_matcher.feature +6 -6
- data/features/custom_matchers/define_matcher_outside_rspec.feature +4 -8
- data/features/test_frameworks/{test_unit.feature → minitest.feature} +11 -11
- data/lib/rspec/expectations.rb +31 -42
- data/lib/rspec/expectations/diff_presenter.rb +141 -0
- data/lib/rspec/expectations/differ.rb +22 -132
- data/lib/rspec/expectations/encoded_string.rb +56 -0
- data/lib/rspec/expectations/expectation_target.rb +0 -30
- data/lib/rspec/expectations/fail_with.rb +2 -2
- data/lib/rspec/expectations/handler.rb +128 -31
- data/lib/rspec/expectations/minitest_integration.rb +16 -0
- data/lib/rspec/expectations/syntax.rb +4 -58
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +298 -60
- data/lib/rspec/matchers/aliased_matcher.rb +35 -0
- data/lib/rspec/matchers/built_in.rb +37 -33
- data/lib/rspec/matchers/built_in/base_matcher.rb +25 -15
- data/lib/rspec/matchers/built_in/be.rb +23 -31
- data/lib/rspec/matchers/built_in/be_between.rb +55 -0
- data/lib/rspec/matchers/built_in/be_within.rb +15 -11
- data/lib/rspec/matchers/built_in/change.rb +198 -81
- data/lib/rspec/matchers/built_in/compound.rb +106 -0
- data/lib/rspec/matchers/built_in/contain_exactly.rb +245 -0
- data/lib/rspec/matchers/built_in/eq.rb +43 -4
- data/lib/rspec/matchers/built_in/eql.rb +2 -2
- data/lib/rspec/matchers/built_in/equal.rb +35 -18
- data/lib/rspec/matchers/built_in/has.rb +16 -15
- data/lib/rspec/matchers/built_in/include.rb +45 -23
- data/lib/rspec/matchers/built_in/match.rb +6 -3
- data/lib/rspec/matchers/built_in/operators.rb +103 -0
- data/lib/rspec/matchers/built_in/output.rb +108 -0
- data/lib/rspec/matchers/built_in/raise_error.rb +9 -15
- data/lib/rspec/matchers/built_in/respond_to.rb +5 -4
- data/lib/rspec/matchers/built_in/satisfy.rb +4 -3
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +37 -16
- data/lib/rspec/matchers/built_in/throw_symbol.rb +6 -5
- data/lib/rspec/matchers/built_in/yield.rb +31 -29
- data/lib/rspec/matchers/composable.rb +138 -0
- data/lib/rspec/matchers/dsl.rb +330 -0
- data/lib/rspec/matchers/generated_descriptions.rb +6 -6
- data/lib/rspec/matchers/matcher_delegator.rb +33 -0
- data/lib/rspec/matchers/pretty.rb +13 -2
- data/spec/rspec/expectations/{differ_spec.rb → diff_presenter_spec.rb} +56 -36
- data/spec/rspec/expectations/encoded_string_spec.rb +74 -0
- data/spec/rspec/expectations/extensions/kernel_spec.rb +11 -11
- data/spec/rspec/expectations/fail_with_spec.rb +8 -8
- data/spec/rspec/expectations/handler_spec.rb +27 -49
- data/spec/rspec/expectations/minitest_integration_spec.rb +27 -0
- data/spec/rspec/expectations/syntax_spec.rb +17 -67
- data/spec/rspec/expectations_spec.rb +7 -52
- data/spec/rspec/matchers/aliased_matcher_spec.rb +48 -0
- data/spec/rspec/matchers/aliases_spec.rb +449 -0
- data/spec/rspec/matchers/{base_matcher_spec.rb → built_in/base_matcher_spec.rb} +24 -3
- data/spec/rspec/matchers/built_in/be_between_spec.rb +159 -0
- data/spec/rspec/matchers/{be_instance_of_spec.rb → built_in/be_instance_of_spec.rb} +0 -0
- data/spec/rspec/matchers/{be_kind_of_spec.rb → built_in/be_kind_of_spec.rb} +0 -0
- data/spec/rspec/matchers/{be_spec.rb → built_in/be_spec.rb} +76 -32
- data/spec/rspec/matchers/{be_within_spec.rb → built_in/be_within_spec.rb} +6 -2
- data/spec/rspec/matchers/{change_spec.rb → built_in/change_spec.rb} +310 -69
- data/spec/rspec/matchers/built_in/compound_spec.rb +292 -0
- data/spec/rspec/matchers/built_in/contain_exactly_spec.rb +441 -0
- data/spec/rspec/matchers/{cover_spec.rb → built_in/cover_spec.rb} +0 -0
- data/spec/rspec/matchers/built_in/eq_spec.rb +156 -0
- data/spec/rspec/matchers/{eql_spec.rb → built_in/eql_spec.rb} +2 -2
- data/spec/rspec/matchers/built_in/equal_spec.rb +106 -0
- data/spec/rspec/matchers/{exist_spec.rb → built_in/exist_spec.rb} +1 -1
- data/spec/rspec/matchers/{has_spec.rb → built_in/has_spec.rb} +39 -0
- data/spec/rspec/matchers/{include_spec.rb → built_in/include_spec.rb} +118 -109
- data/spec/rspec/matchers/{match_spec.rb → built_in/match_spec.rb} +30 -2
- data/spec/rspec/matchers/{operator_matcher_spec.rb → built_in/operators_spec.rb} +26 -26
- data/spec/rspec/matchers/built_in/output_spec.rb +165 -0
- data/spec/rspec/matchers/{raise_error_spec.rb → built_in/raise_error_spec.rb} +81 -11
- data/spec/rspec/matchers/{respond_to_spec.rb → built_in/respond_to_spec.rb} +0 -0
- data/spec/rspec/matchers/{satisfy_spec.rb → built_in/satisfy_spec.rb} +0 -0
- data/spec/rspec/matchers/{start_with_end_with_spec.rb → built_in/start_and_end_with_spec.rb} +82 -15
- data/spec/rspec/matchers/{throw_symbol_spec.rb → built_in/throw_symbol_spec.rb} +29 -10
- data/spec/rspec/matchers/{yield_spec.rb → built_in/yield_spec.rb} +90 -0
- data/spec/rspec/matchers/configuration_spec.rb +7 -39
- data/spec/rspec/matchers/description_generation_spec.rb +22 -6
- data/spec/rspec/matchers/dsl_spec.rb +838 -0
- data/spec/rspec/matchers/legacy_spec.rb +101 -0
- data/spec/rspec/matchers_spec.rb +74 -0
- data/spec/spec_helper.rb +35 -21
- data/spec/support/shared_examples.rb +26 -4
- metadata +172 -116
- metadata.gz.sig +3 -4
- checksums.yaml +0 -15
- checksums.yaml.gz.sig +0 -0
- data/features/built_in_matchers/match_array.feature +0 -37
- data/lib/rspec/expectations/errors.rb +0 -9
- data/lib/rspec/expectations/extensions.rb +0 -1
- data/lib/rspec/expectations/extensions/object.rb +0 -29
- data/lib/rspec/matchers/built_in/match_array.rb +0 -51
- data/lib/rspec/matchers/compatibility.rb +0 -14
- data/lib/rspec/matchers/matcher.rb +0 -301
- data/lib/rspec/matchers/method_missing.rb +0 -12
- data/lib/rspec/matchers/operator_matcher.rb +0 -99
- data/lib/rspec/matchers/test_unit_integration.rb +0 -11
- data/spec/rspec/matchers/eq_spec.rb +0 -60
- data/spec/rspec/matchers/equal_spec.rb +0 -78
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
- data/spec/rspec/matchers/match_array_spec.rb +0 -194
- data/spec/rspec/matchers/matcher_spec.rb +0 -706
- data/spec/rspec/matchers/matchers_spec.rb +0 -36
- data/spec/rspec/matchers/method_missing_spec.rb +0 -28
- data/spec/support/classes.rb +0 -56
- data/spec/support/in_sub_process.rb +0 -37
- data/spec/support/ruby_version.rb +0 -10
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec::Expectations
|
4
|
+
describe EncodedString do
|
5
|
+
let(:target_encoding) { 'UTF-8' }
|
6
|
+
|
7
|
+
if String.method_defined?(:encoding)
|
8
|
+
|
9
|
+
describe '#source_encoding' do
|
10
|
+
it 'knows the original encoding of the string' do
|
11
|
+
str = EncodedString.new("abc".encode('ASCII-8BIT'), "UTF-8")
|
12
|
+
expect( str.source_encoding.to_s ).to eq('ASCII-8BIT')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#<<' do
|
17
|
+
context 'with strings that can be converted to the target encoding' do
|
18
|
+
it 'encodes and appends the string' do
|
19
|
+
valid_ascii_string = "abc".force_encoding("ASCII-8BIT")
|
20
|
+
valid_unicode_string = "\xE2\x82\xAC".force_encoding('UTF-8')
|
21
|
+
|
22
|
+
resulting_string = build_encoded_string(valid_unicode_string, target_encoding) << valid_ascii_string
|
23
|
+
expect(resulting_string).to eq "\xE2\x82\xACabc".force_encoding('UTF-8')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with a string that cannot be converted to the target encoding' do
|
28
|
+
it 'replaces undefined characters with either a ? or a unicode ?' do
|
29
|
+
ascii_string = "\xAE".force_encoding("ASCII-8BIT")
|
30
|
+
valid_unicode_string = "\xE2\x82\xAC".force_encoding('UTF-8')
|
31
|
+
|
32
|
+
resulting_string = build_encoded_string(valid_unicode_string, target_encoding) << ascii_string
|
33
|
+
expected_bytes = [226, 130, 172, "?".unpack("c").first]
|
34
|
+
actual_bytes = resulting_string.each_byte.to_a
|
35
|
+
|
36
|
+
expect(actual_bytes).to eq(expected_bytes)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with two ascii strings with a target encoding of UTF-8 ' do
|
41
|
+
it 'has an encoding of UTF-8' do
|
42
|
+
ascii_string = 'abc'.force_encoding("ASCII-8BIT")
|
43
|
+
other_ascii_string = '123'.force_encoding("ASCII-8BIT")
|
44
|
+
|
45
|
+
resulting_string = build_encoded_string(ascii_string, target_encoding) << other_ascii_string
|
46
|
+
expect(resulting_string.encoding.to_s).to eq 'UTF-8'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#split' do
|
52
|
+
it 'splits the string based on the delimiter accounting for encoding' do
|
53
|
+
wrapped_string = "aaaaaaaaaaa\xAEaaaaa".force_encoding("ASCII-8BIT")
|
54
|
+
|
55
|
+
expect {
|
56
|
+
build_encoded_string(wrapped_string, target_encoding).split("\xE2\x82\xAC".force_encoding("UTF-8"))
|
57
|
+
}.not_to raise_error
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_encoded_string(string, target_encoding)
|
62
|
+
EncodedString.new(string, target_encoding)
|
63
|
+
end
|
64
|
+
else
|
65
|
+
|
66
|
+
describe '#source_encoding' do
|
67
|
+
it 'defaults to US-ASCII' do
|
68
|
+
str = EncodedString.new("abc", "UTF-8")
|
69
|
+
expect( str.source_encoding ).to eq('US-ASCII')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -4,18 +4,18 @@ describe Object, "#should" do
|
|
4
4
|
before(:each) do
|
5
5
|
@target = "target"
|
6
6
|
@matcher = double("matcher")
|
7
|
-
@matcher.
|
8
|
-
@matcher.
|
7
|
+
allow(@matcher).to receive(:matches?).and_return(true)
|
8
|
+
allow(@matcher).to receive(:failure_message)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "accepts and interacts with a matcher" do
|
12
|
-
@matcher.
|
12
|
+
expect(@matcher).to receive(:matches?).with(@target).and_return(true)
|
13
13
|
expect(@target).to @matcher
|
14
14
|
end
|
15
15
|
|
16
|
-
it "asks for a
|
17
|
-
@matcher.
|
18
|
-
@matcher.
|
16
|
+
it "asks for a failure_message when matches? returns false" do
|
17
|
+
expect(@matcher).to receive(:matches?).with(@target).and_return(false)
|
18
|
+
expect(@matcher).to receive(:failure_message).and_return("the failure message")
|
19
19
|
expect {
|
20
20
|
expect(@target).to @matcher
|
21
21
|
}.to fail_with("the failure message")
|
@@ -51,15 +51,15 @@ describe Object, "#should_not" do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "accepts and interacts with a matcher" do
|
54
|
-
@matcher.
|
55
|
-
@matcher.
|
54
|
+
expect(@matcher).to receive(:matches?).with(@target).and_return(false)
|
55
|
+
allow(@matcher).to receive(:failure_message_when_negated)
|
56
56
|
|
57
57
|
expect(@target).not_to @matcher
|
58
58
|
end
|
59
59
|
|
60
|
-
it "asks for a
|
61
|
-
@matcher.
|
62
|
-
@matcher.
|
60
|
+
it "asks for a failure_message_when_negated when matches? returns true" do
|
61
|
+
expect(@matcher).to receive(:matches?).with(@target).and_return(true)
|
62
|
+
expect(@matcher).to receive(:failure_message_when_negated).and_return("the failure message for should not")
|
63
63
|
expect {
|
64
64
|
expect(@target).not_to @matcher
|
65
65
|
}.to fail_with("the failure message for should not")
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
|
5
5
|
describe RSpec::Expectations, "#fail_with with diff of arrays" do
|
6
|
-
before { RSpec::Matchers.configuration.
|
6
|
+
before { allow(RSpec::Matchers.configuration).to receive_messages(:color? => false) }
|
7
7
|
|
8
8
|
it "splits items with newlines" do
|
9
9
|
expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+c\\nd\n"
|
@@ -24,11 +24,11 @@ describe RSpec::Expectations, "#fail_with with diff" do
|
|
24
24
|
let(:differ) { double("differ") }
|
25
25
|
|
26
26
|
before(:each) do
|
27
|
-
RSpec::Expectations.
|
27
|
+
allow(RSpec::Expectations).to receive(:differ) { differ }
|
28
28
|
end
|
29
29
|
|
30
30
|
it "calls differ if expected/actual are not strings (or numbers or procs)" do
|
31
|
-
differ.
|
31
|
+
expect(differ).to receive(:diff_as_object).and_return("diff")
|
32
32
|
expect {
|
33
33
|
RSpec::Expectations.fail_with "the message", Object.new, Object.new
|
34
34
|
}.to fail_with("the message\nDiff:diff")
|
@@ -37,7 +37,7 @@ describe RSpec::Expectations, "#fail_with with diff" do
|
|
37
37
|
context "with two strings" do
|
38
38
|
context "and actual is multiline" do
|
39
39
|
it "calls differ" do
|
40
|
-
differ.
|
40
|
+
expect(differ).to receive(:diff_as_string).and_return("diff")
|
41
41
|
expect {
|
42
42
|
RSpec::Expectations.fail_with "the message", "expected\nthis", "actual"
|
43
43
|
}.to fail_with("the message\nDiff:diff")
|
@@ -46,7 +46,7 @@ describe RSpec::Expectations, "#fail_with with diff" do
|
|
46
46
|
|
47
47
|
context "and expected is multiline" do
|
48
48
|
it "calls differ" do
|
49
|
-
differ.
|
49
|
+
expect(differ).to receive(:diff_as_string).and_return("diff")
|
50
50
|
expect {
|
51
51
|
RSpec::Expectations.fail_with "the message", "expected", "actual\nthat"
|
52
52
|
}.to fail_with("the message\nDiff:diff")
|
@@ -55,7 +55,7 @@ describe RSpec::Expectations, "#fail_with with diff" do
|
|
55
55
|
|
56
56
|
context "and both are single line strings" do
|
57
57
|
it "does not call differ" do
|
58
|
-
differ.
|
58
|
+
expect(differ).not_to receive(:diff_as_string)
|
59
59
|
expect {
|
60
60
|
RSpec::Expectations.fail_with("the message", "expected", "actual")
|
61
61
|
}.to fail_with("the message")
|
@@ -64,7 +64,7 @@ describe RSpec::Expectations, "#fail_with with diff" do
|
|
64
64
|
|
65
65
|
context "and they are UTF-16LE encoded", :if => String.method_defined?(:encode) do
|
66
66
|
it 'does not diff when they are not multiline' do
|
67
|
-
differ.
|
67
|
+
expect(differ).not_to receive(:diff_as_string)
|
68
68
|
|
69
69
|
str_1 = "This is a pile of poo: 💩".encode("UTF-16LE")
|
70
70
|
str_2 = "This is a pile of poo: 💩".encode("UTF-16LE")
|
@@ -75,7 +75,7 @@ describe RSpec::Expectations, "#fail_with with diff" do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'diffs when they are multiline' do
|
78
|
-
differ.
|
78
|
+
expect(differ).to receive(:diff_as_string).and_return("diff")
|
79
79
|
|
80
80
|
str_1 = "This is a pile of poo:\n💩".encode("UTF-16LE")
|
81
81
|
str_2 = "This is a pile of poo:\n💩".encode("UTF-16LE")
|
@@ -25,13 +25,13 @@ module ExampleExpectations
|
|
25
25
|
"expected #{@expected}, got #{@target}"
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def failure_message_when_negated
|
29
29
|
"expected not #{@expected}, got #{@target}"
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
class PositiveOnlyMatcher < ArbitraryMatcher
|
34
|
-
undef
|
34
|
+
undef failure_message_when_negated rescue nil
|
35
35
|
end
|
36
36
|
|
37
37
|
def arbitrary_matcher(*args, &block)
|
@@ -51,22 +51,22 @@ module RSpec
|
|
51
51
|
it "asks the matcher if it matches" do
|
52
52
|
matcher = double("matcher")
|
53
53
|
actual = Object.new
|
54
|
-
matcher.
|
54
|
+
expect(matcher).to receive(:matches?).with(actual).and_return(true)
|
55
55
|
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
|
56
56
|
end
|
57
57
|
|
58
58
|
it "returns the match value" do
|
59
59
|
matcher = double("matcher")
|
60
60
|
actual = Object.new
|
61
|
-
matcher.
|
61
|
+
expect(matcher).to receive(:matches?).with(actual).and_return(:this_value)
|
62
62
|
expect(RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)).to eq :this_value
|
63
63
|
end
|
64
64
|
|
65
|
-
it "calls
|
66
|
-
matcher = double("matcher", :
|
65
|
+
it "calls failure_message if the matcher implements it" do
|
66
|
+
matcher = double("matcher", :failure_message => "message", :matches? => false)
|
67
67
|
actual = Object.new
|
68
68
|
|
69
|
-
::RSpec::Expectations.
|
69
|
+
expect(::RSpec::Expectations).to receive(:fail_with).with("message")
|
70
70
|
|
71
71
|
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
|
72
72
|
end
|
@@ -74,44 +74,44 @@ module RSpec
|
|
74
74
|
it "calls fail if matcher.diffable?" do
|
75
75
|
matcher = double("matcher",
|
76
76
|
:diffable? => true,
|
77
|
-
:
|
77
|
+
:failure_message => "message",
|
78
78
|
:matches? => false,
|
79
79
|
:expected => 1,
|
80
80
|
:actual => 2
|
81
81
|
)
|
82
82
|
actual = Object.new
|
83
83
|
|
84
|
-
::RSpec::Expectations.
|
84
|
+
expect(::RSpec::Expectations).to receive(:fail_with).with("message", 1, 2)
|
85
85
|
|
86
86
|
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
|
87
87
|
end
|
88
88
|
|
89
|
-
it "calls failure_message if the matcher does not implement
|
89
|
+
it "calls failure_message if the matcher does not implement failure_message" do
|
90
90
|
matcher = double("matcher", :failure_message => "message", :matches? => false)
|
91
91
|
actual = Object.new
|
92
92
|
|
93
|
-
::RSpec::Expectations.
|
93
|
+
expect(::RSpec::Expectations).to receive(:fail_with).with("message")
|
94
94
|
|
95
95
|
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
|
96
96
|
|
97
97
|
end
|
98
98
|
|
99
99
|
it "uses the custom failure message when one is provided" do
|
100
|
-
matcher = double("matcher", :
|
100
|
+
matcher = double("matcher", :failure_message => "message", :matches? => false)
|
101
101
|
actual = Object.new
|
102
102
|
|
103
|
-
::RSpec::Expectations.
|
103
|
+
expect(::RSpec::Expectations).to receive(:fail_with).with("custom")
|
104
104
|
|
105
105
|
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, "custom")
|
106
106
|
end
|
107
107
|
|
108
108
|
it "uses the custom failure message when one is provided as a callable object" do
|
109
|
-
matcher = double("matcher", :
|
109
|
+
matcher = double("matcher", :failure_message => "message", :matches? => false)
|
110
110
|
actual = Object.new
|
111
111
|
|
112
112
|
failure_message = double("failure message", :call => "custom")
|
113
113
|
|
114
|
-
::RSpec::Expectations.
|
114
|
+
expect(::RSpec::Expectations).to receive(:fail_with).with("custom")
|
115
115
|
|
116
116
|
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, failure_message)
|
117
117
|
end
|
@@ -121,81 +121,59 @@ module RSpec
|
|
121
121
|
describe NegativeExpectationHandler do
|
122
122
|
describe "#handle_matcher" do
|
123
123
|
it "asks the matcher if it doesn't match when the matcher responds to #does_not_match?" do
|
124
|
-
matcher = double("matcher", :does_not_match? => true, :
|
124
|
+
matcher = double("matcher", :does_not_match? => true, :failure_message_when_negated => nil)
|
125
125
|
actual = Object.new
|
126
|
-
matcher.
|
126
|
+
expect(matcher).to receive(:does_not_match?).with(actual).and_return(true)
|
127
127
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
128
128
|
end
|
129
129
|
|
130
130
|
it "asks the matcher if it matches when the matcher doesn't respond to #does_not_match?" do
|
131
131
|
matcher = double("matcher")
|
132
132
|
actual = Object.new
|
133
|
-
matcher.
|
134
|
-
matcher.
|
133
|
+
allow(matcher).to receive(:failure_message_when_negated)
|
134
|
+
expect(matcher).to receive(:matches?).with(actual).and_return(false)
|
135
135
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
136
136
|
end
|
137
137
|
|
138
138
|
it "returns the match value" do
|
139
139
|
matcher = double("matcher")
|
140
140
|
actual = Object.new
|
141
|
-
matcher.
|
142
|
-
matcher.
|
141
|
+
expect(matcher).to receive(:matches?).with(actual).and_return(false)
|
142
|
+
allow(matcher).to receive(:failure_message_when_negated).and_return("ignore")
|
143
143
|
expect(RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)).to be_falsey
|
144
144
|
end
|
145
145
|
|
146
|
-
|
147
|
-
it "calls failure_message_for_should_not if the matcher implements it" do
|
148
|
-
matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
|
149
|
-
actual = Object.new
|
150
|
-
|
151
|
-
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
152
|
-
|
153
|
-
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
it "calls negative_failure_message if the matcher does not implement failure_message_for_should_not" do
|
158
|
-
matcher = double("matcher", :negative_failure_message => "message", :matches? => true)
|
159
|
-
actual = Object.new
|
160
|
-
|
161
|
-
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
162
|
-
|
163
|
-
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
|
168
146
|
it "calls fail if matcher.diffable?" do
|
169
147
|
matcher = double("matcher",
|
170
148
|
:diffable? => true,
|
171
|
-
:
|
149
|
+
:failure_message_when_negated => "message",
|
172
150
|
:matches? => true,
|
173
151
|
:expected => 1,
|
174
152
|
:actual => 2
|
175
153
|
)
|
176
154
|
actual = Object.new
|
177
155
|
|
178
|
-
::RSpec::Expectations.
|
156
|
+
expect(::RSpec::Expectations).to receive(:fail_with).with("message", 1, 2)
|
179
157
|
|
180
158
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
181
159
|
end
|
182
160
|
|
183
161
|
it "uses the custom failure message when one is provided" do
|
184
|
-
matcher = double("matcher", :
|
162
|
+
matcher = double("matcher", :failure_message_when_negated => "message", :matches? => true)
|
185
163
|
actual = Object.new
|
186
164
|
|
187
|
-
::RSpec::Expectations.
|
165
|
+
expect(::RSpec::Expectations).to receive(:fail_with).with("custom")
|
188
166
|
|
189
167
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, "custom")
|
190
168
|
end
|
191
169
|
|
192
170
|
it "uses the custom failure message when one is provided as a callable object" do
|
193
|
-
matcher = double("matcher", :
|
171
|
+
matcher = double("matcher", :failure_message_when_negated => "message", :matches? => true)
|
194
172
|
actual = Object.new
|
195
173
|
|
196
174
|
failure_message = double("failure message", :call => "custom")
|
197
175
|
|
198
|
-
::RSpec::Expectations.
|
176
|
+
expect(::RSpec::Expectations).to receive(:fail_with).with("custom")
|
199
177
|
|
200
178
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, failure_message)
|
201
179
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
describe Matchers do
|
5
|
+
|
6
|
+
let(:sample_matchers) do
|
7
|
+
[:be,
|
8
|
+
:be_instance_of,
|
9
|
+
:be_kind_of]
|
10
|
+
end
|
11
|
+
|
12
|
+
context "once required" do
|
13
|
+
include MinitestIntegration
|
14
|
+
|
15
|
+
it "includes itself in Minitest::Test" do
|
16
|
+
with_minitest_loaded do
|
17
|
+
minitest_case = MiniTest::Test.allocate
|
18
|
+
sample_matchers.each do |sample_matcher|
|
19
|
+
expect(minitest_case).to respond_to(sample_matcher)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -20,118 +20,68 @@ module RSpec
|
|
20
20
|
|
21
21
|
describe "expect(...).to" do
|
22
22
|
it "prints a warning when the message object isn't a String" do
|
23
|
-
warner.
|
23
|
+
expect(warner).to receive(:warn).with(/ignoring.*message/)
|
24
24
|
expect(3).to eq(3), :not_a_string
|
25
25
|
end
|
26
26
|
|
27
27
|
it "doesn't print a warning when message is a String" do
|
28
|
-
warner.
|
28
|
+
expect(warner).not_to receive(:warn)
|
29
29
|
expect(3).to eq(3), "a string"
|
30
30
|
end
|
31
31
|
|
32
32
|
it "doesn't print a warning when message responds to to_str" do
|
33
|
-
warner.
|
33
|
+
expect(warner).not_to receive(:warn)
|
34
34
|
expect(3).to eq(3), string_like_object
|
35
35
|
end
|
36
36
|
|
37
37
|
it "prints a warning when the message object handles to_s but not to_str" do
|
38
|
-
warner.
|
38
|
+
expect(warner).to receive(:warn).with(/ignoring.*message/)
|
39
39
|
expect(3).to eq(3), insufficiently_string_like_object
|
40
40
|
end
|
41
41
|
|
42
42
|
it "doesn't print a warning when message responds to call" do
|
43
|
-
warner.
|
43
|
+
expect(warner).not_to receive(:warn)
|
44
44
|
expect(3).to eq(3), callable_object
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "expect(...).not_to" do
|
49
49
|
it "prints a warning when the message object isn't a String" do
|
50
|
-
warner.
|
50
|
+
expect(warner).to receive(:warn).with(/ignoring.*message/)
|
51
51
|
expect(3).not_to eq(4), :not_a_string
|
52
52
|
end
|
53
53
|
|
54
54
|
it "doesn't print a warning when message is a String" do
|
55
|
-
warner.
|
55
|
+
expect(warner).not_to receive(:warn)
|
56
56
|
expect(3).not_to eq(4), "a string"
|
57
57
|
end
|
58
58
|
|
59
59
|
it "doesn't print a warning when message responds to to_str" do
|
60
|
-
warner.
|
60
|
+
expect(warner).not_to receive(:warn)
|
61
61
|
expect(3).not_to eq(4), string_like_object
|
62
62
|
end
|
63
63
|
|
64
64
|
it "prints a warning when the message object handles to_s but not to_str" do
|
65
|
-
warner.
|
65
|
+
expect(warner).to receive(:warn).with(/ignoring.*message/)
|
66
66
|
expect(3).not_to eq(4), insufficiently_string_like_object
|
67
67
|
end
|
68
68
|
|
69
69
|
it "doesn't print a warning when message responds to call" do
|
70
|
-
warner.
|
70
|
+
expect(warner).not_to receive(:warn)
|
71
71
|
expect(3).not_to eq(4), callable_object
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
describe "
|
77
|
-
|
78
|
-
let(:expectation) { "eq('bar')" }
|
79
|
-
let(:positive_expect_example) { "expect(foo).to eq('bar')" }
|
80
|
-
let(:positive_should_example) { "foo.should eq('bar')" }
|
81
|
-
let(:negative_expect_example) { "expect(foo).not_to eq('bar')" }
|
82
|
-
let(:negative_should_example) { "foo.should_not eq('bar')" }
|
76
|
+
describe "enabling the should syntax on something other than the default syntax host" do
|
77
|
+
include_context "with the default expectation syntax"
|
83
78
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
def negative_expression
|
89
|
-
Syntax.negative_expression(target, expectation)
|
90
|
-
end
|
91
|
-
|
92
|
-
context "when only :expect is enabled" do
|
93
|
-
before do
|
94
|
-
expect(Syntax.should_enabled?).to be_falsey
|
95
|
-
expect(Syntax.expect_enabled?).to be_truthy
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'generates a positive expression using the expect syntax' do
|
99
|
-
expect(positive_expression).to eq(positive_expect_example)
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'generates a negative expression using the expect syntax' do
|
103
|
-
expect(negative_expression).to eq(negative_expect_example)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context "when both :should and :expect are enabled", :uses_should do
|
108
|
-
before do
|
109
|
-
expect(Syntax.should_enabled?).to be_truthy
|
110
|
-
expect(Syntax.expect_enabled?).to be_truthy
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'generates a positive expression using the expect syntax' do
|
114
|
-
expect(positive_expression).to eq(positive_expect_example)
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'generates a negative expression using the expect syntax' do
|
118
|
-
expect(negative_expression).to eq(negative_expect_example)
|
119
|
-
end
|
120
|
-
end
|
79
|
+
it "continues to warn about the should syntax" do
|
80
|
+
my_host = Class.new
|
81
|
+
expect(RSpec).to receive(:deprecate)
|
82
|
+
Syntax.enable_should(my_host)
|
121
83
|
|
122
|
-
|
123
|
-
before do
|
124
|
-
Syntax.should_enabled?.should be_truthy
|
125
|
-
Syntax.expect_enabled?.should be_falsey
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'generates a positive expression using the expect syntax' do
|
129
|
-
positive_expression.should eq(positive_should_example)
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'generates a negative expression using the expect syntax' do
|
133
|
-
negative_expression.should eq(negative_should_example)
|
134
|
-
end
|
84
|
+
3.should eq 3
|
135
85
|
end
|
136
86
|
end
|
137
87
|
end
|