rspec-expectations 3.0.0.beta2 → 3.0.0.rc1
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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -2
- data/.yardopts +0 -1
- data/Changelog.md +115 -35
- data/README.md +2 -2
- data/lib/rspec/expectations.rb +13 -8
- data/lib/rspec/{matchers → expectations}/configuration.rb +38 -13
- data/lib/rspec/expectations/expectation_target.rb +72 -8
- data/lib/rspec/expectations/fail_with.rb +10 -52
- data/lib/rspec/expectations/handler.rb +9 -11
- data/lib/rspec/expectations/syntax.rb +37 -35
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +60 -9
- data/lib/rspec/matchers/aliased_matcher.rb +6 -0
- data/lib/rspec/matchers/built_in.rb +9 -1
- data/lib/rspec/matchers/built_in/all.rb +78 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +39 -1
- data/lib/rspec/matchers/built_in/be.rb +117 -42
- data/lib/rspec/matchers/built_in/be_between.rb +22 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
- data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
- data/lib/rspec/matchers/built_in/be_within.rb +26 -6
- data/lib/rspec/matchers/built_in/change.rb +89 -13
- data/lib/rspec/matchers/built_in/compound.rb +19 -3
- data/lib/rspec/matchers/built_in/contain_exactly.rb +17 -6
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +20 -5
- data/lib/rspec/matchers/built_in/eql.rb +15 -3
- data/lib/rspec/matchers/built_in/equal.rb +23 -6
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +58 -3
- data/lib/rspec/matchers/built_in/include.rb +16 -1
- data/lib/rspec/matchers/built_in/match.rb +14 -4
- data/lib/rspec/matchers/built_in/operators.rb +16 -0
- data/lib/rspec/matchers/built_in/output.rb +47 -5
- data/lib/rspec/matchers/built_in/raise_error.rb +40 -23
- data/lib/rspec/matchers/built_in/respond_to.rb +37 -16
- data/lib/rspec/matchers/built_in/satisfy.rb +15 -0
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +29 -14
- data/lib/rspec/matchers/built_in/throw_symbol.rb +32 -3
- data/lib/rspec/matchers/built_in/yield.rb +148 -44
- data/lib/rspec/matchers/composable.rb +48 -7
- data/lib/rspec/matchers/dsl.rb +45 -17
- data/lib/rspec/matchers/generated_descriptions.rb +7 -0
- data/lib/rspec/matchers/matcher_delegator.rb +6 -2
- data/lib/rspec/matchers/pretty.rb +15 -19
- metadata +33 -236
- metadata.gz.sig +0 -0
- data/features/README.md +0 -48
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -96
- data/features/built_in_matchers/be.feature +0 -175
- data/features/built_in_matchers/be_within.feature +0 -48
- data/features/built_in_matchers/comparisons.feature +0 -97
- data/features/built_in_matchers/contain_exactly.feature +0 -46
- data/features/built_in_matchers/cover.feature +0 -47
- data/features/built_in_matchers/end_with.feature +0 -48
- data/features/built_in_matchers/equality.feature +0 -136
- data/features/built_in_matchers/exist.feature +0 -45
- data/features/built_in_matchers/expect_change.feature +0 -59
- data/features/built_in_matchers/expect_error.feature +0 -144
- data/features/built_in_matchers/include.feature +0 -126
- data/features/built_in_matchers/match.feature +0 -51
- data/features/built_in_matchers/output.feature +0 -70
- data/features/built_in_matchers/predicates.feature +0 -161
- data/features/built_in_matchers/respond_to.feature +0 -84
- data/features/built_in_matchers/satisfy.feature +0 -33
- data/features/built_in_matchers/start_with.feature +0 -48
- data/features/built_in_matchers/throw_symbol.feature +0 -91
- data/features/built_in_matchers/types.feature +0 -116
- data/features/built_in_matchers/yield.feature +0 -161
- data/features/composing_matchers.feature +0 -250
- data/features/compound_expectations.feature +0 -45
- data/features/custom_matchers/access_running_example.feature +0 -53
- data/features/custom_matchers/define_diffable_matcher.feature +0 -27
- data/features/custom_matchers/define_matcher.feature +0 -340
- data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -34
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
- data/features/customized_message.feature +0 -39
- data/features/diffing.feature +0 -85
- data/features/implicit_docstrings.feature +0 -52
- data/features/step_definitions/additional_cli_steps.rb +0 -22
- data/features/support/env.rb +0 -21
- data/features/support/rubinius.rb +0 -6
- data/features/syntax_configuration.feature +0 -71
- data/features/test_frameworks/minitest.feature +0 -44
- data/lib/rspec-expectations.rb +0 -1
- data/lib/rspec/expectations/diff_presenter.rb +0 -141
- data/lib/rspec/expectations/differ.rb +0 -44
- data/lib/rspec/expectations/encoded_string.rb +0 -56
- data/spec/rspec/expectations/diff_presenter_spec.rb +0 -249
- data/spec/rspec/expectations/encoded_string_spec.rb +0 -74
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -114
- data/spec/rspec/expectations/handler_spec.rb +0 -205
- data/spec/rspec/expectations/minitest_integration_spec.rb +0 -27
- data/spec/rspec/expectations/syntax_spec.rb +0 -89
- data/spec/rspec/expectations_spec.rb +0 -12
- data/spec/rspec/matchers/aliased_matcher_spec.rb +0 -48
- data/spec/rspec/matchers/aliases_spec.rb +0 -449
- data/spec/rspec/matchers/built_in/base_matcher_spec.rb +0 -83
- data/spec/rspec/matchers/built_in/be_between_spec.rb +0 -159
- data/spec/rspec/matchers/built_in/be_instance_of_spec.rb +0 -63
- data/spec/rspec/matchers/built_in/be_kind_of_spec.rb +0 -41
- data/spec/rspec/matchers/built_in/be_spec.rb +0 -592
- data/spec/rspec/matchers/built_in/be_within_spec.rb +0 -141
- data/spec/rspec/matchers/built_in/change_spec.rb +0 -808
- data/spec/rspec/matchers/built_in/compound_spec.rb +0 -292
- data/spec/rspec/matchers/built_in/contain_exactly_spec.rb +0 -441
- data/spec/rspec/matchers/built_in/cover_spec.rb +0 -69
- data/spec/rspec/matchers/built_in/eq_spec.rb +0 -156
- data/spec/rspec/matchers/built_in/eql_spec.rb +0 -41
- data/spec/rspec/matchers/built_in/equal_spec.rb +0 -106
- data/spec/rspec/matchers/built_in/exist_spec.rb +0 -124
- data/spec/rspec/matchers/built_in/has_spec.rb +0 -161
- data/spec/rspec/matchers/built_in/include_spec.rb +0 -540
- data/spec/rspec/matchers/built_in/match_spec.rb +0 -102
- data/spec/rspec/matchers/built_in/operators_spec.rb +0 -252
- data/spec/rspec/matchers/built_in/output_spec.rb +0 -165
- data/spec/rspec/matchers/built_in/raise_error_spec.rb +0 -461
- data/spec/rspec/matchers/built_in/respond_to_spec.rb +0 -292
- data/spec/rspec/matchers/built_in/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/built_in/start_and_end_with_spec.rb +0 -253
- data/spec/rspec/matchers/built_in/throw_symbol_spec.rb +0 -135
- data/spec/rspec/matchers/built_in/yield_spec.rb +0 -627
- data/spec/rspec/matchers/configuration_spec.rb +0 -213
- data/spec/rspec/matchers/description_generation_spec.rb +0 -191
- data/spec/rspec/matchers/dsl_spec.rb +0 -895
- data/spec/rspec/matchers/legacy_spec.rb +0 -101
- data/spec/rspec/matchers_spec.rb +0 -74
- data/spec/spec_helper.rb +0 -85
- data/spec/support/matchers.rb +0 -22
- data/spec/support/shared_examples.rb +0 -35
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Matchers
|
5
|
-
describe "Legacy matchers" do
|
6
|
-
shared_examples_for "a matcher written against a legacy protocol" do |matcher_class|
|
7
|
-
matcher = matcher_class.new
|
8
|
-
before { allow_deprecation }
|
9
|
-
|
10
|
-
backwards_compat_matcher = Class.new(matcher_class) do
|
11
|
-
def failure_message; "failure when positive"; end
|
12
|
-
def failure_message_when_negated; "failure when negative"; end
|
13
|
-
end.new
|
14
|
-
|
15
|
-
it 'is still considered to be a matcher' do
|
16
|
-
expect(Matchers.is_a_matcher?(matcher)).to be true
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'when matched positively' do
|
20
|
-
it 'returns the positive expectation failure message' do
|
21
|
-
expect {
|
22
|
-
expect(false).to matcher
|
23
|
-
}.to fail_with("failure when positive")
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'warns about the deprecated protocol' do
|
27
|
-
expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 1, /legacy\s+RSpec\s+matcher/)
|
28
|
-
expect(true).to matcher
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'does not warn when it also defines the current methods (i.e. to be compatible on multiple RSpec versions)' do
|
32
|
-
expect_no_deprecations
|
33
|
-
|
34
|
-
expect {
|
35
|
-
expect(false).to backwards_compat_matcher
|
36
|
-
}.to fail_with("failure when positive")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'when matched negatively' do
|
41
|
-
it 'returns the negative expectation failure message' do
|
42
|
-
expect {
|
43
|
-
expect(true).not_to matcher
|
44
|
-
}.to fail_with("failure when negative")
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'warns about the deprecated protocol' do
|
48
|
-
expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 1, /legacy\s+RSpec\s+matcher/)
|
49
|
-
expect(false).not_to matcher
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'does not warn when it also defines the current methods (i.e. to be compatible on multiple RSpec versions)' do
|
53
|
-
expect_no_deprecations
|
54
|
-
|
55
|
-
expect {
|
56
|
-
expect(true).not_to backwards_compat_matcher
|
57
|
-
}.to fail_with("failure when negative")
|
58
|
-
end
|
59
|
-
|
60
|
-
def pending_on_rbx
|
61
|
-
return unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
62
|
-
pending "intermittently fails on RBX due to https://github.com/rubinius/rubinius/issues/2845"
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'calls `does_not_match?` if it is defined on the matcher' do
|
66
|
-
pending_on_rbx
|
67
|
-
|
68
|
-
called = false
|
69
|
-
with_does_not_match = Class.new(matcher_class) do
|
70
|
-
define_method(:does_not_match?) { |actual| called = true; !actual }
|
71
|
-
end.new
|
72
|
-
|
73
|
-
expect(false).not_to with_does_not_match
|
74
|
-
expect(called).to be true
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context "written using the RSpec 2.x `failure_message_for_should` and `failure_message_for_should_not` protocol" do
|
80
|
-
matcher_class = Class.new do
|
81
|
-
def matches?(actual); actual; end
|
82
|
-
def failure_message_for_should; "failure when positive"; end
|
83
|
-
def failure_message_for_should_not; "failure when negative"; end
|
84
|
-
end
|
85
|
-
|
86
|
-
it_behaves_like "a matcher written against a legacy protocol", matcher_class
|
87
|
-
end
|
88
|
-
|
89
|
-
context "written using the older `failure_message` and `negative_failure_message` protocol" do
|
90
|
-
matcher_class = Class.new do
|
91
|
-
def matches?(actual); actual; end
|
92
|
-
def failure_message; "failure when positive"; end
|
93
|
-
def negative_failure_message; "failure when negative"; end
|
94
|
-
end
|
95
|
-
|
96
|
-
it_behaves_like "a matcher written against a legacy protocol", matcher_class
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
data/spec/rspec/matchers_spec.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
main = self
|
4
|
-
describe RSpec::Matchers do
|
5
|
-
include ::RSpec::Support::InSubProcess
|
6
|
-
|
7
|
-
it 'can be mixed into `main`' do
|
8
|
-
in_sub_process do
|
9
|
-
main.instance_eval do
|
10
|
-
include RSpec::Matchers
|
11
|
-
expect(3).to eq(3)
|
12
|
-
expect(3).to be_odd
|
13
|
-
|
14
|
-
expect {
|
15
|
-
expect(4).to be_zero
|
16
|
-
}.to fail_with("expected zero? to return true, got false")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module RSpec
|
23
|
-
module Matchers
|
24
|
-
describe "built in matchers" do
|
25
|
-
let(:matchers) do
|
26
|
-
BuiltIn.constants.map { |n| BuiltIn.const_get(n) }.select do |m|
|
27
|
-
m.method_defined?(:matches?) && m.method_defined?(:failure_message)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
specify "they all have defined #=== so they can be composable" do
|
32
|
-
missing_threequals = matchers.select do |m|
|
33
|
-
m.instance_method(:===).owner == ::Kernel
|
34
|
-
end
|
35
|
-
|
36
|
-
# This spec is merely to make sure we don't forget to make
|
37
|
-
# a built-in matcher implement `===`. It doesn't check the
|
38
|
-
# semantics of that. Use the "an RSpec matcher" shared
|
39
|
-
# example group to actually check the semantics.
|
40
|
-
expect(missing_threequals).to eq([])
|
41
|
-
end
|
42
|
-
|
43
|
-
specify "they all have defined #and and #or so they support compound expectations" do
|
44
|
-
noncompound_matchers = matchers.reject do |m|
|
45
|
-
m.method_defined?(:and) || m.method_defined?(:or)
|
46
|
-
end
|
47
|
-
|
48
|
-
expect(noncompound_matchers).to eq([])
|
49
|
-
end
|
50
|
-
|
51
|
-
shared_examples_for "a well-behaved method_missing hook" do
|
52
|
-
include MinitestIntegration
|
53
|
-
|
54
|
-
it "raises a NoMethodError (and not SystemStackError) for an undefined method" do
|
55
|
-
with_minitest_loaded do
|
56
|
-
expect { subject.some_undefined_method }.to raise_error(NoMethodError)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "RSpec::Matchers method_missing hook" do
|
62
|
-
subject { self }
|
63
|
-
|
64
|
-
it_behaves_like "a well-behaved method_missing hook"
|
65
|
-
|
66
|
-
context 'when invoked in a Minitest::Test' do
|
67
|
-
subject { Minitest::Test.allocate }
|
68
|
-
it_behaves_like "a well-behaved method_missing hook"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
data/spec/spec_helper.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'rspec/support/spec'
|
2
|
-
|
3
|
-
RSpec::Support::Spec.setup_simplecov do
|
4
|
-
minimum_coverage 97
|
5
|
-
end
|
6
|
-
|
7
|
-
Dir['./spec/support/**/*'].each {|f| require f}
|
8
|
-
|
9
|
-
module FormattingSupport
|
10
|
-
def dedent(string)
|
11
|
-
string.gsub(/^\s+\|/, '').chomp
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
RSpec::configure do |config|
|
16
|
-
config.color_enabled = true
|
17
|
-
config.order = :random
|
18
|
-
|
19
|
-
config.include FormattingSupport
|
20
|
-
|
21
|
-
config.expect_with :rspec do |expectations|
|
22
|
-
$default_expectation_syntax = expectations.syntax
|
23
|
-
expectations.syntax = :expect
|
24
|
-
end
|
25
|
-
|
26
|
-
config.mock_with :rspec do |mocks|
|
27
|
-
mocks.syntax = :expect
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
shared_context "with #should enabled", :uses_should do
|
32
|
-
orig_syntax = nil
|
33
|
-
|
34
|
-
before(:all) do
|
35
|
-
orig_syntax = RSpec::Matchers.configuration.syntax
|
36
|
-
RSpec::Matchers.configuration.syntax = [:expect, :should]
|
37
|
-
end
|
38
|
-
|
39
|
-
after(:all) do
|
40
|
-
RSpec::Matchers.configuration.syntax = orig_syntax
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
shared_context "with the default expectation syntax" do
|
45
|
-
orig_syntax = nil
|
46
|
-
|
47
|
-
before(:all) do
|
48
|
-
orig_syntax = RSpec::Matchers.configuration.syntax
|
49
|
-
RSpec::Matchers.configuration.reset_syntaxes_to_default
|
50
|
-
end
|
51
|
-
|
52
|
-
after(:all) do
|
53
|
-
RSpec::Matchers.configuration.syntax = orig_syntax
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
shared_context "with #should exclusively enabled", :uses_only_should do
|
59
|
-
orig_syntax = nil
|
60
|
-
|
61
|
-
before(:all) do
|
62
|
-
orig_syntax = RSpec::Matchers.configuration.syntax
|
63
|
-
RSpec::Matchers.configuration.syntax = :should
|
64
|
-
end
|
65
|
-
|
66
|
-
after(:all) do
|
67
|
-
RSpec::Matchers.configuration.syntax = orig_syntax
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
require 'rspec/support/spec/in_sub_process'
|
72
|
-
module MinitestIntegration
|
73
|
-
include ::RSpec::Support::InSubProcess
|
74
|
-
|
75
|
-
def with_minitest_loaded
|
76
|
-
in_sub_process do
|
77
|
-
with_isolated_stderr do
|
78
|
-
require 'minitest/autorun'
|
79
|
-
end
|
80
|
-
|
81
|
-
require 'rspec/expectations/minitest_integration'
|
82
|
-
yield
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
data/spec/support/matchers.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
RSpec::Matchers.define :include_method do |expected|
|
2
|
-
match do |actual|
|
3
|
-
actual.map { |m| m.to_s }.include?(expected.to_s)
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
module RSpec
|
8
|
-
module Matchers
|
9
|
-
def fail
|
10
|
-
raise_error(RSpec::Expectations::ExpectationNotMetError)
|
11
|
-
end
|
12
|
-
|
13
|
-
def fail_with(message)
|
14
|
-
raise_error(RSpec::Expectations::ExpectationNotMetError, message)
|
15
|
-
end
|
16
|
-
|
17
|
-
def fail_matching(message)
|
18
|
-
raise_error(RSpec::Expectations::ExpectationNotMetError, /#{Regexp.escape(message)}/)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
@@ -1,35 +0,0 @@
|
|
1
|
-
shared_examples_for "an RSpec matcher" do |options|
|
2
|
-
let(:valid_value) { options.fetch(:valid_value) }
|
3
|
-
let(:invalid_value) { options.fetch(:invalid_value) }
|
4
|
-
|
5
|
-
it 'preserves the symmetric property of `==`' do
|
6
|
-
expect(matcher).to eq(matcher)
|
7
|
-
expect(matcher).not_to eq(valid_value)
|
8
|
-
expect(valid_value).not_to eq(matcher)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'matches a valid value when using #=== so it can be composed' do
|
12
|
-
expect(matcher).to be === valid_value
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'does not match an invalid value when using #=== so it can be composed' do
|
16
|
-
expect(matcher).not_to be === invalid_value
|
17
|
-
end
|
18
|
-
|
19
|
-
matcher :always_passes do
|
20
|
-
match { true }
|
21
|
-
end
|
22
|
-
|
23
|
-
matcher :always_fails do
|
24
|
-
match { false }
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'supports compound expectations by chaining `and`' do
|
28
|
-
expect(valid_value).to matcher.and always_passes
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'supports compound expectations by chaining `or`' do
|
32
|
-
expect(valid_value).to matcher.or always_fails
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|