rr 1.1.1.rc1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/CREDITS.md +61 -0
  3. data/VERSION +1 -1
  4. data/doc/01_test_double.md +16 -0
  5. data/doc/02_syntax_comparison.md +96 -0
  6. data/doc/03_api_overview.md +616 -0
  7. data/rr.gemspec +6 -6
  8. metadata +12 -230
  9. data/spec/global_helper.rb +0 -53
  10. data/spec/spec.opts +0 -2
  11. data/spec/suite.rb +0 -107
  12. data/spec/suites/common/adapter_integration_tests.rb +0 -160
  13. data/spec/suites/common/adapter_tests.rb +0 -43
  14. data/spec/suites/common/rails_integration_tests.rb +0 -106
  15. data/spec/suites/common/test_unit_tests.rb +0 -21
  16. data/spec/suites/minitest/integration/minitest_test.rb +0 -13
  17. data/spec/suites/minitest/test_helper.rb +0 -7
  18. data/spec/suites/minitest_4/integration/minitest_test.rb +0 -13
  19. data/spec/suites/minitest_4/test_helper.rb +0 -7
  20. data/spec/suites/rspec_1/helper.rb +0 -24
  21. data/spec/suites/rspec_1/integration/rspec_1_spec.rb +0 -77
  22. data/spec/suites/rspec_1/integration/test_unit_1_spec.rb +0 -41
  23. data/spec/suites/rspec_1/integration/test_unit_2_spec.rb +0 -57
  24. data/spec/suites/rspec_1/spec_helper.rb +0 -3
  25. data/spec/suites/rspec_1_rails_2/integration/test_unit_1_rails_2_spec.rb +0 -53
  26. data/spec/suites/rspec_1_rails_2/integration/test_unit_2_rails_2_spec.rb +0 -57
  27. data/spec/suites/rspec_1_rails_2/spec_helper.rb +0 -3
  28. data/spec/suites/rspec_2/functional/any_instance_of_spec.rb +0 -47
  29. data/spec/suites/rspec_2/functional/dont_allow_spec.rb +0 -12
  30. data/spec/suites/rspec_2/functional/dsl_spec.rb +0 -13
  31. data/spec/suites/rspec_2/functional/instance_of_spec.rb +0 -14
  32. data/spec/suites/rspec_2/functional/mock_spec.rb +0 -241
  33. data/spec/suites/rspec_2/functional/proxy_spec.rb +0 -136
  34. data/spec/suites/rspec_2/functional/spy_spec.rb +0 -41
  35. data/spec/suites/rspec_2/functional/strong_spec.rb +0 -79
  36. data/spec/suites/rspec_2/functional/stub_spec.rb +0 -190
  37. data/spec/suites/rspec_2/functional/wildcard_matchers_spec.rb +0 -128
  38. data/spec/suites/rspec_2/helper.rb +0 -27
  39. data/spec/suites/rspec_2/integration/minitest_4_spec.rb +0 -57
  40. data/spec/suites/rspec_2/integration/minitest_spec.rb +0 -57
  41. data/spec/suites/rspec_2/integration/rspec_2_spec.rb +0 -126
  42. data/spec/suites/rspec_2/integration/test_unit_200_spec.rb +0 -57
  43. data/spec/suites/rspec_2/integration/test_unit_2_spec.rb +0 -57
  44. data/spec/suites/rspec_2/spec_helper.rb +0 -3
  45. data/spec/suites/rspec_2/support/matchers/wildcard_matcher_matchers.rb +0 -32
  46. data/spec/suites/rspec_2/support/shared_examples/space.rb +0 -13
  47. data/spec/suites/rspec_2/support/shared_examples/times_called_expectation.rb +0 -9
  48. data/spec/suites/rspec_2/unit/adapters/rr_methods/double_creators_spec.rb +0 -135
  49. data/spec/suites/rspec_2/unit/adapters/rr_methods/space_spec.rb +0 -101
  50. data/spec/suites/rspec_2/unit/adapters/rr_methods/wildcard_matchers_spec.rb +0 -69
  51. data/spec/suites/rspec_2/unit/core_ext/array_spec.rb +0 -39
  52. data/spec/suites/rspec_2/unit/core_ext/enumerable_spec.rb +0 -81
  53. data/spec/suites/rspec_2/unit/core_ext/hash_spec.rb +0 -55
  54. data/spec/suites/rspec_2/unit/core_ext/range_spec.rb +0 -41
  55. data/spec/suites/rspec_2/unit/core_ext/regexp_spec.rb +0 -41
  56. data/spec/suites/rspec_2/unit/double_definitions/child_double_definition_create_spec.rb +0 -114
  57. data/spec/suites/rspec_2/unit/double_definitions/double_definition_create_blank_slate_spec.rb +0 -93
  58. data/spec/suites/rspec_2/unit/double_definitions/double_definition_create_spec.rb +0 -446
  59. data/spec/suites/rspec_2/unit/errors/rr_error_spec.rb +0 -67
  60. data/spec/suites/rspec_2/unit/expectations/any_argument_expectation_spec.rb +0 -48
  61. data/spec/suites/rspec_2/unit/expectations/anything_argument_equality_expectation_spec.rb +0 -14
  62. data/spec/suites/rspec_2/unit/expectations/argument_equality_expectation_spec.rb +0 -135
  63. data/spec/suites/rspec_2/unit/expectations/boolean_argument_equality_expectation_spec.rb +0 -30
  64. data/spec/suites/rspec_2/unit/expectations/hash_including_argument_equality_expectation_spec.rb +0 -82
  65. data/spec/suites/rspec_2/unit/expectations/satisfy_argument_equality_expectation_spec.rb +0 -61
  66. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/any_times_matcher_spec.rb +0 -22
  67. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/at_least_matcher_spec.rb +0 -37
  68. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/at_most_matcher_spec.rb +0 -43
  69. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb +0 -58
  70. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/proc_matcher_spec.rb +0 -35
  71. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/range_matcher_spec.rb +0 -39
  72. data/spec/suites/rspec_2/unit/hash_with_object_id_key_spec.rb +0 -88
  73. data/spec/suites/rspec_2/unit/injections/double_injection/double_injection_spec.rb +0 -545
  74. data/spec/suites/rspec_2/unit/injections/double_injection/double_injection_verify_spec.rb +0 -32
  75. data/spec/suites/rspec_2/unit/integrations/rspec/invocation_matcher_spec.rb +0 -297
  76. data/spec/suites/rspec_2/unit/integrations/rspec_spec.rb +0 -85
  77. data/spec/suites/rspec_2/unit/proc_from_block_spec.rb +0 -14
  78. data/spec/suites/rspec_2/unit/rr_spec.rb +0 -28
  79. data/spec/suites/rspec_2/unit/space_spec.rb +0 -595
  80. data/spec/suites/rspec_2/unit/spy_verification_spec.rb +0 -133
  81. data/spec/suites/rspec_2/unit/times_called_matchers/any_times_matcher_spec.rb +0 -46
  82. data/spec/suites/rspec_2/unit/times_called_matchers/at_least_matcher_spec.rb +0 -54
  83. data/spec/suites/rspec_2/unit/times_called_matchers/at_most_matcher_spec.rb +0 -69
  84. data/spec/suites/rspec_2/unit/times_called_matchers/integer_matcher_spec.rb +0 -69
  85. data/spec/suites/rspec_2/unit/times_called_matchers/proc_matcher_spec.rb +0 -54
  86. data/spec/suites/rspec_2/unit/times_called_matchers/range_matcher_spec.rb +0 -75
  87. data/spec/suites/rspec_2/unit/times_called_matchers/times_called_matcher_spec.rb +0 -117
  88. data/spec/suites/rspec_2/unit/wildcard_matchers/anything_spec.rb +0 -33
  89. data/spec/suites/rspec_2/unit/wildcard_matchers/boolean_spec.rb +0 -45
  90. data/spec/suites/rspec_2/unit/wildcard_matchers/duck_type_spec.rb +0 -64
  91. data/spec/suites/rspec_2/unit/wildcard_matchers/hash_including_spec.rb +0 -64
  92. data/spec/suites/rspec_2/unit/wildcard_matchers/is_a_spec.rb +0 -55
  93. data/spec/suites/rspec_2/unit/wildcard_matchers/numeric_spec.rb +0 -46
  94. data/spec/suites/rspec_2/unit/wildcard_matchers/satisfy_spec.rb +0 -57
  95. data/spec/suites/rspec_2_rails_3/integration/minitest_4_rails_3_spec.rb +0 -66
  96. data/spec/suites/rspec_2_rails_3/integration/test_unit_200_rails_3_spec.rb +0 -66
  97. data/spec/suites/rspec_2_rails_3/integration/test_unit_2_rails_3_spec.rb +0 -66
  98. data/spec/suites/rspec_2_rails_3/spec_helper.rb +0 -3
  99. data/spec/suites/rspec_2_rails_4/integration/minitest_4_rails_4_spec.rb +0 -66
  100. data/spec/suites/rspec_2_rails_4/integration/rspec_2_rails_4_spec.rb +0 -156
  101. data/spec/suites/rspec_2_rails_4/integration/test_unit_200_rails_4_spec.rb +0 -66
  102. data/spec/suites/rspec_2_rails_4/integration/test_unit_2_rails_4_spec.rb +0 -66
  103. data/spec/suites/rspec_2_rails_4/spec_helper.rb +0 -3
  104. data/spec/suites/test_unit_1/integration/test_unit_1_test.rb +0 -10
  105. data/spec/suites/test_unit_1/test_helper.rb +0 -10
  106. data/spec/suites/test_unit_2/integration/test_unit_2_test.rb +0 -10
  107. data/spec/suites/test_unit_2/test_helper.rb +0 -6
  108. data/spec/suites/test_unit_200/integration/test_unit_200_test.rb +0 -10
  109. data/spec/suites/test_unit_200/test_helper.rb +0 -6
  110. data/spec/suites/test_unit_200_rails_3/integration/test_unit_200_rails_3_test.rb +0 -10
  111. data/spec/suites/test_unit_200_rails_3/test_helper.rb +0 -7
  112. data/spec/suites/test_unit_200_rails_4/integration/test_unit_200_rails_4_test.rb +0 -10
  113. data/spec/suites/test_unit_200_rails_4/test_helper.rb +0 -7
  114. data/spec/suites/test_unit_2_rails_2/integration/test_unit_2_rails_2_test.rb +0 -10
  115. data/spec/suites/test_unit_2_rails_2/test_helper.rb +0 -7
  116. data/spec/suites/test_unit_2_rails_3/integration/test_unit_2_rails_3_test.rb +0 -10
  117. data/spec/suites/test_unit_2_rails_3/test_helper.rb +0 -7
  118. data/spec/suites/test_unit_2_rails_4/integration/test_unit_2_rails_4_test.rb +0 -10
  119. data/spec/suites/test_unit_2_rails_4/test_helper.rb +0 -7
@@ -1,136 +0,0 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
- describe '#proxy' do
4
- subject { Object.new }
5
-
6
- it "proxies via inline call" do
7
- expected_to_s_value = subject.to_s
8
- mock.proxy(subject).to_s
9
- expect(subject.to_s).to eq expected_to_s_value
10
- expect { subject.to_s }.to raise_error
11
- RR.reset
12
- end
13
-
14
- it "proxy allows ordering" do
15
- def subject.to_s(arg)
16
- "Original to_s with arg #{arg}"
17
- end
18
- mock.proxy(subject).to_s(:foo).ordered
19
- mock.proxy(subject).to_s(:bar).twice.ordered
20
-
21
- expect(subject.to_s(:foo)).to eq "Original to_s with arg foo"
22
- expect(subject.to_s(:bar)).to eq "Original to_s with arg bar"
23
- expect(subject.to_s(:bar)).to eq "Original to_s with arg bar"
24
- expect { subject.to_s(:bar) }.to raise_error(RR::Errors::TimesCalledError)
25
-
26
- RR.reset
27
- end
28
-
29
- it "proxy allows ordering" do
30
- def subject.to_s(arg)
31
- "Original to_s with arg #{arg}"
32
- end
33
- mock.proxy(subject).to_s(:foo).ordered
34
- mock.proxy(subject).to_s(:bar).twice.ordered
35
-
36
- expect(subject.to_s(:foo)).to eq "Original to_s with arg foo"
37
- expect(subject.to_s(:bar)).to eq "Original to_s with arg bar"
38
- expect(subject.to_s(:bar)).to eq "Original to_s with arg bar"
39
- expect { subject.to_s(:bar) }.to raise_error(RR::Errors::TimesCalledError)
40
-
41
- RR.reset
42
- end
43
-
44
- it "proxies via block with argument" do
45
- def subject.foobar_1(*args)
46
- :original_value_1
47
- end
48
-
49
- def subject.foobar_2
50
- :original_value_2
51
- end
52
-
53
- mock.proxy subject do |c|
54
- c.foobar_1(1)
55
- c.foobar_2
56
- end
57
- expect(subject.foobar_1(1)).to eq :original_value_1
58
- expect { subject.foobar_1(:blah) }.to raise_error
59
-
60
- expect(subject.foobar_2).to eq :original_value_2
61
- expect { subject.foobar_2(:blah) }.to raise_error
62
-
63
- RR.reset
64
- end
65
-
66
- it "proxies via block without argument" do
67
- def subject.foobar_1(*args)
68
- :original_value_1
69
- end
70
-
71
- def subject.foobar_2
72
- :original_value_2
73
- end
74
-
75
- mock.proxy subject do
76
- foobar_1(1)
77
- foobar_2
78
- end
79
- expect(subject.foobar_1(1)).to eq :original_value_1
80
- expect { subject.foobar_1(:blah) }.to raise_error
81
-
82
- expect(subject.foobar_2).to eq :original_value_2
83
- expect { subject.foobar_2(:blah) }.to raise_error
84
-
85
- RR.reset
86
- end
87
-
88
- # bug #44
89
- describe 'when wrapped in an array that is then flattened' do
90
- subject {
91
- Object.new.tap do |o|
92
- def o.foo; end
93
- end
94
- }
95
-
96
- context 'when the method being mocked is not defined' do
97
- it "does not raise an error" do
98
- mock.proxy(subject).foo
99
- subject.foo
100
- expect([subject].flatten).to eq [subject]
101
- end
102
-
103
- it "honors a #to_ary that already exists" do
104
- subject.instance_eval do
105
- def to_ary; []; end
106
- end
107
- mock.proxy(subject).foo
108
- subject.foo
109
- expect([subject].flatten).to eq []
110
- end
111
- end
112
-
113
- context 'when the method being mocked is defined' do
114
- before do
115
- subject.instance_eval do
116
- def foo; end
117
- end
118
- end
119
-
120
- it "does not raise an error" do
121
- mock.proxy(subject).foo
122
- subject.foo
123
- expect([subject].flatten).to eq [subject]
124
- end
125
-
126
- it "honors a #to_ary that already exists" do
127
- eigen(subject).class_eval do
128
- def to_ary; []; end
129
- end
130
- mock.proxy(subject).foo
131
- subject.foo
132
- expect([subject].flatten).to eq []
133
- end
134
- end
135
- end
136
- end
@@ -1,41 +0,0 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
- describe '#spy' do
4
- subject { Object.new }
5
-
6
- it "should record all method invocations" do
7
- subject = Object.new
8
-
9
- def subject.something
10
- end
11
-
12
- def subject.something_else
13
- end
14
-
15
- spy(subject)
16
-
17
- subject.something
18
- subject.something_else
19
- subject.to_s
20
-
21
- received(subject).something.call
22
- received(subject).something_else.call
23
- received(subject).to_s.call
24
- end
25
-
26
- describe "RR recorded_calls" do
27
- it "should verify method calls after the fact" do
28
- stub(subject).pig_rabbit
29
- subject.pig_rabbit("bacon", "bunny meat")
30
- #expect(subject).to have_received.pig_rabitt("bacon", "bunny meat")
31
- received(subject).pig_rabbit("bacon", "bunny meat").call
32
- end
33
-
34
- it "should verify method calls after the fact" do
35
- stub(subject).pig_rabbit
36
- expect {
37
- received(subject).pig_rabbit("bacon", "bunny meat").call
38
- }.to raise_error(RR::Errors::SpyVerificationErrors::SpyVerificationError)
39
- end
40
- end
41
- end
@@ -1,79 +0,0 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
- class StrongSpecFixture
4
- def method_with_no_arguments
5
- end
6
-
7
- def method_with_one_argument(string)
8
- end
9
-
10
- def method_with_two_arguments(string, integer)
11
- end
12
-
13
- def method_with_three_arguments_including_varargs(string, integer, *args)
14
- end
15
-
16
- def method_with_varargs(*args)
17
- end
18
- end
19
-
20
- describe '#strong' do
21
- subject { Object.new }
22
-
23
- context "when the method does not exist" do
24
- it "raises an exception" do
25
- expect {
26
- strong.stub(StrongSpecFixture.new).something
27
- }.to raise_error(RR::Errors::SubjectDoesNotImplementMethodError)
28
- end
29
- end
30
-
31
- context "when the method exists with no arguments" do
32
- it "does not raise an exception" do
33
- strong.stub(StrongSpecFixture.new).method_with_no_arguments
34
- end
35
- end
36
-
37
- context "when the method has a different arity" do
38
- it "raises an exception" do
39
- expect {
40
- strong.stub(StrongSpecFixture.new).method_with_one_argument
41
- }.to raise_error(RR::Errors::SubjectHasDifferentArityError)
42
- end
43
- end
44
-
45
- context "when the method has accepts a variable number of arguments" do
46
- it "does not raise an exception" do
47
- strong.stub(StrongSpecFixture.new).method_with_varargs
48
- end
49
- end
50
-
51
- context "when the method does not provide the required parameters before varargs" do
52
- it "raises an exception" do
53
- expect {
54
- strong.stub(StrongSpecFixture.new).method_with_three_arguments_including_varargs
55
- }.to raise_error(RR::Errors::SubjectHasDifferentArityError)
56
- end
57
- end
58
-
59
- context "when the minimum number of parameters are provided" do
60
- it "does not raise an exception" do
61
- strong.stub(StrongSpecFixture.new).method_with_three_arguments_including_varargs("one", 2)
62
- end
63
- end
64
-
65
- context "when using instance_of and the method does not exist" do
66
- it "raises an exception" do
67
- expect {
68
- strong.stub.instance_of(StrongSpecFixture).something
69
- StrongSpecFixture.new
70
- }.to raise_error(RR::Errors::SubjectDoesNotImplementMethodError)
71
- end
72
- end
73
-
74
- context "when using instance_of and the method does exist" do
75
- it "does not raise an exception" do
76
- strong.stub.instance_of(StrongSpecFixture).method_with_no_arguments
77
- end
78
- end
79
- end
@@ -1,190 +0,0 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
- class StubSpecFixture
4
- attr_reader :initialize_arguments
5
-
6
- def initialize(*args)
7
- @initialize_arguments = args
8
- yield if block_given?
9
- method_run_in_initialize
10
- end
11
-
12
- def method_run_in_initialize
13
-
14
- end
15
- end
16
-
17
- describe '#stub' do
18
- subject { Object.new }
19
-
20
- it "creates a stub DoubleInjection Double" do
21
- stub(subject).foobar {:baz}
22
- expect(subject.foobar("any", "thing")).to eq :baz
23
- end
24
-
25
- it "stubs via inline call" do
26
- stub(subject).to_s {"a value"}
27
- expect(subject.to_s).to eq "a value"
28
- end
29
-
30
- describe ".once.ordered" do
31
- it "returns the values in the ordered called" do
32
- stub(subject).to_s {"value 1"}.once.ordered
33
- stub(subject).to_s {"value 2"}.once.ordered
34
-
35
- expect(subject.to_s).to eq "value 1"
36
- expect(subject.to_s).to eq "value 2"
37
- end
38
- end
39
-
40
- context "when the subject is a proxy for the object with the defined method" do
41
- it "stubs the method on the proxy object" do
42
- proxy_target = Class.new {def foobar; :original_foobar; end}.new
43
- proxy = Class.new do
44
- def initialize(target)
45
- @target = target
46
- end
47
-
48
- instance_methods.each do |m|
49
- unless m =~ /^_/ || m.to_s == 'object_id' || m.to_s == 'method_missing'
50
- alias_method "__blank_slated_#{m}", m
51
- undef_method m
52
- end
53
- end
54
-
55
- def method_missing(method_name, *args, &block)
56
- @target.send(method_name, *args, &block)
57
- end
58
- end.new(proxy_target)
59
- expect(proxy.methods).to match_array(proxy_target.methods)
60
-
61
- stub(proxy).foobar {:new_foobar}
62
- expect(proxy.foobar).to eq :new_foobar
63
- end
64
- end
65
-
66
- it "stubs via block with argument" do
67
- stub subject do |d|
68
- d.to_s {"a value"}
69
- d.to_sym {:crazy}
70
- end
71
- expect(subject.to_s).to eq "a value"
72
- expect(subject.to_sym).to eq :crazy
73
- end
74
-
75
- it "stubs via block without argument" do
76
- stub subject do
77
- to_s {"a value"}
78
- to_sym {:crazy}
79
- end
80
- expect(subject.to_s).to eq "a value"
81
- expect(subject.to_sym).to eq :crazy
82
- end
83
-
84
- it "stubs instance_of" do
85
- stub.instance_of(StubSpecFixture) do |o|
86
- o.to_s {"High Level Spec"}
87
- end
88
- expect(StubSpecFixture.new.to_s).to eq "High Level Spec"
89
- end
90
-
91
- it "stubs methods without letters" do
92
- stub(subject).__send__(:==) {:equality}
93
- expect((subject == 55)).to eq :equality
94
- end
95
-
96
- it "stubs methods invoked in #initialize while passing along the #initialize arg" do
97
- method_run_in_initialize_stubbed = false
98
- stub.instance_of(StubSpecFixture) do |o|
99
- o.method_run_in_initialize {method_run_in_initialize_stubbed = true}
100
- end
101
- StubSpecFixture.new
102
- expect(method_run_in_initialize_stubbed).to be_true
103
- end
104
-
105
- it "passed the arguments and block passed to #initialize" do
106
- block_called = false
107
- stub.instance_of(StubSpecFixture) do |o|
108
- o.method_run_in_initialize
109
- end
110
- instance = StubSpecFixture.new(1, 2) {block_called = true}
111
- expect(instance.initialize_arguments).to eq [1, 2]
112
- expect(block_called).to be_true
113
- end
114
-
115
- context "mock then stub" do
116
- it "stubs any calls not matching the mock" do
117
- mock(subject).foobar(3) {:baz3}
118
- stub(subject).foobar {:baz}
119
- expect(subject.foobar(3)).to eq :baz3
120
- expect(subject.foobar(4)).to eq :baz
121
- end
122
- end
123
-
124
- context "stub that yields" do
125
- context "when yields called without any arguments" do
126
- it "yields only once" do
127
- called_from_block = mock!.foo.once.subject
128
- block_caller = stub!.bar.yields.subject
129
- block_caller.bar { called_from_block.foo }
130
- end
131
- end
132
-
133
- context "when yields called with an argument" do
134
- it "yields only once" do
135
- called_from_block = mock!.foo(1).once.subject
136
- block_caller = stub!.bar.yields(1).subject
137
- block_caller.bar { |argument| called_from_block.foo(argument) }
138
- end
139
- end
140
-
141
- context "when yields calls are chained" do
142
- it "yields several times" do
143
- pending "This test is failing with a TimesCalledError"
144
-
145
- called_from_block = mock!.foo(1).once.then.foo(2).once.subject
146
- block_caller = stub!.bar.yields(1).yields(2).subject
147
- block_caller.bar { |argument| called_from_block.foo(argument) }
148
- end
149
- end
150
- end
151
-
152
- # bug #44
153
- describe 'when wrapped in an array that is then flattened' do
154
- context 'when the method being stubbed is not defined' do
155
- it "does not raise an error" do
156
- stub(subject).foo
157
- expect([subject].flatten).to eq [subject]
158
- end
159
-
160
- it "honors a #to_ary that already exists" do
161
- subject.instance_eval do
162
- def to_ary; []; end
163
- end
164
- stub(subject).foo
165
- expect([subject].flatten).to eq []
166
- end
167
- end
168
-
169
- context 'when the method being stubbed is defined' do
170
- before do
171
- subject.instance_eval do
172
- def foo; end
173
- end
174
- end
175
-
176
- it "does not raise an error" do
177
- stub(subject).foo
178
- expect([subject].flatten).to eq [subject]
179
- end
180
-
181
- it "honors a #to_ary that already exists" do
182
- eigen(subject).class_eval do
183
- def to_ary; []; end
184
- end
185
- stub(subject).foo
186
- expect([subject].flatten).to eq []
187
- end
188
- end
189
- end
190
- end
@@ -1,128 +0,0 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
- require 'ostruct'
3
-
4
- describe 'wildcard matchers' do
5
- subject { Object.new }
6
-
7
- describe '#anything' do
8
- it "works outside a container" do
9
- mock(subject).foo(anything)
10
- subject.foo(:whatever)
11
- end
12
-
13
- it "works within a container too" do
14
- mock(subject).foo([anything])
15
- subject.foo([:whatever])
16
- end
17
- end
18
-
19
- describe '#boolean' do
20
- it "works outside a container" do
21
- mock(subject).foo(boolean)
22
- subject.foo(false)
23
- end
24
-
25
- it "works within a container too" do
26
- mock(subject).foo([boolean])
27
- subject.foo([false])
28
- end
29
- end
30
-
31
- describe '#duck_type' do
32
- it "works outside a container" do
33
- mock(subject).foo(duck_type(:bar))
34
- subject.foo(OpenStruct.new(:bar => 3))
35
- end
36
-
37
- it "works within a container too" do
38
- mock(subject).foo([duck_type(:bar)])
39
- subject.foo([OpenStruct.new(:bar => 3)])
40
- end
41
- end
42
-
43
- describe '#hash_including' do
44
- it "works outside a container" do
45
- mock(subject).foo(hash_including(:c => 'd'))
46
- subject.foo(:a => 'b', :c => 'd')
47
- end
48
-
49
- it "works within a container too" do
50
- mock(subject).foo([hash_including(:c => 'd')])
51
- subject.foo([{:a => 'b', :c => 'd'}])
52
- end
53
- end
54
-
55
- describe '#is_a' do
56
- context 'when outside a container' do
57
- it "matches a simple value" do
58
- mock(subject).foo(is_a(Symbol))
59
- subject.foo(:symbol)
60
- end
61
-
62
- it "matches a container value" do
63
- mock(subject).foo(is_a(Array))
64
- subject.foo(['x', 'y'])
65
- end
66
- end
67
-
68
- context 'within a container' do
69
- it "matches a simple value" do
70
- mock(subject).foo([is_a(Symbol)])
71
- subject.foo([:symbol])
72
- end
73
-
74
- it "matches a container" do
75
- mock(subject).foo([is_a(Hash)])
76
- subject.foo([{:x => 'y'}])
77
- end
78
- end
79
- end
80
-
81
- describe '#numeric' do
82
- it "works outside a container" do
83
- mock(subject).foo(numeric)
84
- subject.foo(3)
85
- end
86
-
87
- it "works within a container too" do
88
- mock(subject).foo([numeric])
89
- subject.foo([3])
90
- end
91
- end
92
-
93
- describe 'range' do
94
- it "works outside a container" do
95
- mock(subject).foo(1..5)
96
- subject.foo(3)
97
- end
98
-
99
- it "works within a container too" do
100
- mock(subject).foo([1..5])
101
- subject.foo([3])
102
- end
103
- end
104
-
105
- describe 'regexp' do
106
- it "works outside a container" do
107
- mock(subject).foo(/foo/)
108
- subject.foo('foobar')
109
- end
110
-
111
- it "works within a container too" do
112
- mock(subject).foo([/foo/])
113
- subject.foo(['foobar'])
114
- end
115
- end
116
-
117
- describe '#satisfy' do
118
- it "works outside a container" do
119
- mock(subject).foo(satisfy {|x| x == 'x' })
120
- subject.foo('x')
121
- end
122
-
123
- it "works within a container too" do
124
- mock(subject).foo([satisfy {|x| x == 'x' }])
125
- subject.foo(['x'])
126
- end
127
- end
128
- end