rspec-expectations 2.13.0 → 3.0.0
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 +15 -0
- checksums.yaml.gz.sig +0 -0
- data/Changelog.md +413 -23
- data/License.txt +1 -0
- data/README.md +109 -80
- data/lib/rspec/{matchers → expectations}/configuration.rb +44 -14
- data/lib/rspec/expectations/expectation_target.rb +71 -38
- data/lib/rspec/expectations/fail_with.rb +12 -44
- data/lib/rspec/expectations/handler.rb +135 -35
- data/lib/rspec/expectations/minitest_integration.rb +16 -0
- data/lib/rspec/expectations/syntax.rb +60 -94
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +46 -24
- data/lib/rspec/matchers/aliased_matcher.rb +41 -0
- data/lib/rspec/matchers/built_in/all.rb +78 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +63 -15
- data/lib/rspec/matchers/built_in/be.rb +170 -79
- data/lib/rspec/matchers/built_in/be_between.rb +77 -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 +40 -16
- data/lib/rspec/matchers/built_in/change.rb +275 -74
- data/lib/rspec/matchers/built_in/compound.rb +122 -0
- data/lib/rspec/matchers/built_in/contain_exactly.rb +256 -0
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +60 -6
- data/lib/rspec/matchers/built_in/eql.rb +17 -5
- data/lib/rspec/matchers/built_in/equal.rb +55 -21
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +71 -15
- data/lib/rspec/matchers/built_in/include.rb +58 -29
- data/lib/rspec/matchers/built_in/match.rb +19 -1
- data/lib/rspec/matchers/built_in/operators.rb +119 -0
- data/lib/rspec/matchers/built_in/output.rb +150 -0
- data/lib/rspec/matchers/built_in/raise_error.rb +91 -33
- data/lib/rspec/matchers/built_in/respond_to.rb +42 -20
- data/lib/rspec/matchers/built_in/satisfy.rb +19 -3
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +54 -18
- data/lib/rspec/matchers/built_in/throw_symbol.rb +38 -8
- data/lib/rspec/matchers/built_in/yield.rb +237 -55
- data/lib/rspec/matchers/built_in.rb +45 -33
- data/lib/rspec/matchers/composable.rb +179 -0
- data/lib/rspec/matchers/dsl.rb +362 -5
- data/lib/rspec/matchers/generated_descriptions.rb +13 -6
- data/lib/rspec/matchers/matcher_delegator.rb +37 -0
- data/lib/rspec/matchers/pretty.rb +33 -20
- data/lib/rspec/matchers.rb +450 -227
- data.tar.gz.sig +1 -0
- metadata +100 -215
- metadata.gz.sig +0 -0
- data/features/README.md +0 -49
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -90
- data/features/built_in_matchers/be.feature +0 -175
- data/features/built_in_matchers/be_within.feature +0 -48
- 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 -139
- 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/have.feature +0 -109
- data/features/built_in_matchers/include.feature +0 -174
- data/features/built_in_matchers/match.feature +0 -52
- data/features/built_in_matchers/operators.feature +0 -227
- data/features/built_in_matchers/predicates.feature +0 -137
- 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 -146
- 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 -368
- data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
- data/features/customized_message.feature +0 -22
- 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 -5
- data/features/syntax_configuration.feature +0 -68
- data/features/test_frameworks/test_unit.feature +0 -46
- data/lib/rspec/expectations/deprecation.rb +0 -38
- data/lib/rspec/expectations/differ.rb +0 -115
- data/lib/rspec/expectations/errors.rb +0 -9
- data/lib/rspec/expectations/extensions/array.rb +0 -9
- data/lib/rspec/expectations/extensions/object.rb +0 -39
- data/lib/rspec/expectations/extensions.rb +0 -2
- data/lib/rspec/matchers/be_close.rb +0 -9
- data/lib/rspec/matchers/built_in/have.rb +0 -108
- data/lib/rspec/matchers/built_in/match_array.rb +0 -51
- data/lib/rspec/matchers/compatibility.rb +0 -14
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
- data/lib/rspec/matchers/matcher.rb +0 -300
- data/lib/rspec/matchers/method_missing.rb +0 -12
- data/lib/rspec/matchers/operator_matcher.rb +0 -109
- data/lib/rspec-expectations.rb +0 -1
- data/spec/rspec/expectations/differ_spec.rb +0 -170
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -75
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -95
- data/spec/rspec/expectations/handler_spec.rb +0 -206
- data/spec/rspec/expectations/syntax_spec.rb +0 -97
- data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
- data/spec/rspec/matchers/be_close_spec.rb +0 -22
- data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
- data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
- data/spec/rspec/matchers/be_spec.rb +0 -516
- data/spec/rspec/matchers/be_within_spec.rb +0 -129
- data/spec/rspec/matchers/change_spec.rb +0 -542
- data/spec/rspec/matchers/configuration_spec.rb +0 -238
- data/spec/rspec/matchers/cover_spec.rb +0 -69
- data/spec/rspec/matchers/description_generation_spec.rb +0 -176
- data/spec/rspec/matchers/dsl_spec.rb +0 -57
- data/spec/rspec/matchers/eq_spec.rb +0 -60
- data/spec/rspec/matchers/eql_spec.rb +0 -41
- data/spec/rspec/matchers/equal_spec.rb +0 -78
- data/spec/rspec/matchers/exist_spec.rb +0 -124
- data/spec/rspec/matchers/has_spec.rb +0 -122
- data/spec/rspec/matchers/have_spec.rb +0 -445
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
- data/spec/rspec/matchers/include_spec.rb +0 -531
- data/spec/rspec/matchers/match_array_spec.rb +0 -194
- data/spec/rspec/matchers/match_spec.rb +0 -61
- data/spec/rspec/matchers/matcher_spec.rb +0 -471
- data/spec/rspec/matchers/matchers_spec.rb +0 -37
- data/spec/rspec/matchers/method_missing_spec.rb +0 -28
- data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
- data/spec/rspec/matchers/raise_error_spec.rb +0 -395
- data/spec/rspec/matchers/respond_to_spec.rb +0 -292
- data/spec/rspec/matchers/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
- data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
- data/spec/rspec/matchers/yield_spec.rb +0 -437
- data/spec/spec_helper.rb +0 -54
- data/spec/support/classes.rb +0 -56
- data/spec/support/in_sub_process.rb +0 -38
- data/spec/support/matchers.rb +0 -22
- data/spec/support/ruby_version.rb +0 -10
- data/spec/support/shared_examples.rb +0 -13
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Object, "#should" do
|
|
4
|
-
before(:each) do
|
|
5
|
-
@target = "target"
|
|
6
|
-
@matcher = mock("matcher")
|
|
7
|
-
@matcher.stub!(:matches?).and_return(true)
|
|
8
|
-
@matcher.stub!(:failure_message_for_should)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "accepts and interacts with a matcher" do
|
|
12
|
-
@matcher.should_receive(:matches?).with(@target).and_return(true)
|
|
13
|
-
expect(@target).to @matcher
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "asks for a failure_message_for_should when matches? returns false" do
|
|
17
|
-
@matcher.should_receive(:matches?).with(@target).and_return(false)
|
|
18
|
-
@matcher.should_receive(:failure_message_for_should).and_return("the failure message")
|
|
19
|
-
expect {
|
|
20
|
-
expect(@target).to @matcher
|
|
21
|
-
}.to fail_with("the failure message")
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
context "on interpretters that have BasicObject", :if => defined?(BasicObject) do
|
|
25
|
-
let(:proxy_class) do
|
|
26
|
-
Class.new(BasicObject) do
|
|
27
|
-
def initialize(target)
|
|
28
|
-
@target = target
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def proxied?
|
|
32
|
-
true
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def method_missing(name, *args)
|
|
36
|
-
@target.send(name, *args)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'works properly on BasicObject-subclassed proxy objects' do
|
|
42
|
-
expect(proxy_class.new(Object.new)).to be_proxied
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
describe Object, "#should_not" do
|
|
48
|
-
before(:each) do
|
|
49
|
-
@target = "target"
|
|
50
|
-
@matcher = mock("matcher")
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "accepts and interacts with a matcher" do
|
|
54
|
-
@matcher.should_receive(:matches?).with(@target).and_return(false)
|
|
55
|
-
@matcher.stub!(:failure_message_for_should_not)
|
|
56
|
-
|
|
57
|
-
expect(@target).not_to @matcher
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "asks for a failure_message_for_should_not when matches? returns true" do
|
|
61
|
-
@matcher.should_receive(:matches?).with(@target).and_return(true)
|
|
62
|
-
@matcher.should_receive(:failure_message_for_should_not).and_return("the failure message for should not")
|
|
63
|
-
expect {
|
|
64
|
-
expect(@target).not_to @matcher
|
|
65
|
-
}.to fail_with("the failure message for should not")
|
|
66
|
-
end
|
|
67
|
-
end
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require 'spec_helper'
|
|
3
|
-
|
|
4
|
-
describe RSpec::Expectations, "#fail_with with diff" do
|
|
5
|
-
let(:differ) { double("differ") }
|
|
6
|
-
|
|
7
|
-
before(:each) do
|
|
8
|
-
RSpec::Expectations.stub(:differ) { differ }
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "calls differ if expected/actual are not strings (or numbers or procs)" do
|
|
12
|
-
differ.should_receive(:diff_as_object).and_return("diff")
|
|
13
|
-
expect {
|
|
14
|
-
RSpec::Expectations.fail_with "the message", Object.new, Object.new
|
|
15
|
-
}.to fail_with("the message\nDiff:diff")
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context "with two strings" do
|
|
19
|
-
context "and actual is multiline" do
|
|
20
|
-
it "calls differ" do
|
|
21
|
-
differ.should_receive(:diff_as_string).and_return("diff")
|
|
22
|
-
expect {
|
|
23
|
-
RSpec::Expectations.fail_with "the message", "expected\nthis", "actual"
|
|
24
|
-
}.to fail_with("the message\nDiff:diff")
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context "and expected is multiline" do
|
|
29
|
-
it "calls differ" do
|
|
30
|
-
differ.should_receive(:diff_as_string).and_return("diff")
|
|
31
|
-
expect {
|
|
32
|
-
RSpec::Expectations.fail_with "the message", "expected", "actual\nthat"
|
|
33
|
-
}.to fail_with("the message\nDiff:diff")
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context "and both are single line strings" do
|
|
38
|
-
it "does not call differ" do
|
|
39
|
-
differ.should_not_receive(:diff_as_string)
|
|
40
|
-
expect {
|
|
41
|
-
RSpec::Expectations.fail_with("the message", "expected", "actual")
|
|
42
|
-
}.to fail_with("the message")
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context "and they are UTF-16LE encoded", :if => String.method_defined?(:encode) do
|
|
47
|
-
it 'does not diff when they are not multiline' do
|
|
48
|
-
differ.should_not_receive(:diff_as_string)
|
|
49
|
-
|
|
50
|
-
str_1 = "This is a pile of poo: 💩".encode("UTF-16LE")
|
|
51
|
-
str_2 = "This is a pile of poo: 💩".encode("UTF-16LE")
|
|
52
|
-
|
|
53
|
-
expect {
|
|
54
|
-
RSpec::Expectations.fail_with("the message", str_1, str_2)
|
|
55
|
-
}.to fail_with("the message")
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'diffs when they are multiline' do
|
|
59
|
-
differ.should_receive(:diff_as_string).and_return("diff")
|
|
60
|
-
|
|
61
|
-
str_1 = "This is a pile of poo:\n💩".encode("UTF-16LE")
|
|
62
|
-
str_2 = "This is a pile of poo:\n💩".encode("UTF-16LE")
|
|
63
|
-
|
|
64
|
-
expect {
|
|
65
|
-
RSpec::Expectations.fail_with("the message", str_1, str_2)
|
|
66
|
-
}.to fail_with("the message\nDiff:diff")
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "does not call differ if no expected/actual" do
|
|
72
|
-
expect {
|
|
73
|
-
RSpec::Expectations.fail_with "the message"
|
|
74
|
-
}.to fail_with("the message")
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "does not call differ expected is Numeric" do
|
|
78
|
-
expect {
|
|
79
|
-
RSpec::Expectations.fail_with "the message", 1, "1"
|
|
80
|
-
}.to fail_with("the message")
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "does not call differ when actual is Numeric" do
|
|
84
|
-
expect {
|
|
85
|
-
RSpec::Expectations.fail_with "the message", "1", 1
|
|
86
|
-
}.to fail_with("the message")
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it "does not call differ if expected or actual are procs" do
|
|
90
|
-
expect {
|
|
91
|
-
RSpec::Expectations.fail_with "the message", lambda {}, lambda {}
|
|
92
|
-
}.to fail_with("the message")
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module ExampleExpectations
|
|
4
|
-
|
|
5
|
-
class ArbitraryMatcher
|
|
6
|
-
def initialize(*args, &block)
|
|
7
|
-
if args.last.is_a? Hash
|
|
8
|
-
@expected = args.last[:expected]
|
|
9
|
-
end
|
|
10
|
-
@expected = block.call if block
|
|
11
|
-
@block = block
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def matches?(target)
|
|
15
|
-
@target = target
|
|
16
|
-
return @expected == target
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def with(new_value)
|
|
20
|
-
@expected = new_value
|
|
21
|
-
self
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def failure_message
|
|
25
|
-
"expected #{@expected}, got #{@target}"
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def negative_failure_message
|
|
29
|
-
"expected not #{@expected}, got #{@target}"
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
class PositiveOnlyMatcher < ArbitraryMatcher
|
|
34
|
-
undef negative_failure_message rescue nil
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def arbitrary_matcher(*args, &block)
|
|
38
|
-
ArbitraryMatcher.new(*args, &block)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def positive_only_matcher(*args, &block)
|
|
42
|
-
PositiveOnlyMatcher.new(*args, &block)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
module RSpec
|
|
48
|
-
module Expectations
|
|
49
|
-
describe PositiveExpectationHandler do
|
|
50
|
-
describe "#handle_matcher" do
|
|
51
|
-
it "asks the matcher if it matches" do
|
|
52
|
-
matcher = mock("matcher")
|
|
53
|
-
actual = Object.new
|
|
54
|
-
matcher.should_receive(:matches?).with(actual).and_return(true)
|
|
55
|
-
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "returns the match value" do
|
|
59
|
-
matcher = mock("matcher")
|
|
60
|
-
actual = Object.new
|
|
61
|
-
matcher.should_receive(:matches?).with(actual).and_return(:this_value)
|
|
62
|
-
expect(RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)).to eq :this_value
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "calls failure_message_for_should if the matcher implements it" do
|
|
66
|
-
matcher = mock("matcher", :failure_message_for_should => "message", :matches? => false)
|
|
67
|
-
actual = Object.new
|
|
68
|
-
|
|
69
|
-
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
|
70
|
-
|
|
71
|
-
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "calls fail if matcher.diffable?" do
|
|
75
|
-
matcher = mock("matcher",
|
|
76
|
-
:diffable? => true,
|
|
77
|
-
:failure_message_for_should => "message",
|
|
78
|
-
:matches? => false,
|
|
79
|
-
:expected => 1,
|
|
80
|
-
:actual => 2
|
|
81
|
-
)
|
|
82
|
-
actual = Object.new
|
|
83
|
-
|
|
84
|
-
::RSpec::Expectations.should_receive(:fail_with).with("message", 1, 2)
|
|
85
|
-
|
|
86
|
-
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it "calls failure_message if the matcher does not implement failure_message_for_should" do
|
|
90
|
-
matcher = mock("matcher", :failure_message => "message", :matches? => false)
|
|
91
|
-
actual = Object.new
|
|
92
|
-
|
|
93
|
-
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
|
94
|
-
|
|
95
|
-
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
|
|
96
|
-
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "appends the :or message in the options hash passed to should" do
|
|
100
|
-
matcher = mock("matcher", :failure_message_for_should => "message", :matches? => false)
|
|
101
|
-
actual = Object.new
|
|
102
|
-
|
|
103
|
-
::RSpec::Expectations.should_receive(:fail_with).with("custom")
|
|
104
|
-
|
|
105
|
-
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, "custom")
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
describe NegativeExpectationHandler do
|
|
111
|
-
describe "#handle_matcher" do
|
|
112
|
-
it "asks the matcher if it doesn't match when the matcher responds to #does_not_match?" do
|
|
113
|
-
matcher = mock("matcher", :does_not_match? => true, :negative_failure_message => nil)
|
|
114
|
-
actual = Object.new
|
|
115
|
-
matcher.should_receive(:does_not_match?).with(actual).and_return(true)
|
|
116
|
-
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "asks the matcher if it matches when the matcher doesn't respond to #does_not_match?" do
|
|
120
|
-
matcher = mock("matcher")
|
|
121
|
-
actual = Object.new
|
|
122
|
-
matcher.stub!(:negative_failure_message)
|
|
123
|
-
matcher.should_receive(:matches?).with(actual).and_return(false)
|
|
124
|
-
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
it "returns the match value" do
|
|
128
|
-
matcher = mock("matcher")
|
|
129
|
-
actual = Object.new
|
|
130
|
-
matcher.should_receive(:matches?).with(actual).and_return(false)
|
|
131
|
-
matcher.stub!(:negative_failure_message).and_return("ignore")
|
|
132
|
-
expect(RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)).to be_false
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
it "calls failure_message_for_should_not if the matcher implements it" do
|
|
137
|
-
matcher = mock("matcher", :failure_message_for_should_not => "message", :matches? => true)
|
|
138
|
-
actual = Object.new
|
|
139
|
-
|
|
140
|
-
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
|
141
|
-
|
|
142
|
-
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
|
143
|
-
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
it "calls negative_failure_message if the matcher does not implement failure_message_for_should_not" do
|
|
147
|
-
matcher = mock("matcher", :negative_failure_message => "message", :matches? => true)
|
|
148
|
-
actual = Object.new
|
|
149
|
-
|
|
150
|
-
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
|
151
|
-
|
|
152
|
-
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
|
153
|
-
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
it "calls fail if matcher.diffable?" do
|
|
158
|
-
matcher = mock("matcher",
|
|
159
|
-
:diffable? => true,
|
|
160
|
-
:failure_message_for_should_not => "message",
|
|
161
|
-
:matches? => true,
|
|
162
|
-
:expected => 1,
|
|
163
|
-
:actual => 2
|
|
164
|
-
)
|
|
165
|
-
actual = Object.new
|
|
166
|
-
|
|
167
|
-
::RSpec::Expectations.should_receive(:fail_with).with("message", 1, 2)
|
|
168
|
-
|
|
169
|
-
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
it "appends the :or message in the options hash passed to should" do
|
|
173
|
-
matcher = mock("matcher", :failure_message_for_should_not => "message", :matches? => true)
|
|
174
|
-
actual = Object.new
|
|
175
|
-
|
|
176
|
-
::RSpec::Expectations.should_receive(:fail_with).with("custom")
|
|
177
|
-
|
|
178
|
-
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, "custom")
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
describe PositiveExpectationHandler do
|
|
185
|
-
include ExampleExpectations
|
|
186
|
-
|
|
187
|
-
it "handles submitted args" do
|
|
188
|
-
expect(5).to arbitrary_matcher(:expected => 5)
|
|
189
|
-
expect(5).to arbitrary_matcher(:expected => "wrong").with(5)
|
|
190
|
-
expect { expect(5).to arbitrary_matcher(:expected => 4) }.to fail_with("expected 4, got 5")
|
|
191
|
-
expect { expect(5).to arbitrary_matcher(:expected => 5).with(4) }.to fail_with("expected 4, got 5")
|
|
192
|
-
expect(5).to_not arbitrary_matcher(:expected => 4)
|
|
193
|
-
expect(5).to_not arbitrary_matcher(:expected => 5).with(4)
|
|
194
|
-
expect { expect(5).to_not arbitrary_matcher(:expected => 5) }.to fail_with("expected not 5, got 5")
|
|
195
|
-
expect { expect(5).to_not arbitrary_matcher(:expected => 4).with(5) }.to fail_with("expected not 5, got 5")
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
it "handles the submitted block" do
|
|
199
|
-
expect(5).to arbitrary_matcher { 5 }
|
|
200
|
-
expect(5).to arbitrary_matcher(:expected => 4) { 5 }
|
|
201
|
-
expect(5).to arbitrary_matcher(:expected => 4).with(5) { 3 }
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
end
|
|
205
|
-
end
|
|
206
|
-
end
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module RSpec
|
|
4
|
-
module Expectations
|
|
5
|
-
describe Syntax do
|
|
6
|
-
context "when passing a message to an expectation" do
|
|
7
|
-
let(:warner) { ::Kernel }
|
|
8
|
-
|
|
9
|
-
describe "expect(...).to" do
|
|
10
|
-
it "prints a warning when the message object isn't a String" do
|
|
11
|
-
warner.should_receive(:warn).with /ignoring.*message/
|
|
12
|
-
expect(3).to eq(3), :not_a_string
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "doesn't print a warning when message is a String" do
|
|
16
|
-
warner.should_not_receive(:warn)
|
|
17
|
-
expect(3).to eq(3), "a string"
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "expect(...).to_not" do
|
|
22
|
-
it "prints a warning when the message object isn't a String" do
|
|
23
|
-
warner.should_receive(:warn).with /ignoring.*message/
|
|
24
|
-
expect(3).not_to eq(4), :not_a_string
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "doesn't print a warning when message is a String" do
|
|
28
|
-
warner.should_not_receive(:warn)
|
|
29
|
-
expect(3).not_to eq(4), "a string"
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
describe "expression generation" do
|
|
35
|
-
let(:target) { "foo" }
|
|
36
|
-
let(:expectation) { "eq('bar')" }
|
|
37
|
-
let(:positive_expect_example) { "expect(foo).to eq('bar')" }
|
|
38
|
-
let(:positive_should_example) { "foo.should eq('bar')" }
|
|
39
|
-
let(:negative_expect_example) { "expect(foo).not_to eq('bar')" }
|
|
40
|
-
let(:negative_should_example) { "foo.should_not eq('bar')" }
|
|
41
|
-
|
|
42
|
-
def positive_expression
|
|
43
|
-
Syntax.positive_expression(target, expectation)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def negative_expression
|
|
47
|
-
Syntax.negative_expression(target, expectation)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
context "when only :expect is enabled" do
|
|
51
|
-
before do
|
|
52
|
-
expect(Syntax.should_enabled?).to be_false
|
|
53
|
-
expect(Syntax.expect_enabled?).to be_true
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it 'generates a positive expression using the expect syntax' do
|
|
57
|
-
expect(positive_expression).to eq(positive_expect_example)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it 'generates a negative expression using the expect syntax' do
|
|
61
|
-
expect(negative_expression).to eq(negative_expect_example)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
context "when both :should and :expect are enabled", :uses_should do
|
|
66
|
-
before do
|
|
67
|
-
expect(Syntax.should_enabled?).to be_true
|
|
68
|
-
expect(Syntax.expect_enabled?).to be_true
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'generates a positive expression using the expect syntax' do
|
|
72
|
-
expect(positive_expression).to eq(positive_expect_example)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it 'generates a negative expression using the expect syntax' do
|
|
76
|
-
expect(negative_expression).to eq(negative_expect_example)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
context "when only :should is enabled", :uses_only_should do
|
|
81
|
-
before do
|
|
82
|
-
Syntax.should_enabled?.should be_true
|
|
83
|
-
Syntax.expect_enabled?.should be_false
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
it 'generates a positive expression using the expect syntax' do
|
|
87
|
-
positive_expression.should eq(positive_should_example)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it 'generates a negative expression using the expect syntax' do
|
|
91
|
-
negative_expression.should eq(negative_should_example)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module RSpec::Matchers::BuiltIn
|
|
4
|
-
describe BaseMatcher do
|
|
5
|
-
describe "#match_unless_raises" do
|
|
6
|
-
let(:matcher) do
|
|
7
|
-
Class.new(BaseMatcher).new
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "returns true if there are no errors" do
|
|
11
|
-
expect(matcher.match_unless_raises {}).to be_true
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "returns false if there is an error" do
|
|
15
|
-
expect(matcher.match_unless_raises { raise }).to be_false
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "returns false if the only submitted error is raised" do
|
|
19
|
-
expect(matcher.match_unless_raises(RuntimeError){ raise "foo" }).to be_false
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "returns false if any of several errors submitted is raised" do
|
|
23
|
-
expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise "foo" }).to be_false
|
|
24
|
-
expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise ArgumentError.new('') }).to be_false
|
|
25
|
-
expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise NameError.new('') }).to be_false
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "re-raises any error other than one of those specified" do
|
|
29
|
-
expect do
|
|
30
|
-
matcher.match_unless_raises(ArgumentError){ raise "foo" }
|
|
31
|
-
end.to raise_error
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "stores the rescued exception for use in messages" do
|
|
35
|
-
matcher.match_unless_raises(RuntimeError){ raise "foo" }
|
|
36
|
-
expect(matcher.rescued_exception).to be_a(RuntimeError)
|
|
37
|
-
expect(matcher.rescued_exception.message).to eq("foo")
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
describe "#==" do
|
|
43
|
-
it "responds the same way as matches?" do
|
|
44
|
-
matcher = Class.new(BaseMatcher) do
|
|
45
|
-
def initialize(expected)
|
|
46
|
-
@expected = expected
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def matches?(actual)
|
|
50
|
-
(@actual = actual) == @expected
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
expect(matcher.new(3).matches?(3)).to be_true
|
|
55
|
-
expect(matcher.new(3)).to eq(3)
|
|
56
|
-
|
|
57
|
-
expect(matcher.new(3).matches?(4)).to be_false
|
|
58
|
-
expect(matcher.new(3)).not_to eq(4)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module RSpec
|
|
4
|
-
module Matchers
|
|
5
|
-
describe "expect(actual).to be_close(expected, delta)" do
|
|
6
|
-
before(:each) do
|
|
7
|
-
RSpec.stub(:warn)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "delegates to be_within(delta).of(expected)" do
|
|
11
|
-
should_receive(:be_within).with(0.5).and_return( be_within_matcher = stub )
|
|
12
|
-
be_within_matcher.should_receive(:of).with(3.0)
|
|
13
|
-
be_close(3.0, 0.5)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "prints a deprecation warning" do
|
|
17
|
-
RSpec.should_receive(:warn).with(/please use be_within.*instead/)
|
|
18
|
-
be_close(3.0, 0.5)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module RSpec
|
|
4
|
-
module Matchers
|
|
5
|
-
[:be_an_instance_of, :be_instance_of].each do |method|
|
|
6
|
-
describe "expect(actual).to #{method}(expected)" do
|
|
7
|
-
it_behaves_like "an RSpec matcher", :valid_value => 5, :invalid_value => "a" do
|
|
8
|
-
let(:matcher) { send(method, Fixnum) }
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "passes if actual is instance of expected class" do
|
|
12
|
-
expect(5).to send(method, Fixnum)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "fails if actual is instance of subclass of expected class" do
|
|
16
|
-
expect {
|
|
17
|
-
expect(5).to send(method, Numeric)
|
|
18
|
-
}.to fail_with(%Q{expected 5 to be an instance of Numeric})
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "fails with failure message for should unless actual is instance of expected class" do
|
|
22
|
-
expect {
|
|
23
|
-
expect("foo").to send(method, Array)
|
|
24
|
-
}.to fail_with(%Q{expected "foo" to be an instance of Array})
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "provides a description" do
|
|
28
|
-
matcher = be_an_instance_of(Fixnum)
|
|
29
|
-
matcher.matches?(Numeric)
|
|
30
|
-
expect(matcher.description).to eq "be an instance of Fixnum"
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context "when expected provides an expanded inspect, e.g. AR::Base" do
|
|
34
|
-
let(:user_klass) do
|
|
35
|
-
Class.new do
|
|
36
|
-
def self.inspect
|
|
37
|
-
"User(id: integer, name: string)"
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
before { stub_const("User", user_klass) }
|
|
43
|
-
|
|
44
|
-
it "provides a description including only the class name" do
|
|
45
|
-
matcher = be_an_instance_of(User)
|
|
46
|
-
expect(matcher.description).to eq "be an instance of User"
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
describe "expect(actual).not_to #{method}(expected)" do
|
|
52
|
-
|
|
53
|
-
it "fails with failure message for should_not if actual is instance of expected class" do
|
|
54
|
-
expect {
|
|
55
|
-
expect("foo").not_to send(method, String)
|
|
56
|
-
}.to fail_with(%Q{expected "foo" not to be an instance of String})
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module RSpec
|
|
4
|
-
module Matchers
|
|
5
|
-
[:be_a_kind_of, :be_kind_of].each do |method|
|
|
6
|
-
describe "expect(actual).to #{method}(expected)" do
|
|
7
|
-
it_behaves_like "an RSpec matcher", :valid_value => 5, :invalid_value => "a" do
|
|
8
|
-
let(:matcher) { send(method, Fixnum) }
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "passes if actual is instance of expected class" do
|
|
12
|
-
expect(5).to send(method, Fixnum)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "passes if actual is instance of subclass of expected class" do
|
|
16
|
-
expect(5).to send(method, Numeric)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "fails with failure message for should unless actual is kind of expected class" do
|
|
20
|
-
expect {
|
|
21
|
-
expect("foo").to send(method, Array)
|
|
22
|
-
}.to fail_with(%Q{expected "foo" to be a kind of Array})
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "provides a description" do
|
|
26
|
-
matcher = be_a_kind_of(String)
|
|
27
|
-
matcher.matches?("this")
|
|
28
|
-
expect(matcher.description).to eq "be a kind of String"
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe "expect(actual).not_to #{method}(expected)" do
|
|
33
|
-
it "fails with failure message for should_not if actual is kind of expected class" do
|
|
34
|
-
expect {
|
|
35
|
-
expect("foo").not_to send(method, String)
|
|
36
|
-
}.to fail_with(%Q{expected "foo" not to be a kind of String})
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|