rspec-expectations 3.13.6 → 4.0.0.beta1
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Changelog.md +27 -9
- data/LICENSE.md +1 -0
- data/README.md +7 -67
- data/lib/rspec/expectations/block_snippet_extractor.rb +3 -1
- data/lib/rspec/expectations/configuration.rb +2 -99
- data/lib/rspec/expectations/expectation_target.rb +11 -12
- data/lib/rspec/expectations/fail_with.rb +2 -0
- data/lib/rspec/expectations/failure_aggregator.rb +4 -2
- data/lib/rspec/expectations/handler.rb +2 -103
- data/lib/rspec/expectations/minitest_integration.rb +2 -0
- data/lib/rspec/expectations/version.rb +3 -1
- data/lib/rspec/expectations.rb +5 -0
- data/lib/rspec/matchers/aliased_matcher.rb +2 -0
- data/lib/rspec/matchers/built_in/all.rb +2 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +10 -30
- data/lib/rspec/matchers/built_in/be.rb +4 -2
- data/lib/rspec/matchers/built_in/be_between.rb +2 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +2 -0
- data/lib/rspec/matchers/built_in/be_kind_of.rb +2 -0
- data/lib/rspec/matchers/built_in/be_within.rb +2 -0
- data/lib/rspec/matchers/built_in/change.rb +24 -39
- data/lib/rspec/matchers/built_in/compound.rb +16 -12
- data/lib/rspec/matchers/built_in/contain_exactly.rb +6 -15
- data/lib/rspec/matchers/built_in/count_expectation.rb +7 -17
- data/lib/rspec/matchers/built_in/cover.rb +2 -0
- data/lib/rspec/matchers/built_in/eq.rb +2 -0
- data/lib/rspec/matchers/built_in/eql.rb +2 -0
- data/lib/rspec/matchers/built_in/equal.rb +2 -0
- data/lib/rspec/matchers/built_in/exist.rb +4 -2
- data/lib/rspec/matchers/built_in/has.rb +9 -40
- data/lib/rspec/matchers/built_in/have_attributes.rb +2 -0
- data/lib/rspec/matchers/built_in/include.rb +8 -14
- data/lib/rspec/matchers/built_in/match.rb +3 -39
- data/lib/rspec/matchers/built_in/output.rb +50 -14
- data/lib/rspec/matchers/built_in/raise_error.rb +15 -25
- data/lib/rspec/matchers/built_in/respond_to.rb +3 -1
- data/lib/rspec/matchers/built_in/satisfy.rb +2 -0
- data/lib/rspec/matchers/built_in/start_or_end_with.rb +2 -6
- data/lib/rspec/matchers/built_in/throw_symbol.rb +4 -7
- data/lib/rspec/matchers/built_in/yield.rb +21 -50
- data/lib/rspec/matchers/built_in.rb +2 -3
- data/lib/rspec/matchers/composable.rb +2 -1
- data/lib/rspec/matchers/dsl.rb +19 -71
- data/lib/rspec/matchers/english_phrasing.rb +2 -18
- data/lib/rspec/matchers/fail_matchers.rb +2 -0
- data/lib/rspec/matchers/generated_descriptions.rb +2 -0
- data/lib/rspec/matchers/matcher_delegator.rb +9 -13
- data/lib/rspec/matchers/matcher_protocol.rb +2 -0
- data/lib/rspec/matchers/multi_matcher_diff.rb +5 -3
- data/lib/rspec/matchers.rb +11 -60
- data.tar.gz.sig +0 -0
- metadata +14 -16
- metadata.gz.sig +0 -0
- data/lib/rspec/expectations/syntax.rb +0 -132
- data/lib/rspec/matchers/built_in/operators.rb +0 -128
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
require 'rspec/support'
|
|
2
|
-
|
|
3
|
-
module RSpec
|
|
4
|
-
module Matchers
|
|
5
|
-
module BuiltIn
|
|
6
|
-
# @api private
|
|
7
|
-
# Provides the implementation for operator matchers.
|
|
8
|
-
# Not intended to be instantiated directly.
|
|
9
|
-
# Only available for use with `should`.
|
|
10
|
-
class OperatorMatcher
|
|
11
|
-
class << self
|
|
12
|
-
# @private
|
|
13
|
-
def registry
|
|
14
|
-
@registry ||= {}
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# @private
|
|
18
|
-
def register(klass, operator, matcher)
|
|
19
|
-
registry[klass] ||= {}
|
|
20
|
-
registry[klass][operator] = matcher
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# @private
|
|
24
|
-
def unregister(klass, operator)
|
|
25
|
-
registry[klass] && registry[klass].delete(operator)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# @private
|
|
29
|
-
def get(klass, operator)
|
|
30
|
-
klass.ancestors.each do |ancestor|
|
|
31
|
-
matcher = registry[ancestor] && registry[ancestor][operator]
|
|
32
|
-
return matcher if matcher
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
nil
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
register Enumerable, '=~', BuiltIn::ContainExactly
|
|
40
|
-
|
|
41
|
-
def initialize(actual)
|
|
42
|
-
@actual = actual
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# @private
|
|
46
|
-
def self.use_custom_matcher_or_delegate(operator)
|
|
47
|
-
define_method(operator) do |expected|
|
|
48
|
-
if !has_non_generic_implementation_of?(operator) && (matcher = OperatorMatcher.get(@actual.class, operator))
|
|
49
|
-
@actual.__send__(::RSpec::Matchers.last_expectation_handler.should_method, matcher.new(expected))
|
|
50
|
-
else
|
|
51
|
-
eval_match(@actual, operator, expected)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
negative_operator = operator.sub(/^=/, '!')
|
|
56
|
-
if negative_operator != operator && respond_to?(negative_operator)
|
|
57
|
-
define_method(negative_operator) do |_expected|
|
|
58
|
-
opposite_should = ::RSpec::Matchers.last_expectation_handler.opposite_should_method
|
|
59
|
-
raise "RSpec does not support `#{::RSpec::Matchers.last_expectation_handler.should_method} #{negative_operator} expected`. " \
|
|
60
|
-
"Use `#{opposite_should} #{operator} expected` instead."
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
['==', '===', '=~', '>', '>=', '<', '<='].each do |operator|
|
|
66
|
-
use_custom_matcher_or_delegate operator
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# @private
|
|
70
|
-
def fail_with_message(message)
|
|
71
|
-
RSpec::Expectations.fail_with(message, @expected, @actual)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# @api private
|
|
75
|
-
# @return [String]
|
|
76
|
-
def description
|
|
77
|
-
"#{@operator} #{RSpec::Support::ObjectFormatter.format(@expected)}"
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
private
|
|
81
|
-
|
|
82
|
-
def has_non_generic_implementation_of?(op)
|
|
83
|
-
Support.method_handle_for(@actual, op).owner != ::Kernel
|
|
84
|
-
rescue NameError
|
|
85
|
-
false
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def eval_match(actual, operator, expected)
|
|
89
|
-
::RSpec::Matchers.last_matcher = self
|
|
90
|
-
@operator, @expected = operator, expected
|
|
91
|
-
__delegate_operator(actual, operator, expected)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
# @private
|
|
96
|
-
# Handles operator matcher for `should`.
|
|
97
|
-
class PositiveOperatorMatcher < OperatorMatcher
|
|
98
|
-
def __delegate_operator(actual, operator, expected)
|
|
99
|
-
if actual.__send__(operator, expected)
|
|
100
|
-
true
|
|
101
|
-
else
|
|
102
|
-
expected_formatted = RSpec::Support::ObjectFormatter.format(expected)
|
|
103
|
-
actual_formatted = RSpec::Support::ObjectFormatter.format(actual)
|
|
104
|
-
|
|
105
|
-
if ['==', '===', '=~'].include?(operator)
|
|
106
|
-
fail_with_message("expected: #{expected_formatted}\n got: #{actual_formatted} (using #{operator})")
|
|
107
|
-
else
|
|
108
|
-
fail_with_message("expected: #{operator} #{expected_formatted}\n got: #{operator.gsub(/./, ' ')} #{actual_formatted}")
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
# @private
|
|
115
|
-
# Handles operator matcher for `should_not`.
|
|
116
|
-
class NegativeOperatorMatcher < OperatorMatcher
|
|
117
|
-
def __delegate_operator(actual, operator, expected)
|
|
118
|
-
return false unless actual.__send__(operator, expected)
|
|
119
|
-
|
|
120
|
-
expected_formatted = RSpec::Support::ObjectFormatter.format(expected)
|
|
121
|
-
actual_formatted = RSpec::Support::ObjectFormatter.format(actual)
|
|
122
|
-
|
|
123
|
-
fail_with_message("expected not: #{operator} #{expected_formatted}\n got: #{operator.gsub(/./, ' ')} #{actual_formatted}")
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
end
|