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,83 +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_truthy
|
12
|
-
end
|
13
|
-
|
14
|
-
it "returns false if there is an error" do
|
15
|
-
expect(matcher.match_unless_raises { raise }).to be_falsey
|
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_falsey
|
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_falsey
|
24
|
-
expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise ArgumentError.new('') }).to be_falsey
|
25
|
-
expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise NameError.new('') }).to be_falsey
|
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 "#failure_message" do
|
43
|
-
context "when the parameter to .new is omitted" do
|
44
|
-
it "describes what was expected" do
|
45
|
-
matcher_class = Class.new(BaseMatcher) do
|
46
|
-
def name=(name)
|
47
|
-
@name = name
|
48
|
-
end
|
49
|
-
|
50
|
-
def match(expected, actual)
|
51
|
-
false
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
matcher = matcher_class.new
|
56
|
-
matcher.name = "be something"
|
57
|
-
matcher.matches?("foo")
|
58
|
-
expect(matcher.failure_message).to eq('expected "foo" to be something')
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "#===" do
|
64
|
-
it "responds the same way as matches?" do
|
65
|
-
matcher = Class.new(BaseMatcher) do
|
66
|
-
def initialize(expected)
|
67
|
-
@expected = expected
|
68
|
-
end
|
69
|
-
|
70
|
-
def matches?(actual)
|
71
|
-
(@actual = actual) == @expected
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
expect(matcher.new(3).matches?(3)).to be_truthy
|
76
|
-
expect(matcher.new(3)).to be === 3
|
77
|
-
|
78
|
-
expect(matcher.new(3).matches?(4)).to be_falsey
|
79
|
-
expect(matcher.new(3)).not_to be === 4
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,159 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec::Matchers::BuiltIn
|
4
|
-
describe BeBetween do
|
5
|
-
class SizeMatters
|
6
|
-
include Comparable
|
7
|
-
attr :str
|
8
|
-
def <=>(other)
|
9
|
-
str.size <=> other.str.size
|
10
|
-
end
|
11
|
-
def initialize(str)
|
12
|
-
@str = str
|
13
|
-
end
|
14
|
-
def inspect
|
15
|
-
@str
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
shared_examples_for "be_between" do |mode|
|
20
|
-
it "passes if target is between min and max" do
|
21
|
-
expect(5).to matcher(1, 10)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "fails if target is not between min and max" do
|
25
|
-
expect {
|
26
|
-
# It does not go to 11
|
27
|
-
expect(11).to matcher(1, 10)
|
28
|
-
}.to fail_with("expected 11 to be between 1 and 10 (#{mode})")
|
29
|
-
end
|
30
|
-
|
31
|
-
it "works with strings" do
|
32
|
-
expect("baz").to matcher("bar", "foo")
|
33
|
-
|
34
|
-
expect {
|
35
|
-
expect("foo").to matcher("bar", "baz")
|
36
|
-
}.to fail_with("expected \"foo\" to be between \"bar\" and \"baz\" (#{mode})")
|
37
|
-
end
|
38
|
-
|
39
|
-
it "works with other Comparable objects" do
|
40
|
-
expect(SizeMatters.new("--")).to matcher(SizeMatters.new("-"), SizeMatters.new("---"))
|
41
|
-
|
42
|
-
expect {
|
43
|
-
expect(SizeMatters.new("---")).to matcher(SizeMatters.new("-"), SizeMatters.new("--"))
|
44
|
-
}.to fail_with("expected --- to be between - and -- (#{mode})")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
shared_examples_for "not_to be_between" do |mode|
|
49
|
-
it "passes if target is not between min and max" do
|
50
|
-
expect(11).not_to matcher(1, 10)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "fails if target is between min and max" do
|
54
|
-
expect {
|
55
|
-
expect(5).not_to matcher(1, 10)
|
56
|
-
}.to fail_with("expected 5 not to be between 1 and 10 (#{mode})")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
shared_examples_for "composing with other matchers" do |mode|
|
61
|
-
it "passes when the matchers both match" do
|
62
|
-
expect([nil, 3]).to include(matcher(2, 4), a_nil_value)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "works with mixed types" do
|
66
|
-
expect(["baz", Math::PI]).to include(matcher(3.1, 3.2), matcher("bar", "foo"))
|
67
|
-
|
68
|
-
expect {
|
69
|
-
expect(["baz", 2.14]).to include(matcher(3.1, 3.2), matcher("bar", "foo") )
|
70
|
-
}.to fail_with("expected [\"baz\", 2.14] to include (a value between 3.1 and 3.2 (#{mode})) and (a value between \"bar\" and \"foo\" (#{mode}))")
|
71
|
-
end
|
72
|
-
|
73
|
-
it "provides a description" do
|
74
|
-
description = include(matcher(2, 4), an_instance_of(Float)).description
|
75
|
-
expect(description).to eq("include (a value between 2 and 4 (#{mode})) and (an instance of Float)")
|
76
|
-
end
|
77
|
-
|
78
|
-
it "fails with a clear error message when the matchers do not match" do
|
79
|
-
expect {
|
80
|
-
expect([nil, 1]).to include(matcher(2, 4), a_nil_value)
|
81
|
-
}.to fail_with("expected [nil, 1] to include (a value between 2 and 4 (#{mode})) and (a nil value)")
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
it_behaves_like "an RSpec matcher", :valid_value => (10), :invalid_value => (11) do
|
86
|
-
let(:matcher) { be_between(1, 10) }
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "expect(...).to be_between(min, max) (inclusive)" do
|
90
|
-
it_behaves_like "be_between", :inclusive do
|
91
|
-
def matcher(min, max)
|
92
|
-
be_between(min, max)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
it "is inclusive" do
|
97
|
-
expect(1).to be_between(1, 10)
|
98
|
-
expect(10).to be_between(1, 10)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "indicates it was not comparable if it does not respond to `<=` and `>=`" do
|
102
|
-
expect {
|
103
|
-
expect(nil).to be_between(0, 10)
|
104
|
-
}.to fail_with("expected nil to be between 0 and 10 (inclusive), but it does not respond to `<=` and `>=`")
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "expect(...).to be_between(min, max) (exclusive)" do
|
109
|
-
it_behaves_like "be_between", :exclusive do
|
110
|
-
def matcher(min, max)
|
111
|
-
be_between(min, max).exclusive
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it "indicates it was not comparable if it does not respond to `<` and `>`" do
|
116
|
-
expect {
|
117
|
-
expect(nil).to be_between(0, 10).exclusive
|
118
|
-
}.to fail_with("expected nil to be between 0 and 10 (exclusive), but it does not respond to `<` and `>`")
|
119
|
-
end
|
120
|
-
|
121
|
-
it "is exclusive" do
|
122
|
-
expect { expect(1).to be_between(1, 10).exclusive }.to fail
|
123
|
-
expect { expect(10).to be_between(1, 10).exclusive }.to fail
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "expect(...).not_to be_between(min, max) (inclusive)" do
|
128
|
-
it_behaves_like "not_to be_between", :inclusive do
|
129
|
-
def matcher(min, max)
|
130
|
-
be_between(min, max)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "expect(...).not_to be_between(min, max) (exclusive)" do
|
136
|
-
it_behaves_like "not_to be_between", :exclusive do
|
137
|
-
def matcher(min, max)
|
138
|
-
be_between(min, max).exclusive
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "composing with other matchers (inclusive)" do
|
144
|
-
it_behaves_like "composing with other matchers", :inclusive do
|
145
|
-
def matcher(min, max)
|
146
|
-
a_value_between(min, max)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "composing with other matchers (exclusive)" do
|
152
|
-
it_behaves_like "composing with other matchers", :exclusive do
|
153
|
-
def matcher(min, max)
|
154
|
-
a_value_between(min, max).exclusive
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
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
|
@@ -1,592 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "expect(...).to be_predicate" do
|
4
|
-
it "passes when actual returns true for :predicate?" do
|
5
|
-
actual = double("actual", :happy? => true)
|
6
|
-
expect(actual).to be_happy
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'allows composable aliases to be defined' do
|
10
|
-
RSpec::Matchers.alias_matcher :a_user_who_is_happy, :be_happy
|
11
|
-
actual = double("actual", :happy? => true)
|
12
|
-
expect(actual).to a_user_who_is_happy
|
13
|
-
expect(a_user_who_is_happy.description).to eq("a user who is happy")
|
14
|
-
|
15
|
-
RSpec::Matchers.alias_matcher :a_user_who_is_an_admin, :be_an_admin
|
16
|
-
actual = double("actual", :admin? => true)
|
17
|
-
expect(actual).to a_user_who_is_an_admin
|
18
|
-
expect(a_user_who_is_an_admin.description).to eq("a user who is an admin")
|
19
|
-
|
20
|
-
RSpec::Matchers.alias_matcher :an_animal_that_is_a_canine, :be_a_canine
|
21
|
-
actual = double("actual", :canine? => true)
|
22
|
-
expect(actual).to an_animal_that_is_a_canine
|
23
|
-
expect(an_animal_that_is_a_canine.description).to eq("an animal that is a canine")
|
24
|
-
end
|
25
|
-
|
26
|
-
it "passes when actual returns true for :predicates? (present tense)" do
|
27
|
-
actual = double("actual", :exists? => true, :exist? => true)
|
28
|
-
expect(actual).to be_exist
|
29
|
-
end
|
30
|
-
|
31
|
-
it "fails when actual returns false for :predicate?" do
|
32
|
-
actual = double("actual", :happy? => false)
|
33
|
-
expect {
|
34
|
-
expect(actual).to be_happy
|
35
|
-
}.to fail_with("expected happy? to return true, got false")
|
36
|
-
end
|
37
|
-
|
38
|
-
it "fails when actual returns false for :predicate?" do
|
39
|
-
actual = double("actual", :happy? => nil)
|
40
|
-
expect {
|
41
|
-
expect(actual).to be_happy
|
42
|
-
}.to fail_with("expected happy? to return true, got nil")
|
43
|
-
end
|
44
|
-
|
45
|
-
it "fails when actual does not respond to :predicate?" do
|
46
|
-
expect {
|
47
|
-
expect(Object.new).to be_happy
|
48
|
-
}.to raise_error(NameError, /happy\?/)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'fails when :predicate? is private' do
|
52
|
-
privately_happy = Class.new do
|
53
|
-
private
|
54
|
-
def happy?
|
55
|
-
true
|
56
|
-
end
|
57
|
-
end
|
58
|
-
expect { expect(privately_happy.new).to be_happy }.to raise_error
|
59
|
-
end
|
60
|
-
|
61
|
-
it "fails on error other than NameError" do
|
62
|
-
actual = double("actual")
|
63
|
-
expect(actual).to receive(:foo?).and_raise("aaaah")
|
64
|
-
expect {
|
65
|
-
expect(actual).to be_foo
|
66
|
-
}.to raise_error(/aaaah/)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "fails on error other than NameError (with the present tense predicate)" do
|
70
|
-
actual = Object.new
|
71
|
-
expect(actual).to receive(:foos?).and_raise("aaaah")
|
72
|
-
expect {
|
73
|
-
expect(actual).to be_foo
|
74
|
-
}.to raise_error(/aaaah/)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "does not support operator chaining like a basic `be` matcher does" do
|
78
|
-
matcher = be_happy
|
79
|
-
value = double(:happy? => false)
|
80
|
-
expect(matcher == value).to be false
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "expect(...).not_to be_predicate" do
|
85
|
-
it "passes when actual returns false for :sym?" do
|
86
|
-
actual = double("actual", :happy? => false)
|
87
|
-
expect(actual).not_to be_happy
|
88
|
-
end
|
89
|
-
|
90
|
-
it "passes when actual returns nil for :sym?" do
|
91
|
-
actual = double("actual", :happy? => nil)
|
92
|
-
expect(actual).not_to be_happy
|
93
|
-
end
|
94
|
-
|
95
|
-
it "fails when actual returns true for :sym?" do
|
96
|
-
actual = double("actual", :happy? => true)
|
97
|
-
expect {
|
98
|
-
expect(actual).not_to be_happy
|
99
|
-
}.to fail_with("expected happy? to return false, got true")
|
100
|
-
end
|
101
|
-
|
102
|
-
it "fails when actual does not respond to :sym?" do
|
103
|
-
expect {
|
104
|
-
expect(Object.new).not_to be_happy
|
105
|
-
}.to raise_error(NameError)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "expect(...).to be_predicate(*args)" do
|
110
|
-
it "passes when actual returns true for :predicate?(*args)" do
|
111
|
-
actual = double("actual")
|
112
|
-
expect(actual).to receive(:older_than?).with(3).and_return(true)
|
113
|
-
expect(actual).to be_older_than(3)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "fails when actual returns false for :predicate?(*args)" do
|
117
|
-
actual = double("actual")
|
118
|
-
expect(actual).to receive(:older_than?).with(3).and_return(false)
|
119
|
-
expect {
|
120
|
-
expect(actual).to be_older_than(3)
|
121
|
-
}.to fail_with("expected older_than?(3) to return true, got false")
|
122
|
-
end
|
123
|
-
|
124
|
-
it "fails when actual does not respond to :predicate?" do
|
125
|
-
expect {
|
126
|
-
expect(Object.new).to be_older_than(3)
|
127
|
-
}.to raise_error(NameError)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "expect(...).not_to be_predicate(*args)" do
|
132
|
-
it "passes when actual returns false for :predicate?(*args)" do
|
133
|
-
actual = double("actual")
|
134
|
-
expect(actual).to receive(:older_than?).with(3).and_return(false)
|
135
|
-
expect(actual).not_to be_older_than(3)
|
136
|
-
end
|
137
|
-
|
138
|
-
it "fails when actual returns true for :predicate?(*args)" do
|
139
|
-
actual = double("actual")
|
140
|
-
expect(actual).to receive(:older_than?).with(3).and_return(true)
|
141
|
-
expect {
|
142
|
-
expect(actual).not_to be_older_than(3)
|
143
|
-
}.to fail_with("expected older_than?(3) to return false, got true")
|
144
|
-
end
|
145
|
-
|
146
|
-
it "fails when actual does not respond to :predicate?" do
|
147
|
-
expect {
|
148
|
-
expect(Object.new).not_to be_older_than(3)
|
149
|
-
}.to raise_error(NameError)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe "expect(...).to be_predicate(&block)" do
|
154
|
-
it "passes when actual returns true for :predicate?(&block)" do
|
155
|
-
actual = double("actual")
|
156
|
-
delegate = double("delegate")
|
157
|
-
expect(actual).to receive(:happy?).and_yield
|
158
|
-
expect(delegate).to receive(:check_happy).and_return(true)
|
159
|
-
expect(actual).to be_happy { delegate.check_happy }
|
160
|
-
end
|
161
|
-
|
162
|
-
it "fails when actual returns false for :predicate?(&block)" do
|
163
|
-
actual = double("actual")
|
164
|
-
delegate = double("delegate")
|
165
|
-
expect(actual).to receive(:happy?).and_yield
|
166
|
-
expect(delegate).to receive(:check_happy).and_return(false)
|
167
|
-
expect {
|
168
|
-
expect(actual).to be_happy { delegate.check_happy }
|
169
|
-
}.to fail_with("expected happy? to return true, got false")
|
170
|
-
end
|
171
|
-
|
172
|
-
it "fails when actual does not respond to :predicate?" do
|
173
|
-
delegate = double("delegate", :check_happy => true)
|
174
|
-
expect {
|
175
|
-
expect(Object.new).to be_happy { delegate.check_happy }
|
176
|
-
}.to raise_error(NameError)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
describe "expect(...).not_to be_predicate(&block)" do
|
181
|
-
it "passes when actual returns false for :predicate?(&block)" do
|
182
|
-
actual = double("actual")
|
183
|
-
delegate = double("delegate")
|
184
|
-
expect(actual).to receive(:happy?).and_yield
|
185
|
-
expect(delegate).to receive(:check_happy).and_return(false)
|
186
|
-
expect(actual).not_to be_happy { delegate.check_happy }
|
187
|
-
end
|
188
|
-
|
189
|
-
it "fails when actual returns true for :predicate?(&block)" do
|
190
|
-
actual = double("actual")
|
191
|
-
delegate = double("delegate")
|
192
|
-
expect(actual).to receive(:happy?).and_yield
|
193
|
-
expect(delegate).to receive(:check_happy).and_return(true)
|
194
|
-
expect {
|
195
|
-
expect(actual).not_to be_happy { delegate.check_happy }
|
196
|
-
}.to fail_with("expected happy? to return false, got true")
|
197
|
-
end
|
198
|
-
|
199
|
-
it "fails when actual does not respond to :predicate?" do
|
200
|
-
delegate = double("delegate", :check_happy => true)
|
201
|
-
expect {
|
202
|
-
expect(Object.new).not_to be_happy { delegate.check_happy }
|
203
|
-
}.to raise_error(NameError)
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
describe "expect(...).to be_predicate(*args, &block)" do
|
208
|
-
it "passes when actual returns true for :predicate?(*args, &block)" do
|
209
|
-
actual = double("actual")
|
210
|
-
delegate = double("delegate")
|
211
|
-
expect(actual).to receive(:older_than?).with(3).and_yield(3)
|
212
|
-
expect(delegate).to receive(:check_older_than).with(3).and_return(true)
|
213
|
-
expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) }
|
214
|
-
end
|
215
|
-
|
216
|
-
it "fails when actual returns false for :predicate?(*args, &block)" do
|
217
|
-
actual = double("actual")
|
218
|
-
delegate = double("delegate")
|
219
|
-
expect(actual).to receive(:older_than?).with(3).and_yield(3)
|
220
|
-
expect(delegate).to receive(:check_older_than).with(3).and_return(false)
|
221
|
-
expect {
|
222
|
-
expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) }
|
223
|
-
}.to fail_with("expected older_than?(3) to return true, got false")
|
224
|
-
end
|
225
|
-
|
226
|
-
it "fails when actual does not respond to :predicate?" do
|
227
|
-
delegate = double("delegate", :check_older_than => true)
|
228
|
-
expect {
|
229
|
-
expect(Object.new).to be_older_than(3) { |age| delegate.check_older_than(age) }
|
230
|
-
}.to raise_error(NameError)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
describe "expect(...).not_to be_predicate(*args, &block)" do
|
235
|
-
it "passes when actual returns false for :predicate?(*args, &block)" do
|
236
|
-
actual = double("actual")
|
237
|
-
delegate = double("delegate")
|
238
|
-
expect(actual).to receive(:older_than?).with(3).and_yield(3)
|
239
|
-
expect(delegate).to receive(:check_older_than).with(3).and_return(false)
|
240
|
-
expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
|
241
|
-
end
|
242
|
-
|
243
|
-
it "fails when actual returns true for :predicate?(*args, &block)" do
|
244
|
-
actual = double("actual")
|
245
|
-
delegate = double("delegate")
|
246
|
-
expect(actual).to receive(:older_than?).with(3).and_yield(3)
|
247
|
-
expect(delegate).to receive(:check_older_than).with(3).and_return(true)
|
248
|
-
expect {
|
249
|
-
expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
|
250
|
-
}.to fail_with("expected older_than?(3) to return false, got true")
|
251
|
-
end
|
252
|
-
|
253
|
-
it "fails when actual does not respond to :predicate?" do
|
254
|
-
delegate = double("delegate", :check_older_than => true)
|
255
|
-
expect {
|
256
|
-
expect(Object.new).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
|
257
|
-
}.to raise_error(NameError)
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
describe "expect(...).to be_truthy" do
|
262
|
-
it "passes when actual equal?(true)" do
|
263
|
-
expect(true).to be_truthy
|
264
|
-
end
|
265
|
-
|
266
|
-
it "passes when actual is 1" do
|
267
|
-
expect(1).to be_truthy
|
268
|
-
end
|
269
|
-
|
270
|
-
it "fails when actual equal?(false)" do
|
271
|
-
expect {
|
272
|
-
expect(false).to be_truthy
|
273
|
-
}.to fail_with("expected: truthy value\n got: false")
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
describe "expect(...).to be_falsey" do
|
278
|
-
it "passes when actual equal?(false)" do
|
279
|
-
expect(false).to be_falsey
|
280
|
-
end
|
281
|
-
|
282
|
-
it "passes when actual equal?(nil)" do
|
283
|
-
expect(nil).to be_falsey
|
284
|
-
end
|
285
|
-
|
286
|
-
it "fails when actual equal?(true)" do
|
287
|
-
expect {
|
288
|
-
expect(true).to be_falsey
|
289
|
-
}.to fail_with("expected: falsey value\n got: true")
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
describe "expect(...).to be_falsy" do
|
294
|
-
it "passes when actual equal?(false)" do
|
295
|
-
expect(false).to be_falsy
|
296
|
-
end
|
297
|
-
|
298
|
-
it "passes when actual equal?(nil)" do
|
299
|
-
expect(nil).to be_falsy
|
300
|
-
end
|
301
|
-
|
302
|
-
it "fails when actual equal?(true)" do
|
303
|
-
expect {
|
304
|
-
expect(true).to be_falsy
|
305
|
-
}.to fail_with("expected: falsey value\n got: true")
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
describe "expect(...).to be_nil" do
|
310
|
-
it "passes when actual is nil" do
|
311
|
-
expect(nil).to be_nil
|
312
|
-
end
|
313
|
-
|
314
|
-
it "fails when actual is not nil" do
|
315
|
-
expect {
|
316
|
-
expect(:not_nil).to be_nil
|
317
|
-
}.to fail_with(/^expected: nil/)
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
describe "expect(...).not_to be_nil" do
|
322
|
-
it "passes when actual is not nil" do
|
323
|
-
expect(:not_nil).not_to be_nil
|
324
|
-
end
|
325
|
-
|
326
|
-
it "fails when actual is nil" do
|
327
|
-
expect {
|
328
|
-
expect(nil).not_to be_nil
|
329
|
-
}.to fail_with(/^expected: not nil/)
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
describe "expect(...).to be <" do
|
334
|
-
it "passes when < operator returns true" do
|
335
|
-
expect(3).to be < 4
|
336
|
-
end
|
337
|
-
|
338
|
-
it "fails when < operator returns false" do
|
339
|
-
expect {
|
340
|
-
expect(3).to be < 3
|
341
|
-
}.to fail_with("expected: < 3\n got: 3")
|
342
|
-
end
|
343
|
-
|
344
|
-
it "describes itself" do
|
345
|
-
expect(be.<(4).description).to eq "be < 4"
|
346
|
-
end
|
347
|
-
|
348
|
-
it 'does not lie and say that it is equal to a number' do
|
349
|
-
matcher = (be < 3)
|
350
|
-
expect(5 == matcher).to be false
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
describe "expect(...).to be <=" do
|
355
|
-
it "passes when <= operator returns true" do
|
356
|
-
expect(3).to be <= 4
|
357
|
-
expect(4).to be <= 4
|
358
|
-
end
|
359
|
-
|
360
|
-
it "fails when <= operator returns false" do
|
361
|
-
expect {
|
362
|
-
expect(3).to be <= 2
|
363
|
-
}.to fail_with("expected: <= 2\n got: 3")
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
describe "expect(...).to be >=" do
|
368
|
-
it "passes when >= operator returns true" do
|
369
|
-
expect(4).to be >= 4
|
370
|
-
expect(5).to be >= 4
|
371
|
-
end
|
372
|
-
|
373
|
-
it "fails when >= operator returns false" do
|
374
|
-
expect {
|
375
|
-
expect(3).to be >= 4
|
376
|
-
}.to fail_with("expected: >= 4\n got: 3")
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
describe "expect(...).to be >" do
|
381
|
-
it "passes when > operator returns true" do
|
382
|
-
expect(5).to be > 4
|
383
|
-
end
|
384
|
-
|
385
|
-
it "fails when > operator returns false" do
|
386
|
-
expect {
|
387
|
-
expect(3).to be > 4
|
388
|
-
}.to fail_with("expected: > 4\n got: 3")
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
describe "expect(...).to be ==" do
|
393
|
-
it "passes when == operator returns true" do
|
394
|
-
expect(5).to be == 5
|
395
|
-
end
|
396
|
-
|
397
|
-
it "fails when == operator returns false" do
|
398
|
-
expect {
|
399
|
-
expect(3).to be == 4
|
400
|
-
}.to fail_with("expected: == 4\n got: 3")
|
401
|
-
end
|
402
|
-
|
403
|
-
it 'works when the target overrides `#send`' do
|
404
|
-
klass = Struct.new(:message) do
|
405
|
-
def send
|
406
|
-
:message_sent
|
407
|
-
end
|
408
|
-
end
|
409
|
-
|
410
|
-
msg_1 = klass.new("hello")
|
411
|
-
msg_2 = klass.new("hello")
|
412
|
-
expect(msg_1).to be == msg_2
|
413
|
-
end
|
414
|
-
end
|
415
|
-
|
416
|
-
describe "expect(...).to be =~" do
|
417
|
-
it "passes when =~ operator returns true" do
|
418
|
-
expect("a string").to be =~ /str/
|
419
|
-
end
|
420
|
-
|
421
|
-
it "fails when =~ operator returns false" do
|
422
|
-
expect {
|
423
|
-
expect("a string").to be =~ /blah/
|
424
|
-
}.to fail_with(%Q|expected: =~ /blah/\n got: "a string"|)
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
describe "should be =~", :uses_should do
|
429
|
-
it "passes when =~ operator returns true" do
|
430
|
-
"a string".should be =~ /str/
|
431
|
-
end
|
432
|
-
|
433
|
-
it "fails when =~ operator returns false" do
|
434
|
-
expect {
|
435
|
-
"a string".should be =~ /blah/
|
436
|
-
}.to fail_with(%Q|expected: =~ /blah/\n got: "a string"|)
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
describe "expect(...).to be ===" do
|
441
|
-
it "passes when === operator returns true" do
|
442
|
-
expect(Hash).to be === Hash.new
|
443
|
-
end
|
444
|
-
|
445
|
-
it "fails when === operator returns false" do
|
446
|
-
expect {
|
447
|
-
expect(Hash).to be === "not a hash"
|
448
|
-
}.to fail_with(%[expected: === "not a hash"\n got: Hash])
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
|
-
describe "expect(...).not_to with comparison operators" do
|
453
|
-
it "coaches user to stop using operators with expect().not_to with numerical comparison operators" do
|
454
|
-
expect {
|
455
|
-
expect(5).not_to be < 6
|
456
|
-
}.to fail_with("`expect(5).not_to be < 6` not only FAILED, it is a bit confusing.")
|
457
|
-
|
458
|
-
expect {
|
459
|
-
expect(5).not_to be <= 6
|
460
|
-
}.to fail_with("`expect(5).not_to be <= 6` not only FAILED, it is a bit confusing.")
|
461
|
-
|
462
|
-
expect {
|
463
|
-
expect(6).not_to be > 5
|
464
|
-
}.to fail_with("`expect(6).not_to be > 5` not only FAILED, it is a bit confusing.")
|
465
|
-
|
466
|
-
expect {
|
467
|
-
expect(6).not_to be >= 5
|
468
|
-
}.to fail_with("`expect(6).not_to be >= 5` not only FAILED, it is a bit confusing.")
|
469
|
-
end
|
470
|
-
|
471
|
-
it "coaches users to stop using negation with string comparison operators" do
|
472
|
-
expect {
|
473
|
-
expect("foo").not_to be > "bar"
|
474
|
-
}.to fail_with('`expect("foo").not_to be > "bar"` not only FAILED, it is a bit confusing.')
|
475
|
-
end
|
476
|
-
end
|
477
|
-
|
478
|
-
describe "expect(...).not_to with equality operators" do
|
479
|
-
it "raises normal error with expect().not_to with equality operators" do
|
480
|
-
expect {
|
481
|
-
expect(6).not_to be == 6
|
482
|
-
}.to fail_with("`expect(6).not_to be == 6`")
|
483
|
-
|
484
|
-
expect {
|
485
|
-
expect(String).not_to be === "Hello"
|
486
|
-
}.to fail_with('`expect(String).not_to be === "Hello"`')
|
487
|
-
end
|
488
|
-
end
|
489
|
-
|
490
|
-
describe "expect(...).to be" do
|
491
|
-
it "passes if actual is truthy" do
|
492
|
-
expect(true).to be
|
493
|
-
expect(1).to be
|
494
|
-
end
|
495
|
-
|
496
|
-
it "fails if actual is false" do
|
497
|
-
expect {
|
498
|
-
expect(false).to be
|
499
|
-
}.to fail_with("expected false to evaluate to true")
|
500
|
-
end
|
501
|
-
|
502
|
-
it "fails if actual is nil" do
|
503
|
-
expect {
|
504
|
-
expect(nil).to be
|
505
|
-
}.to fail_with("expected nil to evaluate to true")
|
506
|
-
end
|
507
|
-
|
508
|
-
it "describes itself" do
|
509
|
-
expect(be.description).to eq "be"
|
510
|
-
end
|
511
|
-
end
|
512
|
-
|
513
|
-
describe "expect(...).not_to be" do
|
514
|
-
it "passes if actual is falsy" do
|
515
|
-
expect(false).not_to be
|
516
|
-
expect(nil).not_to be
|
517
|
-
end
|
518
|
-
|
519
|
-
it "fails on true" do
|
520
|
-
expect {
|
521
|
-
expect(true).not_to be
|
522
|
-
}.to fail_with("expected true to evaluate to false")
|
523
|
-
end
|
524
|
-
end
|
525
|
-
|
526
|
-
describe "expect(...).to be(value)" do
|
527
|
-
it "delegates to equal" do
|
528
|
-
matcher = equal(5)
|
529
|
-
expect(self).to receive(:equal).with(5).and_return(matcher)
|
530
|
-
expect(5).to be(5)
|
531
|
-
end
|
532
|
-
end
|
533
|
-
|
534
|
-
describe "expect(...).not_to be(value)" do
|
535
|
-
it "delegates to equal" do
|
536
|
-
matcher = equal(4)
|
537
|
-
expect(self).to receive(:equal).with(4).and_return(matcher)
|
538
|
-
expect(5).not_to be(4)
|
539
|
-
end
|
540
|
-
end
|
541
|
-
|
542
|
-
describe "'expect(...).to be' with operator" do
|
543
|
-
it "includes 'be' in the description" do
|
544
|
-
expect((be > 6).description).to match(/be > 6/)
|
545
|
-
expect((be >= 6).description).to match(/be >= 6/)
|
546
|
-
expect((be <= 6).description).to match(/be <= 6/)
|
547
|
-
expect((be < 6).description).to match(/be < 6/)
|
548
|
-
end
|
549
|
-
end
|
550
|
-
|
551
|
-
|
552
|
-
describe "arbitrary predicate with DelegateClass" do
|
553
|
-
it "accesses methods defined in the delegating class (LH[#48])" do
|
554
|
-
require 'delegate'
|
555
|
-
class ArrayDelegate < DelegateClass(Array)
|
556
|
-
def initialize(array)
|
557
|
-
@internal_array = array
|
558
|
-
super(@internal_array)
|
559
|
-
end
|
560
|
-
|
561
|
-
def large?
|
562
|
-
@internal_array.size >= 5
|
563
|
-
end
|
564
|
-
end
|
565
|
-
|
566
|
-
delegate = ArrayDelegate.new([1,2,3,4,5,6])
|
567
|
-
expect(delegate).to be_large
|
568
|
-
end
|
569
|
-
end
|
570
|
-
|
571
|
-
describe "be_a, be_an" do
|
572
|
-
it "passes when class matches" do
|
573
|
-
expect("foobar").to be_a(String)
|
574
|
-
expect([1,2,3]).to be_an(Array)
|
575
|
-
end
|
576
|
-
|
577
|
-
it "fails when class does not match" do
|
578
|
-
expect("foobar").not_to be_a(Hash)
|
579
|
-
expect([1,2,3]).not_to be_an(Integer)
|
580
|
-
end
|
581
|
-
end
|
582
|
-
|
583
|
-
describe "be_an_instance_of" do
|
584
|
-
it "passes when direct class matches" do
|
585
|
-
expect(5).to be_an_instance_of(Fixnum)
|
586
|
-
end
|
587
|
-
|
588
|
-
it "fails when class is higher up hierarchy" do
|
589
|
-
expect(5).not_to be_an_instance_of(Numeric)
|
590
|
-
end
|
591
|
-
end
|
592
|
-
|