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,41 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
-
3
- describe Range do
4
- include WildcardMatcherMatchers
5
-
6
- describe '#wildcard_match?' do
7
- subject { 1..5 }
8
-
9
- it "returns true when given Range is exactly equal to this Range" do
10
- should wildcard_match(1..5)
11
- end
12
-
13
- it "returns true when given number falls within the range" do
14
- should wildcard_match(3)
15
- end
16
-
17
- it "returns false when given number falls outside the range" do
18
- should_not wildcard_match(8)
19
- end
20
- end
21
-
22
- describe '#==' do
23
- subject { 1..5 }
24
-
25
- it "returns true when given Range is exactly equal to this Range" do
26
- should equal_match(1..5)
27
- end
28
-
29
- it "returns false when given Range is not exactly equal to this Range" do
30
- should_not equal_match(3..5)
31
- end
32
-
33
- it "returns false even when given an object that wildcard matches this Range" do
34
- should_not equal_match(3)
35
- end
36
-
37
- it "returns false when given object isn't even a Range" do
38
- should_not equal_match(:something_else)
39
- end
40
- end
41
- end
@@ -1,41 +0,0 @@
1
- require File.expand_path('../../../spec_helper', __FILE__)
2
-
3
- describe Regexp do
4
- include WildcardMatcherMatchers
5
-
6
- describe '#wildcard_match?' do
7
- subject { /foo/ }
8
-
9
- it "returns true when given Regexp is exactly equal to this Regexp" do
10
- should wildcard_match(/foo/)
11
- end
12
-
13
- it "returns true if given string matches the regexp" do
14
- should wildcard_match('foobarbaz')
15
- end
16
-
17
- it "returns false if given string does not match the regexp" do
18
- should_not wildcard_match('aslkj')
19
- end
20
- end
21
-
22
- describe '#==' do
23
- subject { /foo/ }
24
-
25
- it "returns true when given Regexp is exactly equal to this Regexp" do
26
- should equal_match(/foo/)
27
- end
28
-
29
- it "returns false when given Regexp is not exactly equal to this Regexp" do
30
- should_not equal_match(/alkj/)
31
- end
32
-
33
- it "returns false even when given an object that wildcard matches this Regexp" do
34
- should_not equal_match('foobarbaz')
35
- end
36
-
37
- it "returns false when not even given a Regexp" do
38
- should_not equal_match(:something_else)
39
- end
40
- end
41
- end
@@ -1,114 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
-
3
- module RR
4
- module DoubleDefinitions
5
- describe ChildDoubleDefinitionCreate do
6
- attr_reader :parent_subject, :parent_double_definition_create, :parent_double_definition, :child_double_definition_create
7
-
8
- include_examples "Swapped Space"
9
-
10
- before(:each) do
11
- @parent_subject = Object.new
12
- @parent_double_definition_create = DoubleDefinitionCreate.new
13
- @parent_double_definition = DoubleDefinition.new(parent_double_definition_create)
14
- @child_double_definition_create = ChildDoubleDefinitionCreate.new(parent_double_definition)
15
- end
16
-
17
- describe "#root_subject" do
18
- it "returns the #parent_double_definition.root_subject" do
19
- child_subject = Object.new
20
- parent_double_definition_create.stub(parent_subject)
21
- child_double_definition_create.stub(child_subject)
22
- expect(child_double_definition_create.root_subject).to eq parent_subject
23
- end
24
- end
25
-
26
- describe "Strategies::Verification definitions" do
27
- describe "methods without !" do
28
- attr_reader :child_subject
29
- before do
30
- @child_subject = Object.new
31
- end
32
-
33
- describe "#mock" do
34
- context "when passed a subject" do
35
- it "sets #parent_double_definition.implementation to a Proc returning the passed-in subject" do
36
- expect(parent_double_definition.implementation).to be_nil
37
- child_double_definition_create.mock(child_subject)
38
- expect(parent_double_definition.implementation.call).to eq child_subject
39
- end
40
- end
41
- end
42
-
43
- describe "#stub" do
44
- context "when passed a subject" do
45
- it "sets #parent_double_definition.implementation to a Proc returning the passed-in subject" do
46
- expect(parent_double_definition.implementation).to be_nil
47
- child_double_definition_create.stub(child_subject)
48
- expect(parent_double_definition.implementation.call).to eq child_subject
49
- end
50
- end
51
- end
52
-
53
- describe "#dont_allow" do
54
- context "when passed a subject" do
55
- it "sets #parent_double_definition.implementation to a Proc returning the passed-in subject" do
56
- expect(parent_double_definition.implementation).to be_nil
57
- child_double_definition_create.dont_allow(child_subject)
58
- expect(parent_double_definition.implementation.call).to eq child_subject
59
- end
60
- end
61
- end
62
- end
63
-
64
- describe "methods with !" do
65
- describe "#mock!" do
66
- it "sets #parent_double_definition.implementation to a Proc returning the #subject" do
67
- expect(parent_double_definition.implementation).to be_nil
68
- child_subject = child_double_definition_create.mock!.__double_definition_create__.subject
69
- expect(parent_double_definition.implementation.call).to eq child_subject
70
- end
71
- end
72
-
73
- describe "#stub!" do
74
- it "sets #parent_double_definition.implementation to a Proc returning the #subject" do
75
- expect(parent_double_definition.implementation).to be_nil
76
- child_subject = child_double_definition_create.stub!.__double_definition_create__.subject
77
- expect(parent_double_definition.implementation.call).to eq child_subject
78
- end
79
- end
80
-
81
- describe "#dont_allow!" do
82
- it "sets #parent_double_definition.implementation to a Proc returning the #subject" do
83
- expect(parent_double_definition.implementation).to be_nil
84
- child_subject = child_double_definition_create.dont_allow!.__double_definition_create__.subject
85
- expect(parent_double_definition.implementation.call).to eq child_subject
86
- end
87
- end
88
- end
89
- end
90
-
91
- describe "Strategies::DoubleInjection definitions" do
92
- describe "methods without !" do
93
- describe "#instance_of" do
94
- it "raises a NoMethodError" do
95
- expect {
96
- child_double_definition_create.instance_of
97
- }.to raise_error(NoMethodError)
98
- end
99
- end
100
- end
101
-
102
- describe "methods with !" do
103
- describe "#instance_of!" do
104
- it "raises a NoMethodError" do
105
- expect {
106
- child_double_definition_create.instance_of!
107
- }.to raise_error(NoMethodError)
108
- end
109
- end
110
- end
111
- end
112
- end
113
- end
114
- end
@@ -1,93 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
-
3
- module RR
4
- module DoubleDefinitions
5
- describe DoubleDefinitionCreateBlankSlate do
6
- attr_reader :double_definition_create, :blank_slate
7
-
8
- include_examples "Swapped Space"
9
-
10
- subject { Object.new }
11
-
12
- before(:each) do
13
- @double_definition_create = DoubleDefinitionCreate.new
14
- double_definition_create.mock(subject)
15
- end
16
-
17
- describe ".new" do
18
- it "does not undefine object_id" do
19
- blank_slate = DoubleDefinitionCreateBlankSlate.new(double_definition_create)
20
- expect(blank_slate.object_id.class).to eq Fixnum
21
- end
22
-
23
- context "without block" do
24
- before do
25
- @blank_slate = DoubleDefinitionCreateBlankSlate.new(double_definition_create)
26
- end
27
-
28
- it "clears out all methods from proxy" do
29
- expect(stub(subject).i_should_be_a_double).to be_instance_of(DoubleDefinition)
30
- end
31
- end
32
-
33
- context "when passed a block" do
34
- context "when the block has an arity of 1" do
35
- attr_reader :passed_in_argument
36
- before do
37
- passed_in_argument = nil
38
- stub(subject) do |b|
39
- passed_in_argument = b
40
- b.foobar(1, 2) {:one_two}
41
- b.foobar(1) {:one}
42
- b.foobar.with_any_args {:default}
43
- b.baz() {:baz_result}
44
- end
45
- @passed_in_argument = passed_in_argument
46
- end
47
-
48
- it "creates double_injections" do
49
- expect(subject.foobar(1, 2)).to eq :one_two
50
- expect(subject.foobar(1)).to eq :one
51
- expect(subject.foobar(:something)).to eq :default
52
- expect(subject.baz).to eq :baz_result
53
- end
54
-
55
- it "passes the self into the block" do
56
- expect(passed_in_argument.__double_definition_create__).to be_instance_of(
57
- ::RR::DoubleDefinitions::DoubleDefinitionCreate
58
- )
59
- end
60
- end
61
-
62
- context "when the block has an arity of 0" do
63
- attr_reader :self_value
64
- before do
65
- self_value = nil
66
- stub(subject) do ||
67
- self_value = self
68
- foobar(1, 2) {:one_two}
69
- foobar(1) {:one}
70
- foobar.with_any_args {:default}
71
- baz() {:baz_result}
72
- end
73
- @self_value = self_value
74
- end
75
-
76
- it "creates double_injections" do
77
- expect(subject.foobar(1, 2)).to eq :one_two
78
- expect(subject.foobar(1)).to eq :one
79
- expect(subject.foobar(:something)).to eq :default
80
- expect(subject.baz).to eq :baz_result
81
- end
82
-
83
- it "evaluates the block with the context of self" do
84
- expect(self_value.__double_definition_create__).to be_instance_of(
85
- ::RR::DoubleDefinitions::DoubleDefinitionCreate
86
- )
87
- end
88
- end
89
- end
90
- end
91
- end
92
- end
93
- end
@@ -1,446 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
-
3
- module RR
4
- module DoubleDefinitions
5
- describe DoubleDefinitionCreate do
6
- subject { Object.new }
7
-
8
- attr_reader :double_definition_create, :strategy_method_name
9
-
10
- include_examples "Swapped Space"
11
-
12
- before(:each) do
13
- @double_definition_create = DoubleDefinitionCreate.new
14
- end
15
-
16
- describe "#root_subject" do
17
- it "returns #subject" do
18
- double_definition_create.stub(subject).foobar
19
- expect(double_definition_create.root_subject).to eq subject
20
- end
21
- end
22
-
23
- describe "StrategySetupMethods" do
24
- describe "normal strategy definitions" do
25
- def call_strategy(*args, &block)
26
- double_definition_create.__send__(strategy_method_name, *args, &block)
27
- end
28
-
29
- describe "#mock" do
30
- before do
31
- @strategy_method_name = :mock
32
- end
33
-
34
- context "when passing no args" do
35
- it "returns self" do
36
- expect(call_strategy).to equal double_definition_create
37
- end
38
- end
39
-
40
- context "when passed a subject and a method_name argument" do
41
- it "creates a mock Double for method" do
42
- double_definition = double_definition_create.mock(subject, :foobar).returns {:baz}
43
- expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::IntegerMatcher.new(1)
44
- expect(double_definition.argument_expectation.class).to eq RR::Expectations::ArgumentEqualityExpectation
45
- expect(double_definition.argument_expectation.expected_arguments).to eq []
46
- expect(subject.foobar).to eq :baz
47
- end
48
- end
49
- end
50
-
51
- describe "#stub" do
52
- before do
53
- @strategy_method_name = :stub
54
- end
55
-
56
- context "when passing no args" do
57
- it "returns self" do
58
- expect(call_strategy).to equal double_definition_create
59
- end
60
- end
61
-
62
- context "when passed subject and a method_name argument" do
63
- it "creates a stub Double for method when passed a method_name argument" do
64
- double_definition = double_definition_create.stub(subject, :foobar).returns {:baz}
65
- expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::AnyTimesMatcher.new
66
- expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
67
- expect(subject.foobar).to eq :baz
68
- end
69
- end
70
- end
71
-
72
- describe "#dont_allow" do
73
- before do
74
- @strategy_method_name = :dont_allow
75
- end
76
-
77
- context "when passing no args" do
78
- it "returns self" do
79
- expect(call_strategy).to equal double_definition_create
80
- end
81
- end
82
-
83
- context "when passed a subject and a method_name argument_expectation" do
84
- it "creates a mock Double for method" do
85
- double_definition = double_definition_create.dont_allow(subject, :foobar)
86
- expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::NeverMatcher.new
87
- expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
88
-
89
- expect {
90
- subject.foobar
91
- }.to raise_error(RR::Errors::TimesCalledError)
92
- RR.reset
93
- end
94
- end
95
- end
96
- end
97
-
98
- describe "! strategy definitions" do
99
- attr_reader :strategy_method_name
100
- def call_strategy(*args, &definition_eval_block)
101
- double_definition_create.__send__(strategy_method_name, *args, &definition_eval_block)
102
- end
103
-
104
- describe "#mock!" do
105
- before do
106
- @strategy_method_name = :mock!
107
- end
108
-
109
- context "when passed a method_name argument" do
110
- it "sets #verification_strategy to Mock" do
111
- double_definition_create.mock!(:foobar)
112
- expect(double_definition_create.verification_strategy.class).to eq Strategies::Verification::Mock
113
- expect { RR.verify }.to raise_error(::RR::Errors::TimesCalledError)
114
- end
115
- end
116
- end
117
-
118
- describe "#stub!" do
119
- before do
120
- @strategy_method_name = :stub!
121
- end
122
-
123
- context "when passed a method_name argument" do
124
- it "sets #verification_strategy to Stub" do
125
- double_definition_create.stub!(:foobar)
126
- expect(double_definition_create.verification_strategy.class).to eq Strategies::Verification::Stub
127
- end
128
- end
129
- end
130
-
131
- describe "#dont_allow!" do
132
- before do
133
- @strategy_method_name = :dont_allow!
134
- end
135
-
136
- context "when passed a method_name argument" do
137
- it "sets #verification_strategy to DontAllow" do
138
- double_definition_create.dont_allow!(:foobar)
139
- expect(double_definition_create.verification_strategy.class).to eq Strategies::Verification::DontAllow
140
- end
141
- end
142
- end
143
- end
144
-
145
- describe "#stub.proxy" do
146
- before do
147
- class << subject
148
- def foobar(*args)
149
- :original_foobar
150
- end
151
- end
152
- end
153
-
154
- context "when passed a method_name argument" do
155
- it "creates a proxy Double for method" do
156
- double_definition = double_definition_create.stub.proxy(subject, :foobar).after_call {:baz}
157
- expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::AnyTimesMatcher.new
158
- expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
159
- expect(subject.foobar).to eq :baz
160
- end
161
- end
162
- end
163
-
164
- describe "#instance_of" do
165
- context "when not passed a class" do
166
- it "raises an ArgumentError" do
167
- expect {
168
- double_definition_create.instance_of(Object.new).foobar
169
- }.to raise_error(ArgumentError, "instance_of only accepts class objects")
170
- end
171
- end
172
-
173
- context "when passed a method_name argument" do
174
- it "creates a proxy Double for method" do
175
- klass = Class.new
176
- double_definition = double_definition_create.stub.instance_of(klass, :foobar).returns {:baz}
177
- expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::AnyTimesMatcher.new
178
- expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
179
- expect(klass.new.foobar).to eq :baz
180
- end
181
- end
182
- end
183
-
184
- describe "#instance_of.mock" do
185
- before do
186
- @klass = Class.new
187
- end
188
-
189
- # context "when passed no arguments" do
190
- # it "returns a DoubleDefinitiondouble_definition_create" do
191
- # expect(instance_of.instance_of).to be_instance_of(DoubleDefinitionCreate)
192
- # end
193
- # end
194
-
195
- context "when passed a method_name argument" do
196
- it "creates a instance_of Double for method" do
197
- double_definition = instance_of.mock(@klass, :foobar)
198
- double_definition.with(1, 2) {:baz}
199
- expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::IntegerMatcher.new(1)
200
- expect(double_definition.argument_expectation.class).to eq RR::Expectations::ArgumentEqualityExpectation
201
- expect(double_definition.argument_expectation.expected_arguments).to eq [1, 2]
202
-
203
- expect(@klass.new.foobar(1, 2)).to eq :baz
204
- end
205
- end
206
- end
207
- end
208
-
209
- describe "StrategyExecutionMethods" do
210
- describe "#create" do
211
- context "when #verification_strategy is a Mock" do
212
- context "when #implementation_strategy is a Reimplementation" do
213
- before do
214
- double_definition_create.mock(subject)
215
- end
216
-
217
- it "sets expectation on the #subject that it will be sent the method_name once with the passed-in arguments" do
218
- mock(subject).foobar(1, 2)
219
- subject.foobar(1, 2)
220
- expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
221
- expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
222
- end
223
-
224
- describe "#subject.method_name being called" do
225
- it "returns the return value of the Double#returns block" do
226
- double_definition_create.call(:foobar, 1, 2) {:baz}
227
- expect(subject.foobar(1, 2)).to eq :baz
228
- end
229
- end
230
- end
231
-
232
- context "when #implementation_strategy is a Proxy" do
233
- before do
234
- double_definition_create.mock
235
- double_definition_create.proxy(subject)
236
- end
237
-
238
- it "sets expectation on the #subject that it will be sent the method_name once with the passed-in arguments" do
239
- def subject.foobar(*args)
240
- :baz
241
- end
242
- mock(subject).foobar(1, 2)
243
-
244
- subject.foobar(1, 2)
245
- expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
246
- expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
247
- end
248
-
249
- describe "#subject.method_name being called" do
250
- it "calls the original method" do
251
- original_method_called = false
252
- (class << subject; self; end).class_eval do
253
- define_method(:foobar) do |*args|
254
- original_method_called = true
255
- end
256
- end
257
- double_definition_create.call(:foobar, 1, 2)
258
- subject.foobar(1, 2)
259
- expect(original_method_called).to be_true
260
- end
261
-
262
- context "when not passed a block" do
263
- it "returns the value of the original method" do
264
- def subject.foobar(*args)
265
- :baz;
266
- end
267
- double_definition_create.call(:foobar, 1, 2)
268
- expect(subject.foobar(1, 2)).to eq :baz
269
- end
270
- end
271
-
272
- context "when passed a block" do
273
- attr_reader :real_value
274
- before do
275
- @real_value = real_value = Object.new
276
- (class << subject; self; end).class_eval do
277
- define_method(:foobar) {|arg1, arg2| real_value}
278
- end
279
- end
280
-
281
- it "calls the block with the return value of the original method" do
282
- double_definition_create.call(:foobar, 1, 2) do |value|
283
- mock(value).a_method {99}
284
- value
285
- end
286
- subject.foobar(1, 2)
287
- expect(real_value.a_method).to eq 99
288
- end
289
-
290
- it "returns the return value of the block" do
291
- double_definition_create.call(:foobar, 1, 2) do |value|
292
- :something_else
293
- end
294
- expect(subject.foobar(1, 2)).to eq :something_else
295
- end
296
- end
297
- end
298
- end
299
- end
300
-
301
- context "when #verification_strategy is a Stub" do
302
- context "when #implementation_strategy is a Reimplementation" do
303
- before do
304
- double_definition_create.stub(subject)
305
- end
306
-
307
- context "when not passed a block" do
308
- it "returns nil" do
309
- double_definition_create.call(:foobar)
310
- expect(subject.foobar).to be_nil
311
- end
312
- end
313
-
314
- context "when passed a block" do
315
- describe "#subject.method_name being called" do
316
- it "returns the return value of the block" do
317
- double_definition_create.call(:foobar) {:baz}
318
- expect(subject.foobar).to eq :baz
319
- end
320
- end
321
- end
322
-
323
- context "when not passed args" do
324
- describe "#subject.method_name being called with any arguments" do
325
- it "invokes the implementation of the Stub" do
326
- double_definition_create.call(:foobar) {:baz}
327
- expect(subject.foobar(1, 2)).to eq :baz
328
- expect(subject.foobar()).to eq :baz
329
- expect(subject.foobar([])).to eq :baz
330
- end
331
- end
332
- end
333
-
334
- context "when passed args" do
335
- describe "#subject.method_name being called with the passed-in arguments" do
336
- it "invokes the implementation of the Stub" do
337
- double_definition_create.call(:foobar, 1, 2) {:baz}
338
- expect(subject.foobar(1, 2)).to eq :baz
339
- end
340
- end
341
-
342
- describe "#subject.method_name being called with different arguments" do
343
- it "raises a DoubleNotFoundError" do
344
- double_definition_create.call(:foobar, 1, 2) {:baz}
345
- expect {
346
- subject.foobar
347
- }.to raise_error(RR::Errors::DoubleNotFoundError)
348
- end
349
- end
350
- end
351
- end
352
-
353
- context "when #implementation_strategy is a Proxy" do
354
- before do
355
- def subject.foobar(*args)
356
- :original_return_value
357
- end
358
- double_definition_create.stub
359
- double_definition_create.proxy(subject)
360
- end
361
-
362
- context "when not passed a block" do
363
- describe "#subject.method_name being called" do
364
- it "invokes the original implementanion" do
365
- double_definition_create.call(:foobar)
366
- expect(subject.foobar).to eq :original_return_value
367
- end
368
- end
369
- end
370
-
371
- context "when passed a block" do
372
- describe "#subject.method_name being called" do
373
- it "invokes the original implementanion and invokes the block with the return value of the original implementanion" do
374
- passed_in_value = nil
375
- double_definition_create.call(:foobar) do |original_return_value|
376
- passed_in_value = original_return_value
377
- end
378
- subject.foobar
379
- expect(passed_in_value).to eq :original_return_value
380
- end
381
-
382
- it "returns the return value of the block" do
383
- double_definition_create.call(:foobar) do |original_return_value|
384
- :new_return_value
385
- end
386
- expect(subject.foobar).to eq :new_return_value
387
- end
388
- end
389
- end
390
-
391
- context "when passed args" do
392
- describe "#subject.method_name being called with the passed-in arguments" do
393
- it "invokes the implementation of the Stub" do
394
- double_definition_create.call(:foobar, 1, 2) {:baz}
395
- expect(subject.foobar(1, 2)).to eq :baz
396
- end
397
- end
398
-
399
- describe "#subject.method_name being called with different arguments" do
400
- it "raises a DoubleNotFoundError" do
401
- double_definition_create.call(:foobar, 1, 2) {:baz}
402
- expect {
403
- subject.foobar
404
- }.to raise_error(RR::Errors::DoubleNotFoundError)
405
- end
406
- end
407
- end
408
- end
409
- end
410
-
411
- context "when #verification_strategy is a DontAllow" do
412
- before do
413
- double_definition_create.dont_allow(subject)
414
- end
415
-
416
- context "when not passed args" do
417
- describe "#subject.method_name being called with any arguments" do
418
- it "raises a TimesCalledError" do
419
- double_definition_create.call(:foobar)
420
- expect { subject.foobar }.to raise_error(RR::Errors::TimesCalledError)
421
- expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
422
- end
423
- end
424
- end
425
-
426
- context "when passed args" do
427
- describe "#subject.method_name being called with the passed-in arguments" do
428
- it "raises a TimesCalledError" do
429
- double_definition_create.call(:foobar, 1, 2)
430
- expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
431
- end
432
- end
433
-
434
- describe "#subject.method_name being called with different arguments" do
435
- it "raises a DoubleNotFoundError" do
436
- double_definition_create.call(:foobar, 1, 2)
437
- expect { subject.foobar() }.to raise_error(RR::Errors::DoubleNotFoundError)
438
- end
439
- end
440
- end
441
- end
442
- end
443
- end
444
- end
445
- end
446
- end