rspec-mocks 3.0.0.beta2 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +104 -36
- data/README.md +35 -4
- data/lib/rspec/mocks.rb +52 -13
- data/lib/rspec/mocks/any_instance.rb +10 -0
- data/lib/rspec/mocks/any_instance/chain.rb +17 -0
- data/lib/rspec/mocks/any_instance/expect_chain_chain.rb +1 -1
- data/lib/rspec/mocks/any_instance/expectation_chain.rb +9 -6
- data/lib/rspec/mocks/any_instance/message_chains.rb +10 -1
- data/lib/rspec/mocks/any_instance/proxy.rb +112 -0
- data/lib/rspec/mocks/any_instance/recorder.rb +49 -18
- data/lib/rspec/mocks/any_instance/stub_chain.rb +5 -3
- data/lib/rspec/mocks/any_instance/stub_chain_chain.rb +1 -1
- data/lib/rspec/mocks/argument_list_matcher.rb +5 -3
- data/lib/rspec/mocks/argument_matchers.rb +28 -12
- data/lib/rspec/mocks/configuration.rb +29 -0
- data/lib/rspec/mocks/error_generator.rb +2 -5
- data/lib/rspec/mocks/example_methods.rb +122 -13
- data/lib/rspec/mocks/instance_method_stasher.rb +26 -2
- data/lib/rspec/mocks/marshal_extension.rb +41 -0
- data/lib/rspec/mocks/matchers/expectation_customization.rb +20 -0
- data/lib/rspec/mocks/matchers/receive.rb +6 -20
- data/lib/rspec/mocks/matchers/receive_message_chain.rb +7 -5
- data/lib/rspec/mocks/matchers/receive_messages.rb +1 -2
- data/lib/rspec/mocks/message_chain.rb +9 -9
- data/lib/rspec/mocks/message_expectation.rb +6 -5
- data/lib/rspec/mocks/method_double.rb +67 -10
- data/lib/rspec/mocks/method_reference.rb +1 -1
- data/lib/rspec/mocks/mutate_const.rb +10 -14
- data/lib/rspec/mocks/object_reference.rb +7 -4
- data/lib/rspec/mocks/proxy.rb +95 -8
- data/lib/rspec/mocks/space.rb +58 -9
- data/lib/rspec/mocks/syntax.rb +128 -210
- data/lib/rspec/mocks/targets.rb +6 -8
- data/lib/rspec/mocks/test_double.rb +16 -25
- data/lib/rspec/mocks/verifying_double.rb +15 -12
- data/lib/rspec/mocks/verifying_message_expecation.rb +3 -3
- data/lib/rspec/mocks/verifying_proxy.rb +23 -17
- data/lib/rspec/mocks/version.rb +3 -1
- metadata +29 -257
- metadata.gz.sig +0 -0
- data/features/README.md +0 -75
- data/features/Scope.md +0 -17
- data/features/Upgrade.md +0 -22
- data/features/argument_matchers/README.md +0 -27
- data/features/argument_matchers/explicit.feature +0 -59
- data/features/argument_matchers/general_matchers.feature +0 -85
- data/features/argument_matchers/type_matchers.feature +0 -26
- data/features/message_expectations/README.md +0 -75
- data/features/message_expectations/allow_any_instance_of.feature +0 -26
- data/features/message_expectations/any_instance.feature +0 -43
- data/features/message_expectations/block_local_expectations.feature.pending +0 -55
- data/features/message_expectations/call_original.feature +0 -23
- data/features/message_expectations/expect_message_using_expect.feature +0 -107
- data/features/message_expectations/expect_message_using_should_receive.feature +0 -118
- data/features/message_expectations/message_chains_using_expect.feature +0 -49
- data/features/message_expectations/receive_counts.feature +0 -209
- data/features/message_expectations/warn_when_expectation_is_set_on_nil.feature +0 -50
- data/features/method_stubs/README.md +0 -77
- data/features/method_stubs/allow_any_instance_of.feature +0 -136
- data/features/method_stubs/as_null_object.feature +0 -40
- data/features/method_stubs/receive_message_chain.feature +0 -51
- data/features/method_stubs/simple_return_value_with_allow.feature +0 -44
- data/features/method_stubs/simple_return_value_with_stub.feature +0 -64
- data/features/method_stubs/stub_implementation.feature +0 -48
- data/features/method_stubs/to_ary.feature +0 -51
- data/features/mutating_constants/README.md +0 -82
- data/features/mutating_constants/hiding_defined_constant.feature +0 -64
- data/features/mutating_constants/stub_defined_constant.feature +0 -78
- data/features/mutating_constants/stub_undefined_constant.feature +0 -50
- data/features/outside_rspec/standalone.feature +0 -33
- data/features/spies/spy_partial_mock_method.feature +0 -34
- data/features/spies/spy_pure_mock_method.feature +0 -76
- data/features/spies/spy_unstubbed_method.feature +0 -18
- data/features/step_definitions/additional_cli_steps.rb +0 -11
- data/features/support/env.rb +0 -22
- data/features/support/rubinius.rb +0 -6
- data/features/test_frameworks/test_unit.feature +0 -54
- data/features/verifying_doubles/README.md +0 -17
- data/features/verifying_doubles/class_doubles.feature +0 -73
- data/features/verifying_doubles/dynamic_classes.feature +0 -71
- data/features/verifying_doubles/instance_doubles.feature +0 -103
- data/features/verifying_doubles/object_doubles.feature +0 -65
- data/features/verifying_doubles/partial_doubles.feature +0 -34
- data/lib/rspec/mocks/extensions/marshal.rb +0 -17
- data/lib/rspec/mocks/framework.rb +0 -35
- data/lib/rspec/mocks/method_signature_verifier.rb +0 -207
- data/lib/rspec/mocks/ruby_features.rb +0 -24
- data/spec/rspec/mocks/and_call_original_spec.rb +0 -268
- data/spec/rspec/mocks/and_return_spec.rb +0 -23
- data/spec/rspec/mocks/and_yield_spec.rb +0 -126
- data/spec/rspec/mocks/any_instance/message_chains_spec.rb +0 -41
- data/spec/rspec/mocks/any_instance_spec.rb +0 -1045
- data/spec/rspec/mocks/array_including_matcher_spec.rb +0 -41
- data/spec/rspec/mocks/at_least_spec.rb +0 -123
- data/spec/rspec/mocks/at_most_spec.rb +0 -90
- data/spec/rspec/mocks/before_all_spec.rb +0 -132
- data/spec/rspec/mocks/block_return_value_spec.rb +0 -70
- data/spec/rspec/mocks/combining_implementation_instructions_spec.rb +0 -204
- data/spec/rspec/mocks/configuration_spec.rb +0 -242
- data/spec/rspec/mocks/double_spec.rb +0 -874
- data/spec/rspec/mocks/example_methods_spec.rb +0 -13
- data/spec/rspec/mocks/extensions/marshal_spec.rb +0 -54
- data/spec/rspec/mocks/failing_argument_matchers_spec.rb +0 -184
- data/spec/rspec/mocks/hash_excluding_matcher_spec.rb +0 -67
- data/spec/rspec/mocks/hash_including_matcher_spec.rb +0 -94
- data/spec/rspec/mocks/instance_method_stasher_spec.rb +0 -74
- data/spec/rspec/mocks/matchers/have_received_spec.rb +0 -347
- data/spec/rspec/mocks/matchers/receive_message_chain_spec.rb +0 -198
- data/spec/rspec/mocks/matchers/receive_messages_spec.rb +0 -140
- data/spec/rspec/mocks/matchers/receive_spec.rb +0 -418
- data/spec/rspec/mocks/method_signature_verifier_spec.rb +0 -272
- data/spec/rspec/mocks/methods_spec.rb +0 -26
- data/spec/rspec/mocks/mock_expectation_error_spec.rb +0 -22
- data/spec/rspec/mocks/mock_ordering_spec.rb +0 -114
- data/spec/rspec/mocks/multiple_return_value_spec.rb +0 -132
- data/spec/rspec/mocks/mutate_const_spec.rb +0 -542
- data/spec/rspec/mocks/nil_expectation_warning_spec.rb +0 -52
- data/spec/rspec/mocks/null_object_mock_spec.rb +0 -133
- data/spec/rspec/mocks/once_counts_spec.rb +0 -52
- data/spec/rspec/mocks/options_hash_spec.rb +0 -35
- data/spec/rspec/mocks/order_group_spec.rb +0 -27
- data/spec/rspec/mocks/partial_double_spec.rb +0 -308
- data/spec/rspec/mocks/partial_double_using_mocks_directly_spec.rb +0 -95
- data/spec/rspec/mocks/passing_argument_matchers_spec.rb +0 -145
- data/spec/rspec/mocks/precise_counts_spec.rb +0 -68
- data/spec/rspec/mocks/record_messages_spec.rb +0 -26
- data/spec/rspec/mocks/serialization_spec.rb +0 -90
- data/spec/rspec/mocks/space_spec.rb +0 -244
- data/spec/rspec/mocks/stash_spec.rb +0 -46
- data/spec/rspec/mocks/stub_chain_spec.rb +0 -168
- data/spec/rspec/mocks/stub_implementation_spec.rb +0 -81
- data/spec/rspec/mocks/stub_spec.rb +0 -327
- data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +0 -58
- data/spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb +0 -101
- data/spec/rspec/mocks/syntax_spec.rb +0 -19
- data/spec/rspec/mocks/test_double_spec.rb +0 -49
- data/spec/rspec/mocks/to_ary_spec.rb +0 -54
- data/spec/rspec/mocks/twice_counts_spec.rb +0 -66
- data/spec/rspec/mocks/verifying_double_spec.rb +0 -590
- data/spec/rspec/mocks/verifying_message_expecation_spec.rb +0 -69
- data/spec/rspec/mocks_spec.rb +0 -192
- data/spec/spec_helper.rb +0 -121
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
describe ExampleMethods do
|
6
|
-
it 'does not define private helper methods since it gets included into a ' +
|
7
|
-
'namespace where users define methods and could inadvertently overwrite ' +
|
8
|
-
'them' do
|
9
|
-
expect(ExampleMethods.private_instance_methods).to eq([])
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Marshal, 'extensions' do
|
4
|
-
# An object that raises when code attempts to dup it.
|
5
|
-
#
|
6
|
-
# Because we manipulate the internals of RSpec::Mocks.space below, we need
|
7
|
-
# an object that simply blows up when #dup is called without using any
|
8
|
-
# partial mocking or stubbing from rspec-mocks itself.
|
9
|
-
class UndupableObject
|
10
|
-
def dup
|
11
|
-
raise NotImplementedError
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#dump' do
|
16
|
-
context 'when rspec-mocks has been fully initialized' do
|
17
|
-
it 'duplicates objects with stubbed or mocked implementations before serialization' do
|
18
|
-
obj = double(:foo => "bar")
|
19
|
-
|
20
|
-
serialized = Marshal.dump(obj)
|
21
|
-
expect(Marshal.load(serialized)).to be_an(obj.class)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'does not duplicate other objects before serialization' do
|
25
|
-
obj = UndupableObject.new
|
26
|
-
|
27
|
-
serialized = Marshal.dump(obj)
|
28
|
-
expect(Marshal.load(serialized)).to be_an(UndupableObject)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'does not duplicate nil before serialization' do
|
32
|
-
serialized = Marshal.dump(nil)
|
33
|
-
expect(Marshal.load(serialized)).to be_nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'outside the per-test lifecycle' do
|
38
|
-
def outside_per_test_lifecycle
|
39
|
-
RSpec::Mocks.teardown
|
40
|
-
yield
|
41
|
-
ensure
|
42
|
-
RSpec::Mocks.setup
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'does not duplicate the object before serialization' do
|
46
|
-
obj = UndupableObject.new
|
47
|
-
outside_per_test_lifecycle do
|
48
|
-
serialized = Marshal.dump(obj)
|
49
|
-
expect(Marshal.load(serialized)).to be_an(UndupableObject)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,184 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
describe "failing MockArgumentMatchers" do
|
6
|
-
before(:each) do
|
7
|
-
@double = double("double")
|
8
|
-
@reporter = double("reporter").as_null_object
|
9
|
-
end
|
10
|
-
|
11
|
-
after(:each) do
|
12
|
-
reset @double
|
13
|
-
end
|
14
|
-
|
15
|
-
it "rejects non boolean" do
|
16
|
-
@double.should_receive(:random_call).with(boolean())
|
17
|
-
expect do
|
18
|
-
@double.random_call("false")
|
19
|
-
end.to raise_error(RSpec::Mocks::MockExpectationError)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "rejects non numeric" do
|
23
|
-
@double.should_receive(:random_call).with(an_instance_of(Numeric))
|
24
|
-
expect do
|
25
|
-
@double.random_call("1")
|
26
|
-
end.to raise_error(RSpec::Mocks::MockExpectationError)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "rejects non string" do
|
30
|
-
@double.should_receive(:random_call).with(an_instance_of(String))
|
31
|
-
expect do
|
32
|
-
@double.random_call(123)
|
33
|
-
end.to raise_error(RSpec::Mocks::MockExpectationError)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "rejects goose when expecting a duck" do
|
37
|
-
@double.should_receive(:random_call).with(duck_type(:abs, :div))
|
38
|
-
expect { @double.random_call("I don't respond to :abs or :div") }.to raise_error(RSpec::Mocks::MockExpectationError)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "fails if regexp does not match submitted string" do
|
42
|
-
@double.should_receive(:random_call).with(/bcd/)
|
43
|
-
expect { @double.random_call("abc") }.to raise_error(RSpec::Mocks::MockExpectationError)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "fails if regexp does not match submitted regexp" do
|
47
|
-
@double.should_receive(:random_call).with(/bcd/)
|
48
|
-
expect { @double.random_call(/bcde/) }.to raise_error(RSpec::Mocks::MockExpectationError)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "fails for a hash w/ wrong values" do
|
52
|
-
@double.should_receive(:random_call).with(:a => "b", :c => "d")
|
53
|
-
expect do
|
54
|
-
@double.random_call(:a => "b", :c => "e")
|
55
|
-
end.to raise_error(RSpec::Mocks::MockExpectationError, /Double "double" received :random_call with unexpected arguments\n expected: \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\)\n got: \(\{(:a=>\"b\", :c=>\"e\"|:c=>\"e\", :a=>\"b\")\}\)/)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "fails for a hash w/ wrong keys" do
|
59
|
-
@double.should_receive(:random_call).with(:a => "b", :c => "d")
|
60
|
-
expect do
|
61
|
-
@double.random_call("a" => "b", "c" => "d")
|
62
|
-
end.to raise_error(RSpec::Mocks::MockExpectationError, /Double "double" received :random_call with unexpected arguments\n expected: \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\)\n got: \(\{(\"a\"=>\"b\", \"c\"=>\"d\"|\"c\"=>\"d\", \"a\"=>\"b\")\}\)/)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "matches against a Matcher" do
|
66
|
-
# This spec is generating warnings on 1.8.7, not sure why so
|
67
|
-
# this does with_isolated_stderr to kill them. @samphippen 3rd Jan 2013.
|
68
|
-
expect do
|
69
|
-
@double.should_receive(:msg).with(equal(3))
|
70
|
-
with_isolated_stderr { @double.msg(37) }
|
71
|
-
end.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :msg with unexpected arguments\n expected: (equal 3)\n got: (37)")
|
72
|
-
end
|
73
|
-
|
74
|
-
it "fails no_args with one arg" do
|
75
|
-
expect do
|
76
|
-
@double.should_receive(:msg).with(no_args)
|
77
|
-
@double.msg(37)
|
78
|
-
end.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :msg with unexpected arguments\n expected: (no args)\n got: (37)")
|
79
|
-
end
|
80
|
-
|
81
|
-
it "fails hash_including with missing key" do
|
82
|
-
expect do
|
83
|
-
@double.should_receive(:msg).with(hash_including(:a => 1))
|
84
|
-
@double.msg({})
|
85
|
-
end.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :msg with unexpected arguments\n expected: (hash_including(:a=>1))\n got: ({})")
|
86
|
-
end
|
87
|
-
|
88
|
-
it "fails array_including when args aren't array" do
|
89
|
-
expect do
|
90
|
-
@double.should_receive(:msg).with(array_including(1,2,3))
|
91
|
-
@double.msg(1,2,3)
|
92
|
-
end.to raise_error(/array_including\(1,2,3\)/)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "fails array_including when arg doesn't contain all elements" do
|
96
|
-
expect do
|
97
|
-
@double.should_receive(:msg).with(array_including(1,2,3))
|
98
|
-
@double.msg(1,2)
|
99
|
-
end.to raise_error(/array_including\(1,2,3\)/)
|
100
|
-
end
|
101
|
-
|
102
|
-
it "fails with zero arguments" do
|
103
|
-
expect do
|
104
|
-
@double.should_receive(:msg).with {|arg| expect(arg).to eq :received }
|
105
|
-
end.to raise_error(ArgumentError, /must have at least one argument/)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "fails when given an arbitrary object that returns false from #===" do
|
109
|
-
matcher = double
|
110
|
-
matcher.should_receive(:===).with(4).at_least(:once).and_return(false)
|
111
|
-
|
112
|
-
@double.should_receive(:foo).with(matcher)
|
113
|
-
|
114
|
-
expect {
|
115
|
-
@double.foo(4)
|
116
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "fails with sensible message when args respond to #description" do
|
120
|
-
arg = Class.new do
|
121
|
-
def description
|
122
|
-
end
|
123
|
-
|
124
|
-
def inspect
|
125
|
-
"my_thing"
|
126
|
-
end
|
127
|
-
end.new
|
128
|
-
|
129
|
-
expect do
|
130
|
-
@double.should_receive(:msg).with(3)
|
131
|
-
@double.msg arg
|
132
|
-
end.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :msg with unexpected arguments\n expected: (3)\n got: (my_thing)")
|
133
|
-
end
|
134
|
-
|
135
|
-
it "fails with sensible message when arg#description is nil" do
|
136
|
-
arg = Class.new do
|
137
|
-
def description
|
138
|
-
end
|
139
|
-
|
140
|
-
def inspect
|
141
|
-
"my_thing"
|
142
|
-
end
|
143
|
-
end.new
|
144
|
-
|
145
|
-
expect do
|
146
|
-
@double.should_receive(:msg).with(arg)
|
147
|
-
@double.msg 3
|
148
|
-
end.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :msg with unexpected arguments\n expected: (my_thing)\n got: (3)")
|
149
|
-
end
|
150
|
-
|
151
|
-
it "fails with sensible message when arg#description is blank" do
|
152
|
-
arg = Class.new do
|
153
|
-
def description
|
154
|
-
""
|
155
|
-
end
|
156
|
-
|
157
|
-
def inspect
|
158
|
-
"my_thing"
|
159
|
-
end
|
160
|
-
end.new
|
161
|
-
|
162
|
-
expect do
|
163
|
-
@double.should_receive(:msg).with(arg)
|
164
|
-
@double.msg 3
|
165
|
-
end.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :msg with unexpected arguments\n expected: (my_thing)\n got: (3)")
|
166
|
-
end
|
167
|
-
|
168
|
-
it "fails a class against an unrelated class" do
|
169
|
-
@double.should_receive(:foo).with(Fixnum)
|
170
|
-
expect {
|
171
|
-
@double.foo(Hash)
|
172
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError)
|
173
|
-
end
|
174
|
-
|
175
|
-
it "fails a class against an object of a different type" do
|
176
|
-
@double.should_receive(:foo).with(Fixnum)
|
177
|
-
|
178
|
-
expect {
|
179
|
-
@double.foo(3.2)
|
180
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
module ArgumentMatchers
|
6
|
-
describe HashExcludingMatcher do
|
7
|
-
|
8
|
-
it "describes itself properly" do
|
9
|
-
expect(HashExcludingMatcher.new(:a => 5).description).to eq "hash_not_including(:a=>5)"
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "passing" do
|
13
|
-
it "matches a hash without the specified key" do
|
14
|
-
expect(hash_not_including(:c)).to be === {:a => 1, :b => 2}
|
15
|
-
end
|
16
|
-
|
17
|
-
it "matches a hash with the specified key, but different value" do
|
18
|
-
expect(hash_not_including(:b => 3)).to be === {:a => 1, :b => 2}
|
19
|
-
end
|
20
|
-
|
21
|
-
it "matches a hash without the specified key, given as anything()" do
|
22
|
-
expect(hash_not_including(:c => anything)).to be === {:a => 1, :b => 2}
|
23
|
-
end
|
24
|
-
|
25
|
-
it "matches an empty hash" do
|
26
|
-
expect(hash_not_including(:a)).to be === {}
|
27
|
-
end
|
28
|
-
|
29
|
-
it "matches a hash without any of the specified keys" do
|
30
|
-
expect(hash_not_including(:a, :b, :c)).to be === { :d => 7 }
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "failing" do
|
36
|
-
it "does not match a non-hash" do
|
37
|
-
expect(hash_not_including(:a => 1)).not_to be === 1
|
38
|
-
end
|
39
|
-
|
40
|
-
it "does not match a hash with a specified key" do
|
41
|
-
expect(hash_not_including(:b)).not_to be === { :b => 2 }
|
42
|
-
end
|
43
|
-
|
44
|
-
it "does not match a hash with the specified key/value pair" do
|
45
|
-
expect(hash_not_including(:b => 2)).not_to be === { :a => 1, :b => 2 }
|
46
|
-
end
|
47
|
-
|
48
|
-
it "does not match a hash with the specified key" do
|
49
|
-
expect(hash_not_including(:a, :b => 3)).not_to be === { :a => 1, :b => 2 }
|
50
|
-
end
|
51
|
-
|
52
|
-
it "does not match a hash with one of the specified keys" do
|
53
|
-
expect(hash_not_including(:a, :b)).not_to be === { :b => 2 }
|
54
|
-
end
|
55
|
-
|
56
|
-
it "does not match a hash with some of the specified keys" do
|
57
|
-
expect(hash_not_including(:a, :b, :c)).not_to be === { :a => 1, :b => 2 }
|
58
|
-
end
|
59
|
-
|
60
|
-
it "does not match a hash with one key/value pair included" do
|
61
|
-
expect(hash_not_including(:a, :b, :c, :d => 7)).not_to be === { :d => 7 }
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
module ArgumentMatchers
|
6
|
-
describe HashIncludingMatcher do
|
7
|
-
|
8
|
-
it "describes itself properly" do
|
9
|
-
expect(HashIncludingMatcher.new(:a => 1).description).to eq "hash_including(:a=>1)"
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "passing" do
|
13
|
-
it "matches the same hash" do
|
14
|
-
expect(hash_including(:a => 1)).to be === {:a => 1}
|
15
|
-
end
|
16
|
-
|
17
|
-
it "matches a hash with extra stuff" do
|
18
|
-
expect(hash_including(:a => 1)).to be === {:a => 1, :b => 2}
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "when matching against other matchers" do
|
22
|
-
it "matches an int against anything()" do
|
23
|
-
expect(hash_including(:a => anything, :b => 2)).to be === {:a => 1, :b => 2}
|
24
|
-
end
|
25
|
-
|
26
|
-
it "matches a string against anything()" do
|
27
|
-
expect(hash_including(:a => anything, :b => 2)).to be === {:a => "1", :b => 2}
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'can match against arbitrary objects that implement #===' do
|
31
|
-
expect(hash_including(:a => /foo/)).to be === { :a => "foobar" }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "when passed only keys or keys mixed with key/value pairs" do
|
36
|
-
it "matches if the key is present" do
|
37
|
-
expect(hash_including(:a)).to be === {:a => 1, :b => 2}
|
38
|
-
end
|
39
|
-
|
40
|
-
it "matches if more keys are present" do
|
41
|
-
expect(hash_including(:a, :b)).to be === {:a => 1, :b => 2, :c => 3}
|
42
|
-
end
|
43
|
-
|
44
|
-
it "matches a string against a given key" do
|
45
|
-
expect(hash_including(:a)).to be === {:a => "1", :b => 2}
|
46
|
-
end
|
47
|
-
|
48
|
-
it "matches if passed one key and one key/value pair" do
|
49
|
-
expect(hash_including(:a, :b => 2)).to be === {:a => 1, :b => 2}
|
50
|
-
end
|
51
|
-
|
52
|
-
it "matches if passed many keys and one key/value pair" do
|
53
|
-
expect(hash_including(:a, :b, :c => 3)).to be === {:a => 1, :b => 2, :c => 3, :d => 4}
|
54
|
-
end
|
55
|
-
|
56
|
-
it "matches if passed many keys and many key/value pairs" do
|
57
|
-
expect(hash_including(:a, :b, :c => 3, :e => 5)).to be === {:a => 1, :b => 2, :c => 3, :d => 4, :e => 5}
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "failing" do
|
63
|
-
it "does not match a non-hash" do
|
64
|
-
expect(hash_including(:a => 1)).not_to be === 1
|
65
|
-
end
|
66
|
-
|
67
|
-
it "does not match a hash with a missing key" do
|
68
|
-
expect(hash_including(:a => 1)).not_to be === { :b => 2 }
|
69
|
-
end
|
70
|
-
|
71
|
-
it "does not match a hash with a missing key" do
|
72
|
-
expect(hash_including(:a)).not_to be === { :b => 2 }
|
73
|
-
end
|
74
|
-
|
75
|
-
it "does not match an empty hash with a given key" do
|
76
|
-
expect(hash_including(:a)).not_to be === {}
|
77
|
-
end
|
78
|
-
|
79
|
-
it "does not match a hash with a missing key when one pair is matching" do
|
80
|
-
expect(hash_including(:a, :b => 2)).not_to be === { :b => 2 }
|
81
|
-
end
|
82
|
-
|
83
|
-
it "does not match a hash with an incorrect value" do
|
84
|
-
expect(hash_including(:a => 1, :b => 2)).not_to be === { :a => 1, :b => 3 }
|
85
|
-
end
|
86
|
-
|
87
|
-
it "does not match when values are nil but keys are different" do
|
88
|
-
expect(hash_including(:a => nil)).not_to be === { :b => nil }
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
describe InstanceMethodStasher do
|
6
|
-
class ExampleClass
|
7
|
-
def hello
|
8
|
-
:hello_defined_on_class
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def singleton_class_for(obj)
|
13
|
-
class << obj; self; end
|
14
|
-
end
|
15
|
-
|
16
|
-
def stasher_for(obj, method_name)
|
17
|
-
InstanceMethodStasher.new(obj, method_name)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "stashes the current implementation of an instance method so it can be temporarily replaced" do
|
21
|
-
obj = Object.new
|
22
|
-
def obj.hello; :hello_defined_on_singleton_class; end;
|
23
|
-
|
24
|
-
stashed_method = stasher_for(obj, :hello)
|
25
|
-
stashed_method.stash
|
26
|
-
|
27
|
-
with_isolated_stderr { def obj.hello; :overridden_hello; end }
|
28
|
-
expect(obj.hello).to eql :overridden_hello
|
29
|
-
|
30
|
-
stashed_method.restore
|
31
|
-
expect(obj.hello).to eql :hello_defined_on_singleton_class
|
32
|
-
end
|
33
|
-
|
34
|
-
it "stashes private instance methods" do
|
35
|
-
obj = Object.new
|
36
|
-
def obj.hello; :hello_defined_on_singleton_class; end;
|
37
|
-
singleton_class_for(obj).__send__(:private, :hello)
|
38
|
-
|
39
|
-
stashed_method = stasher_for(obj, :hello)
|
40
|
-
stashed_method.stash
|
41
|
-
|
42
|
-
with_isolated_stderr { def obj.hello; :overridden_hello; end }
|
43
|
-
stashed_method.restore
|
44
|
-
expect(obj.send(:hello)).to eql :hello_defined_on_singleton_class
|
45
|
-
end
|
46
|
-
|
47
|
-
it "only stashes methods directly defined on the given class, not its ancestors" do
|
48
|
-
obj = ExampleClass.new
|
49
|
-
|
50
|
-
stashed_method = stasher_for(obj, :hello)
|
51
|
-
stashed_method.stash
|
52
|
-
|
53
|
-
def obj.hello; :overridden_hello; end;
|
54
|
-
expect(obj.hello).to eql :overridden_hello
|
55
|
-
|
56
|
-
stashed_method.restore
|
57
|
-
expect(obj.hello).to eql :overridden_hello
|
58
|
-
end
|
59
|
-
|
60
|
-
it "does not unnecessarily create obfuscated aliased methods", :if => (RUBY_VERSION.to_f > 1.8) do
|
61
|
-
obj = Object.new
|
62
|
-
def obj.hello; :hello_defined_on_singleton_class; end;
|
63
|
-
|
64
|
-
stashed_method = stasher_for(obj, :hello)
|
65
|
-
|
66
|
-
expect {
|
67
|
-
stashed_method.stash
|
68
|
-
}.not_to change { obj.methods.count }
|
69
|
-
|
70
|
-
expect(obj.methods.grep(/rspec/)).to eq([])
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|