rspec-expectations 2.13.0 → 2.14.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +34 -0
- data/README.md +43 -87
- data/features/README.md +8 -9
- data/features/built_in_matchers/README.md +41 -41
- 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/support/env.rb +10 -1
- data/features/syntax_configuration.feature +3 -0
- data/features/test_frameworks/test_unit.feature +15 -17
- data/lib/rspec/expectations.rb +1 -1
- data/lib/rspec/expectations/deprecation.rb +12 -33
- data/lib/rspec/expectations/differ.rb +25 -7
- data/lib/rspec/expectations/expectation_target.rb +7 -8
- data/lib/rspec/expectations/extensions/object.rb +2 -12
- data/lib/rspec/expectations/fail_with.rb +11 -1
- data/lib/rspec/expectations/handler.rb +11 -6
- data/lib/rspec/expectations/syntax.rb +2 -2
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +134 -144
- data/lib/rspec/matchers/be_close.rb +1 -1
- data/lib/rspec/matchers/built_in/be_within.rb +1 -1
- data/lib/rspec/matchers/built_in/have.rb +20 -4
- data/lib/rspec/matchers/built_in/raise_error.rb +23 -7
- data/lib/rspec/matchers/built_in/yield.rb +78 -3
- data/lib/rspec/matchers/operator_matcher.rb +1 -1
- data/lib/rspec/matchers/test_unit_integration.rb +11 -0
- data/spec/rspec/expectations/differ_spec.rb +27 -5
- data/spec/rspec/expectations/expectation_target_spec.rb +10 -3
- data/spec/rspec/expectations/extensions/kernel_spec.rb +5 -5
- data/spec/rspec/expectations/fail_with_spec.rb +19 -0
- data/spec/rspec/expectations/handler_spec.rb +42 -21
- data/spec/rspec/expectations/syntax_spec.rb +45 -3
- data/spec/rspec/matchers/be_close_spec.rb +6 -6
- data/spec/rspec/matchers/be_spec.rb +36 -36
- data/spec/rspec/matchers/be_within_spec.rb +4 -0
- data/spec/rspec/matchers/change_spec.rb +6 -6
- data/spec/rspec/matchers/configuration_spec.rb +57 -89
- data/spec/rspec/matchers/description_generation_spec.rb +1 -1
- data/spec/rspec/matchers/exist_spec.rb +9 -9
- data/spec/rspec/matchers/has_spec.rb +1 -1
- data/spec/rspec/matchers/have_spec.rb +12 -2
- 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 +1 -1
- data/spec/rspec/matchers/raise_error_spec.rb +189 -99
- 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/yield_spec.rb +81 -4
- data/spec/spec_helper.rb +1 -1
- metadata +10 -12
@@ -2,7 +2,7 @@ module RSpec
|
|
2
2
|
module Matchers
|
3
3
|
# @deprecated use +be_within+ instead.
|
4
4
|
def be_close(expected, delta)
|
5
|
-
RSpec.deprecate("be_close(#{expected}, #{delta})", "be_within(#{delta}).of(#{expected})")
|
5
|
+
RSpec.deprecate("be_close(#{expected}, #{delta})", :replacement => "be_within(#{delta}).of(#{expected})")
|
6
6
|
be_within(delta).of(expected)
|
7
7
|
end
|
8
8
|
end
|
@@ -2,6 +2,8 @@ module RSpec
|
|
2
2
|
module Matchers
|
3
3
|
module BuiltIn
|
4
4
|
class Have
|
5
|
+
QUERY_METHODS = [:size, :length, :count].freeze
|
6
|
+
|
5
7
|
def initialize(expected, relativity=:exactly)
|
6
8
|
@expected = case expected
|
7
9
|
when :no then 0
|
@@ -22,9 +24,19 @@ module RSpec
|
|
22
24
|
|
23
25
|
def matches?(collection_or_owner)
|
24
26
|
collection = determine_collection(collection_or_owner)
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
case collection
|
28
|
+
when enumerator_class
|
29
|
+
for query_method in QUERY_METHODS
|
30
|
+
next unless collection.respond_to?(query_method)
|
31
|
+
@actual = collection.__send__(query_method)
|
32
|
+
break unless @actual.nil?
|
33
|
+
end
|
34
|
+
raise not_a_collection if @actual.nil?
|
35
|
+
else
|
36
|
+
query_method = determine_query_method(collection)
|
37
|
+
raise not_a_collection unless query_method
|
38
|
+
@actual = collection.__send__(query_method)
|
39
|
+
end
|
28
40
|
case @relativity
|
29
41
|
when :at_least then @actual >= @expected
|
30
42
|
when :at_most then @actual <= @expected
|
@@ -46,7 +58,7 @@ module RSpec
|
|
46
58
|
end
|
47
59
|
|
48
60
|
def determine_query_method(collection)
|
49
|
-
|
61
|
+
QUERY_METHODS.detect {|m| collection.respond_to?(m)}
|
50
62
|
end
|
51
63
|
|
52
64
|
def not_a_collection
|
@@ -102,6 +114,10 @@ EOF
|
|
102
114
|
def relative_expectation
|
103
115
|
"#{relativities[@relativity]}#{@expected}"
|
104
116
|
end
|
117
|
+
|
118
|
+
def enumerator_class
|
119
|
+
RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator
|
120
|
+
end
|
105
121
|
end
|
106
122
|
end
|
107
123
|
end
|
@@ -14,19 +14,31 @@ module RSpec
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def matches?(given_proc, negative_expectation = false)
|
17
|
+
if negative_expectation && (expecting_specific_exception? || @expected_message)
|
18
|
+
what_to_deprecate = if expecting_specific_exception? && @expected_message
|
19
|
+
"`expect { }.not_to raise_error(SpecificErrorClass, message)`"
|
20
|
+
elsif expecting_specific_exception?
|
21
|
+
"`expect { }.not_to raise_error(SpecificErrorClass)`"
|
22
|
+
elsif @expected_message
|
23
|
+
"`expect { }.not_to raise_error(message)`"
|
24
|
+
end
|
25
|
+
RSpec.deprecate(what_to_deprecate, :replacement => "`expect { }.not_to raise_error()`")
|
26
|
+
end
|
17
27
|
@raised_expected_error = false
|
18
28
|
@with_expected_message = false
|
19
29
|
@eval_block = false
|
20
30
|
@eval_block_passed = false
|
31
|
+
unless given_proc.respond_to?(:call)
|
32
|
+
::Kernel.warn "`raise_error` was called with non-proc object #{given_proc.inspect}"
|
33
|
+
return false
|
34
|
+
end
|
21
35
|
begin
|
22
36
|
given_proc.call
|
23
|
-
rescue @expected_error => @actual_error
|
24
|
-
@raised_expected_error = true
|
25
|
-
@with_expected_message = verify_message
|
26
37
|
rescue Exception => @actual_error
|
27
|
-
|
28
|
-
|
29
|
-
|
38
|
+
if @actual_error == @expected_error || @expected_error === @actual_error
|
39
|
+
@raised_expected_error = true
|
40
|
+
@with_expected_message = verify_message
|
41
|
+
end
|
30
42
|
end
|
31
43
|
|
32
44
|
unless negative_expectation
|
@@ -79,7 +91,7 @@ module RSpec
|
|
79
91
|
def expected_error
|
80
92
|
case @expected_message
|
81
93
|
when nil
|
82
|
-
@expected_error
|
94
|
+
@expected_error.inspect
|
83
95
|
when Regexp
|
84
96
|
"#{@expected_error} with message matching #{@expected_message.inspect}"
|
85
97
|
else
|
@@ -101,6 +113,10 @@ module RSpec
|
|
101
113
|
*backtrace
|
102
114
|
].join("\n # ")
|
103
115
|
end
|
116
|
+
|
117
|
+
def expecting_specific_exception?
|
118
|
+
@expected_error != Exception
|
119
|
+
end
|
104
120
|
end
|
105
121
|
end
|
106
122
|
end
|
@@ -65,17 +65,92 @@ module RSpec
|
|
65
65
|
end
|
66
66
|
|
67
67
|
class YieldControl < BaseMatcher
|
68
|
+
def initialize
|
69
|
+
@expectation_type = nil
|
70
|
+
@expected_yields_count = nil
|
71
|
+
end
|
72
|
+
|
68
73
|
def matches?(block)
|
69
74
|
probe = YieldProbe.probe(block)
|
70
|
-
|
75
|
+
|
76
|
+
if @expectation_type
|
77
|
+
probe.num_yields.send(@expectation_type, @expected_yields_count)
|
78
|
+
else
|
79
|
+
probe.yielded_once?(:yield_control)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def once
|
84
|
+
exactly(1)
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
def twice
|
89
|
+
exactly(2)
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
def exactly(number)
|
94
|
+
set_expected_yields_count(:==, number)
|
95
|
+
self
|
96
|
+
end
|
97
|
+
|
98
|
+
def at_most(number)
|
99
|
+
set_expected_yields_count(:<=, number)
|
100
|
+
self
|
101
|
+
end
|
102
|
+
|
103
|
+
def at_least(number)
|
104
|
+
set_expected_yields_count(:>=, number)
|
105
|
+
self
|
106
|
+
end
|
107
|
+
|
108
|
+
def times
|
109
|
+
self
|
71
110
|
end
|
72
111
|
|
73
112
|
def failure_message_for_should
|
74
|
-
|
113
|
+
'expected given block to yield control'.tap do |failure_message|
|
114
|
+
failure_message << relativity_failure_message
|
115
|
+
end
|
75
116
|
end
|
76
117
|
|
77
118
|
def failure_message_for_should_not
|
78
|
-
|
119
|
+
'expected given block not to yield control'.tap do |failure_message|
|
120
|
+
failure_message << relativity_failure_message
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def set_expected_yields_count(relativity, n)
|
127
|
+
@expectation_type = relativity
|
128
|
+
@expected_yields_count = case n
|
129
|
+
when Numeric then n
|
130
|
+
when :once then 1
|
131
|
+
when :twice then 2
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def relativity_failure_message
|
136
|
+
return '' unless @expected_yields_count
|
137
|
+
" #{human_readable_expecation_type}#{human_readable_count}"
|
138
|
+
end
|
139
|
+
|
140
|
+
def human_readable_expecation_type
|
141
|
+
case @expectation_type
|
142
|
+
when :<= then 'at most '
|
143
|
+
when :>= then 'at least '
|
144
|
+
else ''
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def human_readable_count
|
149
|
+
case @expected_yields_count
|
150
|
+
when 1 then "once"
|
151
|
+
when 2 then "twice"
|
152
|
+
else "#{@expected_yields_count} times"
|
153
|
+
end
|
79
154
|
end
|
80
155
|
end
|
81
156
|
|
@@ -91,7 +91,7 @@ module RSpec
|
|
91
91
|
if actual.__send__(operator, expected)
|
92
92
|
true
|
93
93
|
elsif ['==','===', '=~'].include?(operator)
|
94
|
-
fail_with_message("expected: #{expected.inspect}\n got: #{actual.inspect} (using #{operator})")
|
94
|
+
fail_with_message("expected: #{expected.inspect}\n got: #{actual.inspect} (using #{operator})")
|
95
95
|
else
|
96
96
|
fail_with_message("expected: #{operator} #{expected.inspect}\n got: #{operator.gsub(/./, ' ')} #{actual.inspect}")
|
97
97
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Include Matchers for other test frameworks. Note that MiniTest _must_
|
2
|
+
# come before TU because on ruby 1.9, T::U::TC is a subclass of MT::U::TC
|
3
|
+
# and a 1.9 bug can lead to infinite recursion from the `super` call in our
|
4
|
+
# method_missing hook. See this gist for more info:
|
5
|
+
# https://gist.github.com/845896
|
6
|
+
if defined?(MiniTest::Unit::TestCase)
|
7
|
+
MiniTest::Unit::TestCase.send(:include, RSpec::Matchers)
|
8
|
+
end
|
9
|
+
if defined?(Test::Unit::TestCase)
|
10
|
+
Test::Unit::TestCase.send(:include, RSpec::Matchers)
|
11
|
+
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,28 @@ 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 'ouputs a message when encountering differently encoded strings' do
|
58
|
+
@expected="Tu avec carté {count} itém has".encode('UTF-16LE')
|
59
|
+
@actual="Tu avec carte {count} item has"
|
60
|
+
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)'
|
61
|
+
end
|
40
62
|
end
|
41
63
|
end
|
42
64
|
|
@@ -37,10 +37,13 @@ module RSpec
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'passes a valid negative expectation' do
|
40
|
-
expect(5).to_not eq(4)
|
41
40
|
expect(5).not_to eq(4)
|
42
41
|
end
|
43
42
|
|
43
|
+
it 'passes a valid negative expectation with a split infinitive' do
|
44
|
+
expect(5).to_not eq(4)
|
45
|
+
end
|
46
|
+
|
44
47
|
it 'fails an invalid positive expectation' do
|
45
48
|
expect {
|
46
49
|
expect(5).to eq(4)
|
@@ -50,10 +53,14 @@ module RSpec
|
|
50
53
|
it 'fails an invalid negative expectation' do
|
51
54
|
message = /expected 5 not to be a kind of Fixnum/
|
52
55
|
expect {
|
53
|
-
expect(5).
|
56
|
+
expect(5).not_to be_a(Fixnum)
|
54
57
|
}.to fail_with(message)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'fails an invalid negative expectation with a split infinitive' do
|
61
|
+
message = /expected 5 not to be a kind of Fixnum/
|
55
62
|
expect {
|
56
|
-
expect(5).
|
63
|
+
expect(5).to_not be_a(Fixnum)
|
57
64
|
}.to fail_with(message)
|
58
65
|
end
|
59
66
|
|
@@ -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
|
@@ -47,12 +47,12 @@ end
|
|
47
47
|
describe Object, "#should_not" do
|
48
48
|
before(:each) do
|
49
49
|
@target = "target"
|
50
|
-
@matcher =
|
50
|
+
@matcher = double("matcher")
|
51
51
|
end
|
52
52
|
|
53
53
|
it "accepts and interacts with a matcher" do
|
54
54
|
@matcher.should_receive(:matches?).with(@target).and_return(false)
|
55
|
-
@matcher.stub
|
55
|
+
@matcher.stub(:failure_message_for_should_not)
|
56
56
|
|
57
57
|
expect(@target).not_to @matcher
|
58
58
|
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
|
|
@@ -49,21 +49,21 @@ module RSpec
|
|
49
49
|
describe PositiveExpectationHandler do
|
50
50
|
describe "#handle_matcher" do
|
51
51
|
it "asks the matcher if it matches" do
|
52
|
-
matcher =
|
52
|
+
matcher = double("matcher")
|
53
53
|
actual = Object.new
|
54
54
|
matcher.should_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
|
-
matcher =
|
59
|
+
matcher = double("matcher")
|
60
60
|
actual = Object.new
|
61
61
|
matcher.should_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
65
|
it "calls failure_message_for_should if the matcher implements it" do
|
66
|
-
matcher =
|
66
|
+
matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
|
67
67
|
actual = Object.new
|
68
68
|
|
69
69
|
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
@@ -72,7 +72,7 @@ module RSpec
|
|
72
72
|
end
|
73
73
|
|
74
74
|
it "calls fail if matcher.diffable?" do
|
75
|
-
matcher =
|
75
|
+
matcher = double("matcher",
|
76
76
|
:diffable? => true,
|
77
77
|
:failure_message_for_should => "message",
|
78
78
|
:matches? => false,
|
@@ -87,7 +87,7 @@ module RSpec
|
|
87
87
|
end
|
88
88
|
|
89
89
|
it "calls failure_message if the matcher does not implement failure_message_for_should" do
|
90
|
-
matcher =
|
90
|
+
matcher = double("matcher", :failure_message => "message", :matches? => false)
|
91
91
|
actual = Object.new
|
92
92
|
|
93
93
|
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
@@ -96,45 +96,56 @@ module RSpec
|
|
96
96
|
|
97
97
|
end
|
98
98
|
|
99
|
-
it "
|
100
|
-
matcher =
|
99
|
+
it "uses the custom failure message when one is provided" do
|
100
|
+
matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
|
101
101
|
actual = Object.new
|
102
102
|
|
103
103
|
::RSpec::Expectations.should_receive(:fail_with).with("custom")
|
104
104
|
|
105
105
|
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, "custom")
|
106
106
|
end
|
107
|
+
|
108
|
+
it "uses the custom failure message when one is provided as a callable object" do
|
109
|
+
matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
|
110
|
+
actual = Object.new
|
111
|
+
|
112
|
+
failure_message = double("failure message", :call => "custom")
|
113
|
+
|
114
|
+
::RSpec::Expectations.should_receive(:fail_with).with("custom")
|
115
|
+
|
116
|
+
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, failure_message)
|
117
|
+
end
|
107
118
|
end
|
108
119
|
end
|
109
120
|
|
110
121
|
describe NegativeExpectationHandler do
|
111
122
|
describe "#handle_matcher" do
|
112
123
|
it "asks the matcher if it doesn't match when the matcher responds to #does_not_match?" do
|
113
|
-
matcher =
|
124
|
+
matcher = double("matcher", :does_not_match? => true, :negative_failure_message => nil)
|
114
125
|
actual = Object.new
|
115
126
|
matcher.should_receive(:does_not_match?).with(actual).and_return(true)
|
116
127
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
117
128
|
end
|
118
129
|
|
119
130
|
it "asks the matcher if it matches when the matcher doesn't respond to #does_not_match?" do
|
120
|
-
matcher =
|
131
|
+
matcher = double("matcher")
|
121
132
|
actual = Object.new
|
122
|
-
matcher.stub
|
133
|
+
matcher.stub(:negative_failure_message)
|
123
134
|
matcher.should_receive(:matches?).with(actual).and_return(false)
|
124
135
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
125
136
|
end
|
126
137
|
|
127
138
|
it "returns the match value" do
|
128
|
-
matcher =
|
139
|
+
matcher = double("matcher")
|
129
140
|
actual = Object.new
|
130
141
|
matcher.should_receive(:matches?).with(actual).and_return(false)
|
131
|
-
matcher.stub
|
142
|
+
matcher.stub(:negative_failure_message).and_return("ignore")
|
132
143
|
expect(RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)).to be_false
|
133
144
|
end
|
134
145
|
|
135
146
|
|
136
147
|
it "calls failure_message_for_should_not if the matcher implements it" do
|
137
|
-
matcher =
|
148
|
+
matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
|
138
149
|
actual = Object.new
|
139
150
|
|
140
151
|
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
@@ -144,7 +155,7 @@ module RSpec
|
|
144
155
|
end
|
145
156
|
|
146
157
|
it "calls negative_failure_message if the matcher does not implement failure_message_for_should_not" do
|
147
|
-
matcher =
|
158
|
+
matcher = double("matcher", :negative_failure_message => "message", :matches? => true)
|
148
159
|
actual = Object.new
|
149
160
|
|
150
161
|
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
@@ -155,7 +166,7 @@ module RSpec
|
|
155
166
|
|
156
167
|
|
157
168
|
it "calls fail if matcher.diffable?" do
|
158
|
-
matcher =
|
169
|
+
matcher = double("matcher",
|
159
170
|
:diffable? => true,
|
160
171
|
:failure_message_for_should_not => "message",
|
161
172
|
:matches? => true,
|
@@ -169,8 +180,8 @@ module RSpec
|
|
169
180
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
170
181
|
end
|
171
182
|
|
172
|
-
it "
|
173
|
-
matcher =
|
183
|
+
it "uses the custom failure message when one is provided" do
|
184
|
+
matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
|
174
185
|
actual = Object.new
|
175
186
|
|
176
187
|
::RSpec::Expectations.should_receive(:fail_with).with("custom")
|
@@ -178,6 +189,16 @@ module RSpec
|
|
178
189
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, "custom")
|
179
190
|
end
|
180
191
|
|
192
|
+
it "uses the custom failure message when one is provided as a callable object" do
|
193
|
+
matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
|
194
|
+
actual = Object.new
|
195
|
+
|
196
|
+
failure_message = double("failure message", :call => "custom")
|
197
|
+
|
198
|
+
::RSpec::Expectations.should_receive(:fail_with).with("custom")
|
199
|
+
|
200
|
+
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, failure_message)
|
201
|
+
end
|
181
202
|
end
|
182
203
|
end
|
183
204
|
|
@@ -189,10 +210,10 @@ module RSpec
|
|
189
210
|
expect(5).to arbitrary_matcher(:expected => "wrong").with(5)
|
190
211
|
expect { expect(5).to arbitrary_matcher(:expected => 4) }.to fail_with("expected 4, got 5")
|
191
212
|
expect { expect(5).to arbitrary_matcher(:expected => 5).with(4) }.to fail_with("expected 4, got 5")
|
192
|
-
expect(5).
|
193
|
-
expect(5).
|
194
|
-
expect { expect(5).
|
195
|
-
expect { expect(5).
|
213
|
+
expect(5).not_to arbitrary_matcher(:expected => 4)
|
214
|
+
expect(5).not_to arbitrary_matcher(:expected => 5).with(4)
|
215
|
+
expect { expect(5).not_to arbitrary_matcher(:expected => 5) }.to fail_with("expected not 5, got 5")
|
216
|
+
expect { expect(5).not_to arbitrary_matcher(:expected => 4).with(5) }.to fail_with("expected not 5, got 5")
|
196
217
|
end
|
197
218
|
|
198
219
|
it "handles the submitted block" do
|