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,37 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
-
3
- module RR
4
- module Expectations
5
- describe TimesCalledExpectation do
6
- context "when using an AtLeastMatcher" do
7
- include_examples "RR::Expectations::TimesCalledExpectation"
8
-
9
- before do
10
- mock(subject).foobar.at_least(3)
11
- end
12
-
13
- describe "#verify!" do
14
- it "passes when times called > times" do
15
- 4.times {subject.foobar}
16
- RR.verify
17
- end
18
-
19
- it "passes when times called == times" do
20
- 3.times {subject.foobar}
21
- RR.verify
22
- end
23
-
24
- it "raises error when times called < times" do
25
- subject.foobar
26
- expect {
27
- RR.verify
28
- }.to raise_error(
29
- RR::Errors::TimesCalledError,
30
- "foobar()\nCalled 1 time.\nExpected at least 3 times."
31
- )
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,43 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
-
3
- module RR
4
- module Expectations
5
- describe TimesCalledExpectation do
6
- context "when using an AtMostMatcher" do
7
- include_examples "RR::Expectations::TimesCalledExpectation"
8
-
9
- before do
10
- stub(subject).foobar.at_most(3)
11
- end
12
-
13
- describe "#verify!" do
14
- it "passes when times called == times" do
15
- 3.times {subject.foobar}
16
- RR.verify
17
- end
18
-
19
- it "passes when times called < times" do
20
- 2.times {subject.foobar}
21
- RR.verify
22
- end
23
-
24
- it "raises error when times called > times" do
25
- expect {
26
- 4.times {subject.foobar}
27
- }.to raise_error(
28
- RR::Errors::TimesCalledError,
29
- "foobar()\nCalled 4 times.\nExpected at most 3 times."
30
- )
31
-
32
- expect {
33
- RR.verify
34
- }.to raise_error(
35
- RR::Errors::TimesCalledError,
36
- "foobar()\nCalled 4 times.\nExpected at most 3 times."
37
- )
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,58 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
-
3
- module RR
4
- module Expectations
5
- describe TimesCalledExpectation do
6
- context "when using an IntegerMatcher" do
7
- include_examples "RR::Expectations::TimesCalledExpectation"
8
-
9
- before do
10
- stub(subject).foobar.times(2)
11
- end
12
-
13
- describe "verify" do
14
- it "passes after attempt! called 2 times" do
15
- subject.foobar
16
- subject.foobar
17
- RR.verify
18
- end
19
-
20
- it "fails after attempt! called 1 time" do
21
- subject.foobar
22
- expect { RR.verify }.to raise_error(
23
- RR::Errors::TimesCalledError,
24
- "foobar()\nCalled 1 time.\nExpected 2 times."
25
- )
26
- end
27
-
28
- it "can't be called when attempt! is called 3 times" do
29
- subject.foobar
30
- subject.foobar
31
- expect {
32
- subject.foobar
33
- }.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
34
- expect {
35
- RR.verify
36
- }.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
37
- end
38
-
39
- it "has a backtrace to where the TimesCalledExpectation was instantiated on failure" do
40
- error = nil
41
- begin
42
- RR.verify
43
- rescue RR::Errors::TimesCalledError => e
44
- error = e
45
- end
46
- expect(e.backtrace.join("\n")).to include(__FILE__)
47
- end
48
-
49
- it "has an error message that includes the number of times called and expected number of times" do
50
- expect {
51
- RR.verify
52
- }.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 0 times.\nExpected 2 times.")
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,35 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
-
3
- module RR
4
- module Expectations
5
- describe TimesCalledExpectation do
6
- context "when using a ProcMatcher" do
7
- include_examples "RR::Expectations::TimesCalledExpectation"
8
-
9
- before do
10
- stub(subject).foobar.times(lambda {|value| value == 2})
11
- end
12
-
13
- describe "#verify" do
14
- it "passes after attempt! called 2 times" do
15
- subject.foobar
16
- subject.foobar
17
- RR.verify
18
- end
19
-
20
- it "fails after attempt! called 1 time" do
21
- subject.foobar
22
- expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
23
- end
24
-
25
- it "fails after attempt! called 3 times" do
26
- subject.foobar
27
- subject.foobar
28
- subject.foobar
29
- expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,39 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
-
3
- module RR
4
- module Expectations
5
- describe TimesCalledExpectation do
6
- context "when using a RangeMatcher" do
7
- include_examples "RR::Expectations::TimesCalledExpectation"
8
-
9
- before do
10
- stub(subject).foobar.times(1..2)
11
- end
12
-
13
- describe "#verify" do
14
- it "passes after attempt! called 1 time" do
15
- subject.foobar
16
- RR.verify
17
- end
18
-
19
- it "passes after attempt! called 2 times" do
20
- subject.foobar
21
- subject.foobar
22
- RR.verify
23
- end
24
-
25
- it "can't be called when attempt! is called 3 times" do
26
- subject.foobar
27
- subject.foobar
28
- expect {
29
- subject.foobar
30
- }.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 1..2 times.")
31
- expect {
32
- RR.verify
33
- }.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 1..2 times.")
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,88 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
-
3
- module RR
4
- describe HashWithObjectIdKey do
5
- describe "#[] and #[]=" do
6
- it "stores object via object id" do
7
- hash = HashWithObjectIdKey.new
8
- array_1 = []
9
- hash[array_1] = 1
10
- array_2 = []
11
- hash[array_2] = 2
12
-
13
- expect(hash[array_1]).to_not eq hash[array_2]
14
- end
15
-
16
- it "stores the passed in object" do
17
- hash = HashWithObjectIdKey.new
18
- obj = Object.new
19
- hash[obj] = 1
20
- expect(hash.instance_eval {@keys}).to eq({obj.__id__ => obj})
21
- end
22
- end
23
-
24
- describe "#each" do
25
- it "iterates through the items in the hash" do
26
- hash = HashWithObjectIdKey.new
27
- hash['one'] = 1
28
- hash['two'] = 2
29
-
30
- keys = []
31
- values = []
32
- hash.each do |key, value|
33
- keys << key
34
- values << value
35
- end
36
-
37
- expect(keys.sort).to eq ['one', 'two']
38
- expect(values.sort).to eq [1, 2]
39
- end
40
- end
41
-
42
- describe "#delete" do
43
- before do
44
- @hash = HashWithObjectIdKey.new
45
- @key = Object.new
46
- @hash[@key] = 1
47
- end
48
-
49
- it "removes the object from the hash" do
50
- @hash.delete(@key)
51
- expect(@hash[@key]).to be_nil
52
- end
53
-
54
- it "removes the object from the keys hash" do
55
- @hash.delete(@key)
56
- expect(@hash.instance_eval { @keys }).to eq({})
57
- end
58
- end
59
-
60
- describe "#keys" do
61
- before do
62
- @hash = HashWithObjectIdKey.new
63
- @key = Object.new
64
- @hash[@key] = 1
65
- end
66
-
67
- it "returns an array of the keys" do
68
- expect(@hash.keys).to eq [@key]
69
- end
70
- end
71
-
72
- describe "#include?" do
73
- before do
74
- @hash = HashWithObjectIdKey.new
75
- @key = Object.new
76
- @hash[@key] = 1
77
- end
78
-
79
- it "returns true when the key is in the Hash" do
80
- expect(@hash.include?(@key)).to be_true
81
- end
82
-
83
- it "returns false when the key is not in the Hash" do
84
- expect(@hash.include?(Object.new)).to be_false
85
- end
86
- end
87
- end
88
- end
@@ -1,545 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
-
3
- module RR
4
- module Injections
5
- describe DoubleInjection do
6
- attr_reader :method_name, :double_injection
7
-
8
- macro("sets up subject and method_name") do
9
- it "sets up subject and method_name" do
10
- expect(double_injection.subject).to equal subject
11
- expect(double_injection.method_name).to eq method_name.to_sym
12
- end
13
- end
14
-
15
- subject { Object.new }
16
-
17
- describe "mock/stub" do
18
- context "when the subject responds to the injected method" do
19
- before do
20
- class << subject
21
- attr_reader :original_foobar_called
22
-
23
- def foobar
24
- @original_foobar_called = true
25
- :original_foobar
26
- end
27
- end
28
-
29
- expect(subject).to respond_to(:foobar)
30
- expect(!!subject.methods.detect {|method| method.to_sym == :foobar}).to be_true
31
- stub(subject).foobar {:new_foobar}
32
- end
33
-
34
- describe "being bound" do
35
- it "sets __rr__original_{method_name} to the original method" do
36
- expect(subject.__rr__original_foobar).to eq :original_foobar
37
- end
38
-
39
- describe "being called" do
40
- it "returns the return value of the block" do
41
- expect(subject.foobar).to eq :new_foobar
42
- end
43
-
44
- it "does not call the original method" do
45
- subject.foobar
46
- expect(subject.original_foobar_called).to be_nil
47
- end
48
- end
49
-
50
- describe "being reset" do
51
- before do
52
- RR::Space.reset_double(subject, :foobar)
53
- end
54
-
55
- it "rebinds the original method" do
56
- expect(subject.foobar).to eq :original_foobar
57
- end
58
-
59
- it "removes __rr__original_{method_name}" do
60
- subject.should_not respond_to(:__rr__original_foobar)
61
- end
62
- end
63
- end
64
- end
65
-
66
- context "when the subject does not respond to the injected method" do
67
- before do
68
- subject.should_not respond_to(:foobar)
69
- subject.methods.should_not include('foobar')
70
- stub(subject).foobar {:new_foobar}
71
- end
72
-
73
- it "does not set __rr__original_{method_name} to the original method" do
74
- subject.should_not respond_to(:__rr__original_foobar)
75
- end
76
-
77
- describe "being called" do
78
- it "calls the newly defined method" do
79
- expect(subject.foobar).to eq :new_foobar
80
- end
81
- end
82
-
83
- describe "being reset" do
84
- before do
85
- RR::Space.reset_double(subject, :foobar)
86
- end
87
-
88
- it "unsets the foobar method" do
89
- subject.should_not respond_to(:foobar)
90
- subject.methods.should_not include('foobar')
91
- end
92
- end
93
- end
94
-
95
- context "when the subject redefines respond_to?" do
96
- it "does not try to call the implementation" do
97
- class << subject
98
- def respond_to?(method_symbol, include_private = false)
99
- method_symbol == :foobar
100
- end
101
- end
102
- mock(subject).foobar
103
- expect(subject.foobar).to eq nil
104
- end
105
- end
106
- end
107
-
108
- describe "mock/stub + proxy" do
109
- context "when the subject responds to the injected method" do
110
- context "when the subject has the method defined" do
111
- describe "being bound" do
112
- before do
113
- def subject.foobar
114
- :original_foobar
115
- end
116
-
117
- expect(subject).to respond_to(:foobar)
118
- expect(!!subject.methods.detect {|method| method.to_sym == :foobar}).to be_true
119
- stub.proxy(subject).foobar {:new_foobar}
120
- end
121
-
122
- it "aliases the original method to __rr__original_{method_name}" do
123
- expect(subject.__rr__original_foobar).to eq :original_foobar
124
- end
125
-
126
- it "replaces the original method with the new method" do
127
- expect(subject.foobar).to eq :new_foobar
128
- end
129
-
130
- describe "being called" do
131
- it "calls the original method first and sends it into the block" do
132
- original_return_value = nil
133
- stub.proxy(subject).foobar {|arg| original_return_value = arg; :new_foobar}
134
- expect(subject.foobar).to eq :new_foobar
135
- expect(original_return_value).to eq :original_foobar
136
- end
137
- end
138
-
139
- describe "being reset" do
140
- before do
141
- RR::Space.reset_double(subject, :foobar)
142
- end
143
-
144
- it "rebinds the original method" do
145
- expect(subject.foobar).to eq :original_foobar
146
- end
147
-
148
- it "removes __rr__original_{method_name}" do
149
- subject.should_not respond_to(:__rr__original_foobar)
150
- end
151
- end
152
- end
153
- end
154
-
155
- context "when the subject does not have the method defined" do
156
- describe "being bound" do
157
- context "when the subject has not been previously bound to" do
158
- before do
159
- setup_subject
160
-
161
- expect(subject).to respond_to(:foobar)
162
- stub.proxy(subject).foobar {:new_foobar}
163
- end
164
-
165
- def setup_subject
166
- def subject.respond_to?(method_name)
167
- if method_name.to_sym == :foobar
168
- true
169
- else
170
- super
171
- end
172
- end
173
- end
174
-
175
- it "does not define __rr__original_{method_name}" do
176
- subject.methods.should_not include("__rr__original_foobar")
177
- end
178
-
179
- context "when method is defined after being bound and before being called" do
180
- def setup_subject
181
- super
182
- def subject.foobar
183
- :original_foobar
184
- end
185
- end
186
-
187
- describe "being called" do
188
- it "defines __rr__original_{method_name} to be the lazily created method" do
189
- expect((!!subject.methods.detect {|method| method.to_sym == :__rr__original_foobar})).to be_true
190
- expect(subject.__rr__original_foobar).to eq :original_foobar
191
- end
192
-
193
- it "calls the original method first and sends it into the block" do
194
- original_return_value = nil
195
- stub.proxy(subject).foobar {|arg| original_return_value = arg; :new_foobar}
196
- expect(subject.foobar).to eq :new_foobar
197
- expect(original_return_value).to eq :original_foobar
198
- end
199
- end
200
-
201
- describe "being reset" do
202
- before do
203
- RR::Space.reset_double(subject, :foobar)
204
- end
205
-
206
- it "rebinds the original method" do
207
- expect(subject.foobar).to eq :original_foobar
208
- end
209
-
210
- it "removes __rr__original_{method_name}" do
211
- subject.should_not respond_to(:__rr__original_foobar)
212
- end
213
- end
214
- end
215
-
216
- context "when method is still not defined" do
217
- context "when the method is lazily created" do
218
- def setup_subject
219
- super
220
- def subject.method_missing(method_name, *args, &block)
221
- if method_name.to_sym == :foobar
222
- def self.foobar
223
- :original_foobar
224
- end
225
-
226
- foobar
227
- else
228
- super
229
- end
230
- end
231
- end
232
-
233
- describe "being called" do
234
- it "defines __rr__original_{method_name} to be the lazily created method" do
235
- subject.foobar
236
- expect((!!subject.methods.detect {|method| method.to_sym == :__rr__original_foobar})).to be_true
237
- expect(subject.__rr__original_foobar).to eq :original_foobar
238
- end
239
-
240
- it "calls the lazily created method and returns the injected method return value" do
241
- original_return_value = nil
242
- stub.proxy(subject).foobar {|arg| original_return_value = arg; :new_foobar}
243
- expect(subject.foobar).to eq :new_foobar
244
- expect(original_return_value).to eq :original_foobar
245
- end
246
- end
247
-
248
- describe "being reset" do
249
- context "when reset before being called" do
250
- before do
251
- RR::Space.reset_double(subject, :foobar)
252
- end
253
-
254
- it "rebinds the original method" do
255
- expect(subject.foobar).to eq :original_foobar
256
- end
257
-
258
- it "removes __rr__original_{method_name}" do
259
- subject.should_not respond_to(:__rr__original_foobar)
260
- end
261
- end
262
- end
263
- end
264
-
265
- context "when the method is not lazily created (handled in method_missing)" do
266
- def setup_subject
267
- super
268
- def subject.method_missing(method_name, *args, &block)
269
- if method_name.to_sym == :foobar
270
- :original_foobar
271
- else
272
- super
273
- end
274
- end
275
- end
276
-
277
- describe "being called" do
278
- it "does not define the __rr__original_{method_name}" do
279
- subject.foobar
280
- subject.methods.should_not include("__rr__original_foobar")
281
- end
282
-
283
- it "calls the lazily created method and returns the injected method return value" do
284
- original_return_value = nil
285
- stub.proxy(subject).foobar {|arg| original_return_value = arg; :new_foobar}
286
- expect(subject.foobar).to eq :new_foobar
287
- expect(original_return_value).to eq :original_foobar
288
- end
289
- end
290
-
291
- describe "being reset" do
292
- before do
293
- RR::Space.reset_double(subject, :foobar)
294
- end
295
-
296
- it "rebinds the original method" do
297
- expect(subject.foobar).to eq :original_foobar
298
- end
299
-
300
- it "removes __rr__original_{method_name}" do
301
- subject.should_not respond_to(:__rr__original_foobar)
302
- end
303
- end
304
- end
305
- end
306
- end
307
-
308
- context "when the subject has been previously bound to" do
309
- before do
310
- setup_subject
311
-
312
- expect(subject).to respond_to(:foobar)
313
- stub.proxy(subject).baz {:new_baz}
314
- stub.proxy(subject).foobar {:new_foobar}
315
- end
316
-
317
- def setup_subject
318
- def subject.respond_to?(method_name)
319
- if method_name.to_sym == :foobar || method_name.to_sym == :baz
320
- true
321
- else
322
- super
323
- end
324
- end
325
- end
326
-
327
- it "does not define __rr__original_{method_name}" do
328
- subject.methods.should_not include("__rr__original_foobar")
329
- end
330
-
331
- context "when method is defined after being bound and before being called" do
332
- def setup_subject
333
- super
334
- def subject.foobar
335
- :original_foobar
336
- end
337
- end
338
-
339
- describe "being called" do
340
- it "defines __rr__original_{method_name} to be the lazily created method" do
341
- expect((!!subject.methods.detect {|method| method.to_sym == :__rr__original_foobar})).to be_true
342
- expect(subject.__rr__original_foobar).to eq :original_foobar
343
- end
344
-
345
- it "calls the original method first and sends it into the block" do
346
- original_return_value = nil
347
- stub.proxy(subject).foobar {|arg| original_return_value = arg; :new_foobar}
348
- expect(subject.foobar).to eq :new_foobar
349
- expect(original_return_value).to eq :original_foobar
350
- end
351
- end
352
-
353
- describe "being reset" do
354
- before do
355
- RR::Space.reset_double(subject, :foobar)
356
- end
357
-
358
- it "rebinds the original method" do
359
- expect(subject.foobar).to eq :original_foobar
360
- end
361
-
362
- it "removes __rr__original_{method_name}" do
363
- subject.should_not respond_to(:__rr__original_foobar)
364
- end
365
- end
366
- end
367
-
368
- context "when method is still not defined" do
369
- context "when the method is lazily created" do
370
- def setup_subject
371
- super
372
- def subject.method_missing(method_name, *args, &block)
373
- if method_name.to_sym == :foobar
374
- def self.foobar
375
- :original_foobar
376
- end
377
-
378
- foobar
379
- else
380
- super
381
- end
382
- end
383
- end
384
-
385
- describe "being called" do
386
- it "defines __rr__original_{method_name} to be the lazily created method" do
387
- subject.foobar
388
- expect((!!subject.methods.detect {|method| method.to_sym == :__rr__original_foobar})).to be_true
389
- expect(subject.__rr__original_foobar).to eq :original_foobar
390
- end
391
-
392
- it "calls the lazily created method and returns the injected method return value" do
393
- original_return_value = nil
394
- stub.proxy(subject).foobar {|arg| original_return_value = arg; :new_foobar}
395
- expect(subject.foobar).to eq :new_foobar
396
- expect(original_return_value).to eq :original_foobar
397
- end
398
- end
399
-
400
- describe "being reset" do
401
- context "when reset before being called" do
402
- before do
403
- RR::Space.reset_double(subject, :foobar)
404
- end
405
-
406
- it "rebinds the original method" do
407
- expect(subject.foobar).to eq :original_foobar
408
- end
409
-
410
- it "removes __rr__original_{method_name}" do
411
- subject.should_not respond_to(:__rr__original_foobar)
412
- end
413
- end
414
- end
415
- end
416
-
417
- context "when the method is not lazily created (handled in method_missing)" do
418
- def setup_subject
419
- super
420
- def subject.method_missing(method_name, *args, &block)
421
- if method_name.to_sym == :foobar
422
- :original_foobar
423
- else
424
- super
425
- end
426
- end
427
- end
428
-
429
- describe "being called" do
430
- it "does not define the __rr__original_{method_name}" do
431
- subject.foobar
432
- subject.methods.should_not include("__rr__original_foobar")
433
- end
434
-
435
- it "calls the lazily created method and returns the injected method return value" do
436
- original_return_value = nil
437
- stub.proxy(subject).foobar {|arg| original_return_value = arg; :new_foobar}
438
- expect(subject.foobar).to eq :new_foobar
439
- expect(original_return_value).to eq :original_foobar
440
- end
441
- end
442
-
443
- describe "being reset" do
444
- before do
445
- RR::Space.reset_double(subject, :foobar)
446
- end
447
-
448
- it "rebinds the original method" do
449
- expect(subject.foobar).to eq :original_foobar
450
- end
451
-
452
- it "removes __rr__original_{method_name}" do
453
- subject.should_not respond_to(:__rr__original_foobar)
454
- end
455
- end
456
- end
457
- end
458
- end
459
- end
460
- end
461
- end
462
-
463
- context "when the subject does not respond to the injected method" do
464
- context "when the subject responds to the method via method_missing" do
465
- describe "being bound" do
466
- before do
467
- subject.should_not respond_to(:foobar)
468
- subject.methods.should_not include('foobar')
469
- class << subject
470
- def method_missing(method_name, *args, &block)
471
- if method_name == :foobar
472
- :original_foobar
473
- else
474
- super
475
- end
476
- end
477
- end
478
- stub.proxy(subject).foobar {:new_foobar}
479
- end
480
-
481
- it "adds the method to the subject" do
482
- expect(subject).to respond_to(:foobar)
483
- expect((!!subject.methods.detect {|method| method.to_sym == :foobar})).to be_true
484
- end
485
-
486
- describe "being called" do
487
- it "calls the original method first and sends it into the block" do
488
- original_return_value = nil
489
- stub.proxy(subject).foobar {|arg| original_return_value = arg; :new_foobar}
490
- expect(subject.foobar).to eq :new_foobar
491
- expect(original_return_value).to eq :original_foobar
492
- end
493
- end
494
-
495
- describe "being reset" do
496
- before do
497
- RR::Space.reset_double(subject, :foobar)
498
- end
499
-
500
- it "unsets the foobar method" do
501
- subject.should_not respond_to(:foobar)
502
- subject.methods.should_not include('foobar')
503
- end
504
- end
505
- end
506
- end
507
-
508
- context "when the subject would raise a NoMethodError when the method is called" do
509
- describe "being bound" do
510
- before do
511
- subject.should_not respond_to(:foobar)
512
- subject.methods.should_not include('foobar')
513
- stub.proxy(subject).foobar {:new_foobar}
514
- end
515
-
516
- it "adds the method to the subject" do
517
- expect(subject).to respond_to(:foobar)
518
- expect((!!subject.methods.detect {|method| method.to_sym == :foobar})).to be_true
519
- end
520
-
521
- describe "being called" do
522
- it "raises a NoMethodError" do
523
- expect {
524
- subject.foobar
525
- }.to raise_error(NoMethodError)
526
- end
527
- end
528
-
529
- describe "being reset" do
530
- before do
531
- RR::Space.reset_double(subject, :foobar)
532
- end
533
-
534
- it "unsets the foobar method" do
535
- subject.should_not respond_to(:foobar)
536
- subject.methods.should_not include('foobar')
537
- end
538
- end
539
- end
540
- end
541
- end
542
- end
543
- end
544
- end
545
- end