rspec-expectations 2.99.2 → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -0
- data/Changelog.md +63 -104
- data/License.txt +1 -0
- data/README.md +14 -8
- data/features/README.md +1 -2
- data/features/built_in_matchers/README.md +3 -0
- data/features/built_in_matchers/be.feature +44 -44
- data/features/built_in_matchers/be_within.feature +1 -1
- data/features/built_in_matchers/comparisons.feature +97 -0
- data/features/built_in_matchers/cover.feature +3 -3
- data/features/built_in_matchers/end_with.feature +3 -3
- data/features/built_in_matchers/equality.feature +20 -23
- data/features/built_in_matchers/exist.feature +5 -5
- data/features/built_in_matchers/expect_error.feature +14 -14
- data/features/built_in_matchers/include.feature +15 -15
- data/features/built_in_matchers/match.feature +4 -5
- data/features/built_in_matchers/match_array.feature +37 -0
- data/features/built_in_matchers/predicates.feature +30 -6
- data/features/built_in_matchers/respond_to.feature +4 -4
- data/features/built_in_matchers/satisfy.feature +2 -2
- data/features/built_in_matchers/start_with.feature +3 -3
- data/features/built_in_matchers/types.feature +6 -6
- data/features/custom_matchers/access_running_example.feature +3 -3
- data/features/custom_matchers/define_matcher.feature +6 -34
- data/features/custom_matchers/define_matcher_outside_rspec.feature +2 -2
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
- data/features/customized_message.feature +18 -1
- data/features/diffing.feature +3 -3
- data/features/implicit_docstrings.feature +9 -9
- data/features/step_definitions/additional_cli_steps.rb +0 -10
- data/features/support/env.rb +10 -3
- data/features/test_frameworks/test_unit.feature +0 -40
- data/lib/rspec-expectations.rb +0 -5
- data/lib/rspec/expectations.rb +4 -18
- data/lib/rspec/expectations/expectation_target.rb +10 -77
- data/lib/rspec/expectations/extensions.rb +0 -1
- data/lib/rspec/expectations/handler.rb +1 -5
- data/lib/rspec/expectations/syntax.rb +25 -5
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +7 -102
- data/lib/rspec/matchers/built_in/base_matcher.rb +10 -17
- data/lib/rspec/matchers/built_in/be.rb +5 -18
- data/lib/rspec/matchers/built_in/be_within.rb +2 -8
- data/lib/rspec/matchers/built_in/change.rb +1 -39
- data/lib/rspec/matchers/built_in/has.rb +7 -40
- data/lib/rspec/matchers/built_in/include.rb +1 -1
- data/lib/rspec/matchers/built_in/match_array.rb +1 -1
- data/lib/rspec/matchers/built_in/raise_error.rb +44 -23
- data/lib/rspec/matchers/built_in/respond_to.rb +1 -7
- data/lib/rspec/matchers/built_in/satisfy.rb +1 -7
- data/lib/rspec/matchers/built_in/throw_symbol.rb +2 -10
- data/lib/rspec/matchers/built_in/yield.rb +4 -25
- data/lib/rspec/matchers/compatibility.rb +2 -2
- data/lib/rspec/{expectations → matchers}/configuration.rb +9 -6
- data/lib/rspec/matchers/dsl.rb +2 -4
- data/lib/rspec/matchers/matcher.rb +163 -283
- data/lib/rspec/matchers/operator_matcher.rb +57 -71
- data/lib/rspec/matchers/pretty.rb +0 -4
- data/lib/rspec/matchers/test_unit_integration.rb +5 -22
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -62
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -4
- data/spec/rspec/expectations_spec.rb +2 -43
- data/spec/rspec/matchers/base_matcher_spec.rb +12 -27
- data/spec/rspec/matchers/be_spec.rb +2 -71
- data/spec/rspec/matchers/change_spec.rb +1 -76
- data/spec/rspec/{expectations → matchers}/configuration_spec.rb +41 -21
- data/spec/rspec/matchers/description_generation_spec.rb +2 -21
- data/spec/rspec/matchers/equal_spec.rb +0 -26
- data/spec/rspec/matchers/has_spec.rb +0 -24
- data/spec/rspec/matchers/match_array_spec.rb +0 -13
- data/spec/rspec/matchers/matcher_spec.rb +325 -279
- data/spec/rspec/matchers/matchers_spec.rb +36 -0
- data/spec/rspec/matchers/operator_matcher_spec.rb +8 -27
- data/spec/rspec/matchers/raise_error_spec.rb +65 -209
- data/spec/rspec/matchers/yield_spec.rb +32 -9
- data/spec/spec_helper.rb +21 -6
- data/spec/support/classes.rb +7 -7
- data/spec/support/in_sub_process.rb +7 -8
- data/spec/support/shared_examples.rb +0 -42
- metadata +113 -84
- metadata.gz.sig +4 -0
- data/features/built_in_matchers/have.feature +0 -109
- data/features/built_in_matchers/operators.feature +0 -227
- data/lib/rspec/expectations/caller_filter.rb +0 -60
- data/lib/rspec/expectations/deprecation.rb +0 -27
- data/lib/rspec/expectations/extensions/array.rb +0 -9
- data/lib/rspec/matchers/be_close.rb +0 -12
- data/lib/rspec/matchers/built_in/have.rb +0 -273
- data/lib/rspec/matchers/differentiate_block_method_types.rb +0 -55
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
- data/lib/rspec/matchers/match_aliases.rb +0 -22
- data/spec/rspec/matchers/be_close_spec.rb +0 -25
- data/spec/rspec/matchers/differentiate_block_method_types_spec.rb +0 -39
- data/spec/rspec/matchers/have_spec.rb +0 -853
- data/spec/rspec/matchers/pretty_spec.rb +0 -23
- data/spec/support/helper_methods.rb +0 -42
@@ -20,13 +20,3 @@ Then /^the example should fail$/ do
|
|
20
20
|
step %q{the output should contain "1 failure"}
|
21
21
|
step %q{the exit status should not be 0}
|
22
22
|
end
|
23
|
-
|
24
|
-
deprecation_message = /rspec-expectations' built-in integration with (Test::Unit|minitest < 5.x) is deprecated/
|
25
|
-
|
26
|
-
Then /^the output should contain a deprecation warning about rspec\-expecations' built\-in integration$/ do
|
27
|
-
expect(all_output).to match(deprecation_message)
|
28
|
-
end
|
29
|
-
|
30
|
-
Then /^the output should not contain a deprecation warning about rspec\-expecations' built\-in integration$/ do
|
31
|
-
expect(all_output).not_to match(deprecation_message)
|
32
|
-
end
|
data/features/support/env.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'aruba/cucumber'
|
2
2
|
|
3
|
-
timeouts = { 'java' => 60 }
|
4
|
-
|
5
3
|
Before do
|
6
|
-
|
4
|
+
if RUBY_PLATFORM =~ /java/ || defined?(Rubinius)
|
5
|
+
@aruba_timeout_seconds = 60
|
6
|
+
else
|
7
|
+
@aruba_timeout_seconds = 10
|
8
|
+
end
|
7
9
|
end
|
8
10
|
|
9
11
|
Aruba.configure do |config|
|
@@ -12,3 +14,8 @@ Aruba.configure do |config|
|
|
12
14
|
end
|
13
15
|
end if RUBY_PLATFORM == 'java'
|
14
16
|
|
17
|
+
Aruba.configure do |config|
|
18
|
+
config.before_cmd do |cmd|
|
19
|
+
set_env('RBXOPT', "-Xint=true #{ENV['RBXOPT']}") # disable JIT since these processes are so short lived
|
20
|
+
end
|
21
|
+
end if defined?(Rubinius)
|
@@ -42,43 +42,3 @@ Feature: Test::Unit integration
|
|
42
42
|
Then the output should contain "3 tests, 0 assertions, 0 failures, 1 errors" or "3 tests, 0 assertions, 1 failures, 0 errors"
|
43
43
|
And the output should contain "expected empty? to return true, got false"
|
44
44
|
And the output should contain "be_an_int is deprecated"
|
45
|
-
And the output should contain a deprecation warning about rspec-expecations' built-in integration
|
46
|
-
|
47
|
-
Scenario: use rspec/expectations with Test::Unit
|
48
|
-
Given a file named "rspec_expectations_with_manual_integration_test.rb" with:
|
49
|
-
"""
|
50
|
-
require 'test/unit'
|
51
|
-
require "rspec/expectations"
|
52
|
-
|
53
|
-
class RSpecExpectationsTest < Test::Unit::TestCase
|
54
|
-
include ::RSpec::Matchers
|
55
|
-
|
56
|
-
RSpec::Matchers.define :be_an_integer do
|
57
|
-
match { |actual| Integer === actual }
|
58
|
-
end
|
59
|
-
|
60
|
-
def be_an_int
|
61
|
-
# This is actually an internal rspec-expectations API, but is used
|
62
|
-
# here to demonstrate that deprecation warnings from within
|
63
|
-
# rspec-expectations work correcty without depending on rspec-core
|
64
|
-
RSpec.deprecate(:be_an_int, :replacement => :be_an_integer)
|
65
|
-
be_an_integer
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_passing_expectation
|
69
|
-
expect(1 + 3).to eq 4
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_failing_expectation
|
73
|
-
expect([1,2]).to be_empty
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_custom_matcher_with_deprecation_warning
|
77
|
-
expect(1).to be_an_int
|
78
|
-
end
|
79
|
-
end
|
80
|
-
"""
|
81
|
-
When I run `ruby rspec_expectations_with_manual_integration_test.rb`
|
82
|
-
Then the output should contain "3 tests, 0 assertions, 0 failures, 1 errors" or "3 tests, 0 assertions, 1 failures, 0 errors"
|
83
|
-
And the output should not contain a deprecation warning about rspec-expecations' built-in integration
|
84
|
-
|
data/lib/rspec-expectations.rb
CHANGED
data/lib/rspec/expectations.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
require 'rspec/support/caller_filter'
|
2
|
+
require 'rspec/support/warnings'
|
3
|
+
|
1
4
|
require 'rspec/expectations/extensions'
|
2
5
|
require 'rspec/matchers'
|
3
6
|
require 'rspec/expectations/expectation_target'
|
4
|
-
require 'rspec/
|
7
|
+
require 'rspec/matchers/configuration'
|
5
8
|
require 'rspec/expectations/fail_with'
|
6
9
|
require 'rspec/expectations/errors'
|
7
|
-
require 'rspec/expectations/deprecation'
|
8
10
|
require 'rspec/expectations/handler'
|
9
11
|
require 'rspec/expectations/version'
|
10
12
|
require 'rspec/expectations/differ'
|
@@ -59,14 +61,6 @@ module RSpec
|
|
59
61
|
if RUBY_VERSION.to_i >= 2
|
60
62
|
def self.method_handle_for(object, method_name)
|
61
63
|
KERNEL_METHOD_METHOD.bind(object).call(method_name)
|
62
|
-
rescue NameError => original
|
63
|
-
begin
|
64
|
-
handle = object.method(method_name)
|
65
|
-
raise original unless handle.is_a? Method
|
66
|
-
handle
|
67
|
-
rescue Exception
|
68
|
-
raise original
|
69
|
-
end
|
70
64
|
end
|
71
65
|
else
|
72
66
|
def self.method_handle_for(object, method_name)
|
@@ -75,14 +69,6 @@ module RSpec
|
|
75
69
|
else
|
76
70
|
object.method(method_name)
|
77
71
|
end
|
78
|
-
rescue NameError => original
|
79
|
-
begin
|
80
|
-
handle = object.method(method_name)
|
81
|
-
raise original unless handle.is_a? Method
|
82
|
-
handle
|
83
|
-
rescue Exception
|
84
|
-
raise original
|
85
|
-
end
|
86
72
|
end
|
87
73
|
end
|
88
74
|
end
|
@@ -1,48 +1,23 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Expectations
|
3
3
|
# Wraps the target of an expectation.
|
4
|
-
#
|
5
4
|
# @example
|
6
|
-
# expect(something)
|
7
|
-
# expect { do_something } # => ExpectationTarget wrapping the block
|
5
|
+
# expect(something) # => ExpectationTarget wrapping something
|
8
6
|
#
|
9
7
|
# # used with `to`
|
10
8
|
# expect(actual).to eq(3)
|
11
9
|
#
|
12
10
|
# # with `not_to`
|
13
11
|
# expect(actual).not_to eq(3)
|
14
|
-
#
|
15
|
-
# @note `ExpectationTarget` is not intended to be instantiated
|
16
|
-
# directly by users. Use `expect` instead.
|
17
12
|
class ExpectationTarget
|
18
13
|
class << self
|
19
14
|
attr_accessor :deprecated_should_enabled
|
20
15
|
alias deprecated_should_enabled? deprecated_should_enabled
|
21
16
|
end
|
22
17
|
|
23
|
-
# @private
|
24
|
-
# Used as a sentinel value to be able to tell when the user
|
25
|
-
# did not pass an argument. We can't use `nil` for that because
|
26
|
-
# `nil` is a valid value to pass.
|
27
|
-
UndefinedValue = Module.new
|
28
|
-
|
29
18
|
# @api private
|
30
|
-
def initialize(
|
31
|
-
@target =
|
32
|
-
end
|
33
|
-
|
34
|
-
# @private
|
35
|
-
def self.for(value, block)
|
36
|
-
if UndefinedValue.equal?(value)
|
37
|
-
unless block
|
38
|
-
raise ArgumentError, "You must pass either an argument or a block to `expect`."
|
39
|
-
end
|
40
|
-
BlockExpectationTarget.new(block)
|
41
|
-
elsif block
|
42
|
-
raise ArgumentError, "You cannot pass both an argument and a block to `expect`."
|
43
|
-
else
|
44
|
-
new(value)
|
45
|
-
end
|
19
|
+
def initialize(target)
|
20
|
+
@target = target
|
46
21
|
end
|
47
22
|
|
48
23
|
# Runs the given expectation, passing if `matcher` returns true.
|
@@ -51,11 +26,11 @@ module RSpec
|
|
51
26
|
# expect { perform }.to raise_error
|
52
27
|
# @param [Matcher]
|
53
28
|
# matcher
|
54
|
-
# @param [String] message optional message to display when the expectation fails
|
29
|
+
# @param [String or Proc] message optional message to display when the expectation fails
|
55
30
|
# @return [Boolean] true if the expectation succeeds (else raises)
|
56
31
|
# @see RSpec::Matchers
|
57
32
|
def to(matcher=nil, message=nil, &block)
|
58
|
-
prevent_operator_matchers(:to
|
33
|
+
prevent_operator_matchers(:to, matcher)
|
59
34
|
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(@target, matcher, message, &block)
|
60
35
|
end
|
61
36
|
|
@@ -64,11 +39,11 @@ module RSpec
|
|
64
39
|
# expect(value).not_to eq(5)
|
65
40
|
# @param [Matcher]
|
66
41
|
# matcher
|
67
|
-
# @param [String] message optional message to display when the expectation fails
|
42
|
+
# @param [String or Proc] message optional message to display when the expectation fails
|
68
43
|
# @return [Boolean] false if the negative expectation succeeds (else raises)
|
69
44
|
# @see RSpec::Matchers
|
70
45
|
def not_to(matcher=nil, message=nil, &block)
|
71
|
-
prevent_operator_matchers(:not_to
|
46
|
+
prevent_operator_matchers(:not_to, matcher)
|
72
47
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(@target, matcher, message, &block)
|
73
48
|
end
|
74
49
|
alias to_not not_to
|
@@ -100,55 +75,13 @@ module RSpec
|
|
100
75
|
|
101
76
|
private
|
102
77
|
|
103
|
-
def prevent_operator_matchers(verb)
|
78
|
+
def prevent_operator_matchers(verb, matcher)
|
79
|
+
return if matcher
|
80
|
+
|
104
81
|
raise ArgumentError, "The expect syntax does not support operator matchers, " +
|
105
82
|
"so you must pass a matcher to `##{verb}`."
|
106
83
|
end
|
107
84
|
end
|
108
|
-
|
109
|
-
# @private
|
110
|
-
# Validates the provided matcher to ensure it supports block
|
111
|
-
# expectations, in order to avoid user confusion when they
|
112
|
-
# use a block thinking the expectation will be on the return
|
113
|
-
# value of the block rather than the block itself.
|
114
|
-
class BlockExpectationTarget < ExpectationTarget
|
115
|
-
def to(matcher, message=nil, &block)
|
116
|
-
enforce_block_expectation(matcher)
|
117
|
-
super
|
118
|
-
end
|
119
|
-
|
120
|
-
def not_to(matcher, message=nil, &block)
|
121
|
-
enforce_block_expectation(matcher)
|
122
|
-
super
|
123
|
-
end
|
124
|
-
alias to_not not_to
|
125
|
-
|
126
|
-
private
|
127
|
-
|
128
|
-
def enforce_block_expectation(matcher)
|
129
|
-
return if supports_block_expectations?(matcher)
|
130
|
-
|
131
|
-
RSpec.deprecate("Using a matcher in a block expectation expression " +
|
132
|
-
"(e.g. `expect { }.to matcher`) that does not implement " +
|
133
|
-
"`supports_block_expectations?`",
|
134
|
-
:replacement => "a value expectation expression " +
|
135
|
-
"(e.g. `expect(value).to matcher`) or implement " +
|
136
|
-
"`supports_block_expectations?` on the provided matcher " +
|
137
|
-
"(#{description_of matcher})")
|
138
|
-
end
|
139
|
-
|
140
|
-
def supports_block_expectations?(matcher)
|
141
|
-
matcher.supports_block_expectations?
|
142
|
-
rescue NoMethodError
|
143
|
-
false
|
144
|
-
end
|
145
|
-
|
146
|
-
def description_of(matcher)
|
147
|
-
matcher.description
|
148
|
-
rescue NoMethodError
|
149
|
-
matcher.inspect
|
150
|
-
end
|
151
|
-
end
|
152
85
|
end
|
153
86
|
end
|
154
87
|
|
@@ -31,11 +31,7 @@ module RSpec
|
|
31
31
|
matcher.failure_message
|
32
32
|
|
33
33
|
if matcher.respond_to?(:diffable?) && matcher.diffable?
|
34
|
-
|
35
|
-
::RSpec::Expectations.fail_with message, matcher.expected_as_array, matcher.actual
|
36
|
-
else
|
37
|
-
::RSpec::Expectations.fail_with message, matcher.expected, matcher.actual
|
38
|
-
end
|
34
|
+
::RSpec::Expectations.fail_with message, matcher.expected, matcher.actual
|
39
35
|
else
|
40
36
|
::RSpec::Expectations.fail_with message
|
41
37
|
end
|
@@ -43,17 +43,35 @@ module RSpec
|
|
43
43
|
@default_should_host ||= ::Object.ancestors.last
|
44
44
|
end
|
45
45
|
|
46
|
+
def self.warn_about_should!
|
47
|
+
@warn_about_should = true
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.warn_about_should_unless_configured(method_name)
|
51
|
+
if @warn_about_should
|
52
|
+
RSpec.deprecate(
|
53
|
+
"Using `#{method_name}` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax",
|
54
|
+
:replacement => "the new `:expect` syntax or explicitly enable `:should`"
|
55
|
+
)
|
56
|
+
|
57
|
+
@warn_about_should = false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
46
61
|
# @api private
|
47
62
|
# Enables the `should` syntax.
|
48
63
|
def enable_should(syntax_host = default_should_host)
|
64
|
+
@warn_about_should = false
|
49
65
|
return if should_enabled?(syntax_host)
|
50
66
|
|
51
|
-
syntax_host.
|
67
|
+
syntax_host.module_exec do
|
52
68
|
def should(matcher=nil, message=nil, &block)
|
69
|
+
::RSpec::Expectations::Syntax.warn_about_should_unless_configured(__method__)
|
53
70
|
::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block)
|
54
71
|
end
|
55
72
|
|
56
73
|
def should_not(matcher=nil, message=nil, &block)
|
74
|
+
::RSpec::Expectations::Syntax.warn_about_should_unless_configured(__method__)
|
57
75
|
::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
|
58
76
|
end
|
59
77
|
end
|
@@ -66,7 +84,7 @@ module RSpec
|
|
66
84
|
def disable_should(syntax_host = default_should_host)
|
67
85
|
return unless should_enabled?(syntax_host)
|
68
86
|
|
69
|
-
syntax_host.
|
87
|
+
syntax_host.module_exec do
|
70
88
|
undef should
|
71
89
|
undef should_not
|
72
90
|
end
|
@@ -80,8 +98,10 @@ module RSpec
|
|
80
98
|
return if expect_enabled?(syntax_host)
|
81
99
|
|
82
100
|
syntax_host.module_exec do
|
83
|
-
def expect(
|
84
|
-
|
101
|
+
def expect(*target, &target_block)
|
102
|
+
target << target_block if block_given?
|
103
|
+
raise ArgumentError.new("You must pass an argument or a block to #expect but not both.") unless target.size == 1
|
104
|
+
::RSpec::Expectations::ExpectationTarget.new(target.first)
|
85
105
|
end
|
86
106
|
end
|
87
107
|
|
@@ -93,7 +113,7 @@ module RSpec
|
|
93
113
|
def disable_expect(syntax_host = ::RSpec::Matchers)
|
94
114
|
return unless expect_enabled?(syntax_host)
|
95
115
|
|
96
|
-
syntax_host.
|
116
|
+
syntax_host.module_exec do
|
97
117
|
undef expect
|
98
118
|
end
|
99
119
|
|
data/lib/rspec/matchers.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
require 'rspec/matchers/extensions/instance_eval_with_args'
|
2
1
|
require 'rspec/matchers/pretty'
|
3
2
|
|
4
|
-
require 'rspec/matchers/match_aliases'
|
5
3
|
require 'rspec/matchers/built_in'
|
6
4
|
require 'rspec/matchers/matcher'
|
7
5
|
require 'rspec/matchers/operator_matcher'
|
8
|
-
require 'rspec/matchers/be_close'
|
9
6
|
|
10
7
|
require 'rspec/matchers/generated_descriptions'
|
11
8
|
require 'rspec/matchers/method_missing'
|
@@ -25,7 +22,6 @@ module RSpec
|
|
25
22
|
# does_not_match?(actual)
|
26
23
|
# failure_message_for_should_not
|
27
24
|
# description
|
28
|
-
# supports_block_expectations?
|
29
25
|
#
|
30
26
|
# ## Predicates
|
31
27
|
#
|
@@ -185,22 +181,6 @@ module RSpec
|
|
185
181
|
obj.respond_to?(:failure_message_for_should) || obj.respond_to?(:failure_message)
|
186
182
|
end
|
187
183
|
|
188
|
-
def be_true
|
189
|
-
RSpec.deprecate("`be_true`", :replacement =>
|
190
|
-
"`be_truthy` (for Ruby's conditional semantics) or " +
|
191
|
-
"`be true` (for exact `== true` equality)"
|
192
|
-
)
|
193
|
-
BuiltIn::BeTruthy.new
|
194
|
-
end
|
195
|
-
|
196
|
-
def be_false
|
197
|
-
RSpec.deprecate("`be_false`", :replacement =>
|
198
|
-
"`be_falsey` (for Ruby's conditional semantics) or " +
|
199
|
-
"`be false` (for exact `== false` equality)"
|
200
|
-
)
|
201
|
-
BuiltIn::BeFalsey.new
|
202
|
-
end
|
203
|
-
|
204
184
|
# Passes if actual is truthy (anything but false or nil)
|
205
185
|
def be_truthy
|
206
186
|
BuiltIn::BeTruthy.new
|
@@ -433,63 +413,6 @@ module RSpec
|
|
433
413
|
BuiltIn::Exist.new(*args)
|
434
414
|
end
|
435
415
|
|
436
|
-
# Passes if receiver is a collection with the submitted number of items OR
|
437
|
-
# if the receiver OWNS a collection with the submitted number of items.
|
438
|
-
#
|
439
|
-
# If the receiver OWNS the collection, you must use the name of the
|
440
|
-
# collection. So if a `Team` instance has a collection named `#players`,
|
441
|
-
# you must use that name to set the expectation.
|
442
|
-
#
|
443
|
-
# If the receiver IS the collection, you can use any name you like for
|
444
|
-
# `named_collection`. We'd recommend using either "elements", "members", or
|
445
|
-
# "items" as these are all standard ways of describing the things IN a
|
446
|
-
# collection.
|
447
|
-
#
|
448
|
-
# This also works for Strings, letting you set expectations about their
|
449
|
-
# lengths.
|
450
|
-
#
|
451
|
-
# @example
|
452
|
-
#
|
453
|
-
# # Passes if team.players.size == 11
|
454
|
-
# expect(team).to have(11).players
|
455
|
-
#
|
456
|
-
# # Passes if [1,2,3].length == 3
|
457
|
-
# expect([1,2,3]).to have(3).items #"items" is pure sugar
|
458
|
-
#
|
459
|
-
# # Passes if ['a', 'b', 'c'].count == 3
|
460
|
-
# expect([1,2,3]).to have(3).items #"items" is pure sugar
|
461
|
-
#
|
462
|
-
# # Passes if "this string".length == 11
|
463
|
-
# expect("this string").to have(11).characters #"characters" is pure sugar
|
464
|
-
def have(n)
|
465
|
-
BuiltIn::Have.new(n)
|
466
|
-
end
|
467
|
-
alias :have_exactly :have
|
468
|
-
|
469
|
-
# Exactly like have() with >=.
|
470
|
-
#
|
471
|
-
# @example
|
472
|
-
# expect("this").to have_at_least(3).letters
|
473
|
-
#
|
474
|
-
# ### Warning:
|
475
|
-
#
|
476
|
-
# `expect(..).not_to have_at_least` is not supported
|
477
|
-
def have_at_least(n)
|
478
|
-
BuiltIn::Have.new(n, :at_least)
|
479
|
-
end
|
480
|
-
|
481
|
-
# Exactly like have() with <=.
|
482
|
-
#
|
483
|
-
# @example
|
484
|
-
# expect("this").to have_at_most(4).letters
|
485
|
-
#
|
486
|
-
# ### Warning:
|
487
|
-
#
|
488
|
-
# `expect(..).not_to have_at_most` is not supported
|
489
|
-
def have_at_most(n)
|
490
|
-
BuiltIn::Have.new(n, :at_most)
|
491
|
-
end
|
492
|
-
|
493
416
|
# Passes if actual includes expected. This works for
|
494
417
|
# collections and Strings. You can also pass in multiple args
|
495
418
|
# and it will only pass if all args are found in collection.
|
@@ -510,20 +433,16 @@ module RSpec
|
|
510
433
|
#
|
511
434
|
# @example
|
512
435
|
#
|
513
|
-
# expect(email).to
|
514
|
-
# expect(email).to
|
515
|
-
# expect(zipcode).to match_regex(/\A\d{5}(-\d{4})?\z/)
|
516
|
-
# expect(zipcode).to match_regex("90210")
|
436
|
+
# expect(email).to match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
|
437
|
+
# expect(email).to match("@example.com")
|
517
438
|
#
|
518
|
-
# @note
|
519
|
-
#
|
520
|
-
# (
|
521
|
-
#
|
522
|
-
# `#match_regex` method.
|
439
|
+
# @note The `match_regex` alias is deprecated and is not recommended for use.
|
440
|
+
# It was added in 2.12.1 to facilitate its use from within custom
|
441
|
+
# matchers (due to how the custom matcher DSL was evaluated in 2.x,
|
442
|
+
# `match` could not be used there), but is no longer needed in 3.x.
|
523
443
|
def match(expected)
|
524
444
|
BuiltIn::Match.new(expected)
|
525
445
|
end
|
526
|
-
|
527
446
|
alias_method :match_regex, :match
|
528
447
|
|
529
448
|
# With no args, matches if any error is raised.
|
@@ -709,20 +628,6 @@ module RSpec
|
|
709
628
|
BuiltIn::MatchArray.new(array)
|
710
629
|
end
|
711
630
|
|
712
|
-
|
713
|
-
|
714
|
-
def self.const_missing(name)
|
715
|
-
case name
|
716
|
-
when :OperatorMatcher
|
717
|
-
RSpec.deprecate("`RSpec::Matchers::OperatorMatcher`",
|
718
|
-
:replacement => "`RSpec::Matchers::BuiltIn::OperatorMatcher`")
|
719
|
-
BuiltIn::OperatorMatcher
|
720
|
-
when :Configuration
|
721
|
-
RSpec.deprecate("`RSpec::Matchers::Configuration`",
|
722
|
-
:replacement => "`RSpec::Expectations::Configuration`")
|
723
|
-
Expectations::Configuration
|
724
|
-
else super
|
725
|
-
end
|
726
|
-
end
|
631
|
+
OperatorMatcher.register(Enumerable, '=~', BuiltIn::MatchArray)
|
727
632
|
end
|
728
633
|
end
|