bogus 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/Gemfile.lock +53 -34
  2. data/Guardfile +3 -1
  3. data/Guardfile.cucumber +2 -0
  4. data/README.md +2 -1
  5. data/bogus.gemspec +1 -0
  6. data/features/.nav +2 -0
  7. data/features/changelog.md +8 -0
  8. data/features/contract_tests/custom_overwritten_class.feature +115 -0
  9. data/features/minitest_support.feature +228 -0
  10. data/lib/bogus.rb +3 -3
  11. data/lib/bogus/contracts/adds_contract_verification.rb +55 -0
  12. data/lib/bogus/{adds_recording.rb → contracts/adds_recording.rb} +2 -3
  13. data/lib/bogus/{contract_not_fulfilled.rb → contracts/contract_not_fulfilled.rb} +0 -0
  14. data/lib/bogus/{interactions_repository.rb → contracts/interactions_repository.rb} +0 -0
  15. data/lib/bogus/{proxy_class.rb → contracts/proxy_class.rb} +0 -0
  16. data/lib/bogus/{recording_proxy.rb → contracts/recording_proxy.rb} +0 -0
  17. data/lib/bogus/{records_double_interactions.rb → contracts/records_double_interactions.rb} +0 -0
  18. data/lib/bogus/{verifies_contracts.rb → contracts/verifies_contracts.rb} +0 -0
  19. data/lib/bogus/{active_record_accessors.rb → fakes/active_record_accessors.rb} +0 -0
  20. data/lib/bogus/fakes/base_class_identifier.rb +39 -0
  21. data/lib/bogus/{class_methods.rb → fakes/class_methods.rb} +0 -0
  22. data/lib/bogus/{constructor_methods.rb → fakes/constructor_methods.rb} +0 -0
  23. data/lib/bogus/{converts_name_to_class.rb → fakes/converts_name_to_class.rb} +0 -0
  24. data/lib/bogus/{copies_classes.rb → fakes/copies_classes.rb} +8 -0
  25. data/lib/bogus/{copies_methods.rb → fakes/copies_methods.rb} +0 -0
  26. data/lib/bogus/{creates_fakes.rb → fakes/creates_fakes.rb} +0 -0
  27. data/lib/bogus/{creates_fakes_with_stubbed_methods.rb → fakes/creates_fakes_with_stubbed_methods.rb} +0 -0
  28. data/lib/bogus/{fake.rb → fakes/fake.rb} +4 -12
  29. data/lib/bogus/{fake_registry.rb → fakes/fake_registry.rb} +0 -0
  30. data/lib/bogus/{fakes_classes.rb → fakes/fakes_classes.rb} +0 -0
  31. data/lib/bogus/{instance_methods.rb → fakes/instance_methods.rb} +0 -0
  32. data/lib/bogus/{makes_ducks.rb → fakes/makes_ducks.rb} +0 -0
  33. data/lib/bogus/{makes_substitute_methods.rb → fakes/makes_substitute_methods.rb} +0 -0
  34. data/lib/bogus/{makes_subtypes.rb → fakes/makes_subtypes.rb} +0 -0
  35. data/lib/bogus/{method_stringifier.rb → fakes/method_stringifier.rb} +0 -0
  36. data/lib/bogus/{overwriten_classes.rb → fakes/overwriten_classes.rb} +0 -0
  37. data/lib/bogus/{overwrites_classes.rb → fakes/overwrites_classes.rb} +0 -0
  38. data/lib/bogus/{registers_created_fakes.rb → fakes/registers_created_fakes.rb} +0 -0
  39. data/lib/bogus/{resets_overwritten_classes.rb → fakes/resets_overwritten_classes.rb} +0 -0
  40. data/lib/bogus/{responds_to_everything.rb → fakes/responds_to_everything.rb} +0 -0
  41. data/lib/bogus/injector.rb +4 -0
  42. data/lib/bogus/minitest.rb +10 -7
  43. data/lib/bogus/minitest/spec.rb +7 -0
  44. data/lib/bogus/minitest/syntax.rb +27 -0
  45. data/lib/bogus/public_methods.rb +4 -0
  46. data/lib/bogus/{rspec_adapter.rb → rspec/adapter.rb} +0 -0
  47. data/lib/bogus/rspec/extensions.rb +21 -0
  48. data/lib/bogus/rspec/syntax.rb +20 -0
  49. data/lib/bogus/{any_args.rb → stubbing/any_args.rb} +0 -0
  50. data/lib/bogus/{anything.rb → stubbing/anything.rb} +0 -0
  51. data/lib/bogus/{default_value.rb → stubbing/default_value.rb} +0 -0
  52. data/lib/bogus/{double.rb → stubbing/double.rb} +0 -0
  53. data/lib/bogus/{ensures_all_interactions_satisfied.rb → stubbing/ensures_all_interactions_satisfied.rb} +0 -0
  54. data/lib/bogus/{has_overwritten_methods.rb → stubbing/has_overwritten_methods.rb} +0 -0
  55. data/lib/bogus/{have_received_matcher.rb → stubbing/have_received_matcher.rb} +0 -0
  56. data/lib/bogus/{interaction.rb → stubbing/interaction.rb} +0 -0
  57. data/lib/bogus/{interaction_presenter.rb → stubbing/interaction_presenter.rb} +0 -0
  58. data/lib/bogus/{multi_stubber.rb → stubbing/multi_stubber.rb} +0 -0
  59. data/lib/bogus/{not_all_expectations_satisfied.rb → stubbing/not_all_expectations_satisfied.rb} +0 -0
  60. data/lib/bogus/{overwrites_methods.rb → stubbing/overwrites_methods.rb} +0 -0
  61. data/lib/bogus/{record_interactions.rb → stubbing/record_interactions.rb} +0 -0
  62. data/lib/bogus/{resets_stubbed_methods.rb → stubbing/resets_stubbed_methods.rb} +0 -0
  63. data/lib/bogus/{same_class.rb → stubbing/same_class.rb} +0 -0
  64. data/lib/bogus/{shadow.rb → stubbing/shadow.rb} +0 -0
  65. data/lib/bogus/{tracks_existence_of_test_doubles.rb → stubbing/tracks_existence_of_test_doubles.rb} +0 -0
  66. data/lib/bogus/{undefined_return_value.rb → stubbing/undefined_return_value.rb} +4 -0
  67. data/lib/bogus/{verifies_stub_definition.rb → stubbing/verifies_stub_definition.rb} +0 -0
  68. data/lib/bogus/version.rb +1 -1
  69. data/license.md +9 -0
  70. data/spec/bogus/contracts/adds_contract_verification_spec.rb +154 -0
  71. data/spec/bogus/contracts/adds_recording_spec.rb +43 -0
  72. data/spec/bogus/{interactions_repository_spec.rb → contracts/interactions_repository_spec.rb} +0 -0
  73. data/spec/bogus/{proxy_class_spec.rb → contracts/proxy_class_spec.rb} +0 -0
  74. data/spec/bogus/{records_double_interactions_spec.rb → contracts/records_double_interactions_spec.rb} +0 -0
  75. data/spec/bogus/{verifies_contracts_spec.rb → contracts/verifies_contracts_spec.rb} +0 -0
  76. data/spec/bogus/fakes/base_class_identifier_spec.rb +67 -0
  77. data/spec/bogus/{class_methods_spec.rb → fakes/class_methods_spec.rb} +0 -0
  78. data/spec/bogus/{converts_name_to_class_spec.rb → fakes/converts_name_to_class_spec.rb} +1 -1
  79. data/spec/bogus/{copies_classes_spec.rb → fakes/copies_classes_spec.rb} +3 -7
  80. data/spec/bogus/{creates_fakes_spec.rb → fakes/creates_fakes_spec.rb} +1 -1
  81. data/spec/bogus/{creates_fakes_with_stubbed_methods_spec.rb → fakes/creates_fakes_with_stubbed_methods_spec.rb} +0 -0
  82. data/spec/bogus/{fake_ar_attributes_spec.rb → fakes/fake_ar_attributes_spec.rb} +0 -0
  83. data/spec/bogus/{fake_configuration_spec.rb → fakes/fake_configuration_spec.rb} +0 -0
  84. data/spec/bogus/{fake_registry_spec.rb → fakes/fake_registry_spec.rb} +0 -0
  85. data/spec/bogus/fakes/fake_spec.rb +8 -0
  86. data/spec/bogus/{fakes_classes_spec.rb → fakes/fakes_classes_spec.rb} +0 -0
  87. data/spec/bogus/{faking_factories_spec.rb → fakes/faking_factories_spec.rb} +0 -0
  88. data/spec/bogus/{frozen_fakes_spec.rb → fakes/frozen_fakes_spec.rb} +0 -0
  89. data/spec/bogus/{instance_methods_spec.rb → fakes/instance_methods_spec.rb} +0 -0
  90. data/spec/bogus/{makes_ducks_spec.rb → fakes/makes_ducks_spec.rb} +0 -0
  91. data/spec/bogus/{makes_substitute_methods_spec.rb → fakes/makes_substitute_methods_spec.rb} +0 -0
  92. data/spec/bogus/{method_copiers_spec.rb → fakes/method_copiers_spec.rb} +0 -0
  93. data/spec/bogus/{overwriten_classes_spec.rb → fakes/overwriten_classes_spec.rb} +0 -0
  94. data/spec/bogus/{overwrites_classes_spec.rb → fakes/overwrites_classes_spec.rb} +0 -0
  95. data/spec/bogus/{registers_created_fakes_spec.rb → fakes/registers_created_fakes_spec.rb} +0 -0
  96. data/spec/bogus/{resets_overwritten_classes_spec.rb → fakes/resets_overwritten_classes_spec.rb} +0 -0
  97. data/spec/bogus/mocking_dsl_spec.rb +2 -2
  98. data/spec/bogus/{anything_spec.rb → stubbing/anything_spec.rb} +0 -0
  99. data/spec/bogus/{double_spec.rb → stubbing/double_spec.rb} +0 -0
  100. data/spec/bogus/{ensures_all_interactions_satisfied_spec.rb → stubbing/ensures_all_interactions_satisfied_spec.rb} +0 -0
  101. data/spec/bogus/{have_received_matcher_spec.rb → stubbing/have_received_matcher_spec.rb} +0 -0
  102. data/spec/bogus/{interaction_spec.rb → stubbing/interaction_spec.rb} +0 -0
  103. data/spec/bogus/{multi_stubber_spec.rb → stubbing/multi_stubber_spec.rb} +0 -0
  104. data/spec/bogus/{overwrites_methods_spec.rb → stubbing/overwrites_methods_spec.rb} +0 -0
  105. data/spec/bogus/{record_interactions_spec.rb → stubbing/record_interactions_spec.rb} +0 -0
  106. data/spec/bogus/{resets_stubbed_methods_spec.rb → stubbing/resets_stubbed_methods_spec.rb} +0 -0
  107. data/spec/bogus/{shadow_spec.rb → stubbing/shadow_spec.rb} +0 -0
  108. data/spec/bogus/{tracks_existence_of_test_doubles_spec.rb → stubbing/tracks_existence_of_test_doubles_spec.rb} +0 -0
  109. data/spec/bogus/stubbing/undefined_return_value_spec.rb +18 -0
  110. data/spec/bogus/{verifies_stub_definition_spec.rb → stubbing/verifies_stub_definition_spec.rb} +0 -0
  111. metadata +176 -160
  112. data/features/minitest/minitest_support.feature +0 -119
  113. data/lib/bogus/rspec_extensions.rb +0 -31
  114. data/spec/bogus/adds_recording_spec.rb +0 -77
@@ -3,10 +3,10 @@ require 'erb'
3
3
  require 'set'
4
4
 
5
5
  require_relative 'bogus/takes'
6
- require_relative 'bogus/record_interactions'
6
+ require_relative 'bogus/stubbing/record_interactions'
7
7
  require_relative 'bogus/proxies_method_calls'
8
- require_relative 'bogus/rspec_extensions'
9
- require_relative 'bogus/rspec_adapter'
8
+ require_relative 'bogus/rspec/extensions'
9
+ require_relative 'bogus/rspec/adapter'
10
10
 
11
11
  dir = File.realpath File.expand_path('../bogus', __FILE__)
12
12
  Dir["#{dir}/**/*.rb"].sort.each do |path|
@@ -0,0 +1,55 @@
1
+ module Bogus
2
+ class AddsContractVerification
3
+ extend Takes
4
+ takes :adds_recording, :verifies_contracts, :converts_name_to_class, :syntax
5
+
6
+ def add(fake_name, &block)
7
+ old_described_class = syntax.described_class
8
+
9
+ before do
10
+ new_class = adds_recording.add(fake_name, class_to_overwrite(fake_name, block))
11
+ syntax.described_class = new_class if overwritten_described_class?(block)
12
+ end
13
+
14
+ after do
15
+ syntax.described_class = old_described_class if overwritten_described_class?(block)
16
+ end
17
+
18
+ after_suite { verifies_contracts.verify(fake_name) }
19
+ end
20
+
21
+ private
22
+
23
+ def overwritten_described_class?(block)
24
+ described_class && !custom_class(block)
25
+ end
26
+
27
+ def class_to_overwrite(fake_name, block)
28
+ custom_class(block) || described_class || fake_class(fake_name)
29
+ end
30
+
31
+ def custom_class(block)
32
+ block.call if block
33
+ end
34
+
35
+ def described_class
36
+ syntax.described_class
37
+ end
38
+
39
+ def fake_class(name)
40
+ converts_name_to_class.convert(name)
41
+ end
42
+
43
+ def after_suite(&block)
44
+ syntax.after_suite { block.call }
45
+ end
46
+
47
+ def after(&block)
48
+ syntax.after { block.call }
49
+ end
50
+
51
+ def before(&block)
52
+ syntax.before { block.call }
53
+ end
54
+ end
55
+ end
@@ -2,11 +2,10 @@ module Bogus
2
2
  class AddsRecording
3
3
  extend Takes
4
4
 
5
- takes :converts_name_to_class, :create_proxy_class, :overwrites_classes,
5
+ takes :create_proxy_class, :overwrites_classes,
6
6
  :overwritten_classes
7
7
 
8
- def add(name, klass = nil)
9
- klass ||= converts_name_to_class.convert(name)
8
+ def add(name, klass)
10
9
  new_klass = create_proxy_class.call(name, klass)
11
10
  overwrites_classes.overwrite(klass.name, new_klass)
12
11
  overwritten_classes.add(klass.name, klass)
@@ -0,0 +1,39 @@
1
+ module Bogus
2
+ class BaseClassIdentifier
3
+ extend Takes
4
+ takes :copied_class, :klass
5
+
6
+ def self.base_class?(copied_class, klass)
7
+ new(copied_class, klass).base_class?
8
+ end
9
+
10
+ def base_class?
11
+ same? || included_module? || subclass?
12
+ end
13
+
14
+ private
15
+
16
+ def same?
17
+ klass == copied_class
18
+ end
19
+
20
+ def included_module?
21
+ copied_class.included_modules.include?(klass)
22
+ end
23
+
24
+ def subclass?
25
+ superclasses.include?(klass)
26
+ end
27
+
28
+ def superclasses
29
+ return [] unless copied_class.is_a?(Class)
30
+ klass = copied_class
31
+ superclasses = []
32
+ while klass
33
+ superclasses << klass
34
+ klass = klass.superclass
35
+ end
36
+ superclasses
37
+ end
38
+ end
39
+ end
@@ -10,6 +10,14 @@ module Bogus
10
10
  klass
11
11
  end
12
12
 
13
+ define_singleton_method(:name) do
14
+ klass.name
15
+ end
16
+
17
+ define_singleton_method(:to_s) do
18
+ klass.name
19
+ end
20
+
13
21
  define_singleton_method(:const_missing) do |name|
14
22
  klass.const_get(name)
15
23
  end
@@ -18,12 +18,12 @@ module Bogus
18
18
  end
19
19
 
20
20
  def kind_of?(klass)
21
- klass == self.class.__copied_class__
21
+ copied_class = self.class.__copied_class__
22
+ super || BaseClassIdentifier.base_class?(copied_class, klass)
22
23
  end
23
24
 
24
- def instance_of?(klass)
25
- klass == self.class.__copied_class__
26
- end
25
+ alias :instance_of? :kind_of?
26
+ alias :is_a? :kind_of?
27
27
 
28
28
  class << self
29
29
  alias :__create__ :new
@@ -32,14 +32,6 @@ module Bogus
32
32
  __record__(:new, *args, &block)
33
33
  __create__
34
34
  end
35
-
36
- def name
37
- __copied_class__.name
38
- end
39
-
40
- def to_s
41
- name
42
- end
43
35
  end
44
36
  end
45
37
  end
@@ -82,6 +82,10 @@ module Bogus
82
82
  @overwritten_classes ||= inject(OverwrittenClasses)
83
83
  end
84
84
 
85
+ def adds_contract_verification(syntax)
86
+ inject(AddsContractVerification, syntax: syntax)
87
+ end
88
+
85
89
  def create_proxy_class(fake_name, klass)
86
90
  inject(ProxyClass, fake_name: fake_name, klass: klass)
87
91
  end
@@ -37,10 +37,13 @@ module Bogus::Minitest
37
37
  end
38
38
  end
39
39
 
40
- class Minitest::Test
41
- include Bogus::Minitest
42
- end if defined? Minitest::Test
43
-
44
- class MiniTest::Unit::TestCase
45
- include Bogus::Minitest
46
- end if defined? MiniTest::Unit::TestCase
40
+ # minitest 5 vs 4.7
41
+ if defined? Minitest::Test
42
+ class Minitest::Test
43
+ include Bogus::Minitest
44
+ end
45
+ else
46
+ class MiniTest::Unit::TestCase
47
+ include Bogus::Minitest
48
+ end
49
+ end
@@ -1,5 +1,7 @@
1
1
  require 'bogus/minitest'
2
2
 
3
+ require_relative 'syntax'
4
+
3
5
  module MiniTest::Expectations
4
6
  infect_an_assertion :assert_received, :must_have_received, true
5
7
  infect_an_assertion :refute_received, :wont_have_received, true
@@ -14,5 +16,10 @@ class MiniTest::Spec
14
16
  def fake_class(name, opts = {})
15
17
  before { fake_class(name, opts) }
16
18
  end
19
+
20
+ def verify_contract(name, &block)
21
+ syntax = Bogus::MiniTestSyntax.new(self)
22
+ Bogus.add_contract_verification(syntax, name, &block)
23
+ end
17
24
  end
18
25
  end
@@ -0,0 +1,27 @@
1
+ require 'forwardable'
2
+
3
+ module Bogus
4
+ class MiniTestSyntax
5
+ extend Takes
6
+ extend Forwardable
7
+ takes :context
8
+ def_delegators :context, :before, :after
9
+
10
+ def described_class
11
+ return context.desc if context.desc.is_a?(Module)
12
+ end
13
+
14
+ def described_class=(value)
15
+ context.instance_variable_set('@desc', value)
16
+ end
17
+
18
+ def after_suite(&block)
19
+ # minitest 5 vs 4.7
20
+ if defined? Minitest.after_run
21
+ Minitest.after_run(&block)
22
+ else
23
+ MiniTest::Unit.after_tests(&block)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -4,6 +4,10 @@ module Bogus
4
4
  inject.adds_recording.add(name, klass)
5
5
  end
6
6
 
7
+ def add_contract_verification(syntax, name, &block)
8
+ inject.adds_contract_verification(syntax).add(name, &block)
9
+ end
10
+
7
11
  def verify_contract!(fake_name)
8
12
  inject.verifies_contracts.verify(fake_name)
9
13
  end
@@ -0,0 +1,21 @@
1
+ require_relative 'syntax'
2
+
3
+ module Bogus
4
+ module RSpecExtensions
5
+ def fake(name, opts = {}, &block)
6
+ let(name) { fake(name, opts, &block) }
7
+ end
8
+
9
+ def fake_class(name, opts = {})
10
+ before do
11
+ fake_class(name, opts)
12
+ end
13
+ end
14
+
15
+ def verify_contract(name, &block)
16
+ syntax = RSpecSyntax.new(self)
17
+ Bogus.add_contract_verification(syntax, name, &block)
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,20 @@
1
+ require 'forwardable'
2
+
3
+ module Bogus
4
+ class RSpecSyntax
5
+ extend Takes
6
+ extend Forwardable
7
+ takes :context
8
+ def_delegators :context, :before, :after, :described_class
9
+
10
+ def described_class=(value)
11
+ context.example.metadata[:example_group][:described_class] = value
12
+ end
13
+
14
+ def after_suite(&block)
15
+ RSpec.configure do |config|
16
+ config.after(:suite, &block)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -7,5 +7,9 @@ module Bogus
7
7
  def to_s
8
8
  "#<UndefinedReturnValue for #{@interaction}>"
9
9
  end
10
+
11
+ def method_missing(name, *args, &block)
12
+ raise NoMethodError, "undefined method '#{name}' for #{self}"
13
+ end
10
14
  end
11
15
  end
@@ -1,3 +1,3 @@
1
1
  module Bogus
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -0,0 +1,9 @@
1
+ # The MIT License (MIT)
2
+
3
+ Copyright (c) 2012-2013 Adam Pohorecki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bogus::AddsContractVerification do
4
+ class FakeSyntax
5
+ attr_accessor :described_class
6
+
7
+ def initialize(described_class = nil)
8
+ @described_class = described_class
9
+ end
10
+
11
+ def before(&block)
12
+ @before = block
13
+ end
14
+
15
+ def run_before
16
+ instance_eval(&@before)
17
+ end
18
+
19
+ def after(&block)
20
+ @after = block
21
+ end
22
+
23
+ def run_after
24
+ instance_eval(&@after)
25
+ end
26
+
27
+ def after_suite(&block)
28
+ @after_suite = block
29
+ end
30
+
31
+ def run_after_suite
32
+ instance_eval(&@after_suite)
33
+ end
34
+ end
35
+
36
+ def self.it_verifies_contract_after_suite
37
+ it "verifies the contract in after_suite" do
38
+ syntax.run_after_suite
39
+
40
+ verifies_contracts.should have_received.verify(:some_fake)
41
+ end
42
+ end
43
+
44
+ class SomeClass
45
+ end
46
+
47
+ class ClassGuessedFromFakeName
48
+ end
49
+
50
+ let(:overwritten_class) { :the_overwritten_class }
51
+
52
+ let(:adds_recording) { stub }
53
+ let(:verifies_contracts) { stub }
54
+ let(:converts_name_to_class) { stub }
55
+ let(:syntax) { FakeSyntax.new(described_class) }
56
+
57
+ let(:adds_contract_verification) { isolate(Bogus::AddsContractVerification) }
58
+
59
+ before do
60
+ stub(adds_recording).add { overwritten_class }
61
+ stub(verifies_contracts).verify
62
+ stub(converts_name_to_class).convert { ClassGuessedFromFakeName }
63
+ end
64
+
65
+ context "with described_class" do
66
+ let(:described_class) { SomeClass }
67
+
68
+ before do
69
+ adds_contract_verification.add(:some_fake)
70
+ end
71
+
72
+ it "overwrites described_class in before" do
73
+ syntax.run_before
74
+
75
+ syntax.described_class.should == overwritten_class
76
+ end
77
+
78
+ it "resets described_class in after" do
79
+ syntax.run_before
80
+ syntax.run_after
81
+
82
+ syntax.described_class.should == SomeClass
83
+ end
84
+
85
+ it_verifies_contract_after_suite
86
+
87
+ it "adds recording to described_class" do
88
+ syntax.run_before
89
+
90
+ adds_recording.should have_received.add(:some_fake, SomeClass)
91
+ end
92
+ end
93
+
94
+ class ClassToOverwrite
95
+ end
96
+
97
+ context "with a custom class to overwrite" do
98
+ let(:described_class) { SomeClass }
99
+
100
+ before do
101
+ adds_contract_verification.add(:some_fake) { ClassToOverwrite }
102
+ end
103
+
104
+ it "does not overwrite described_class in before" do
105
+ syntax.run_before
106
+
107
+ syntax.described_class.should == SomeClass
108
+ end
109
+
110
+ it "does not change described_class in after" do
111
+ syntax.run_before
112
+ syntax.run_after
113
+
114
+ syntax.described_class.should == SomeClass
115
+ end
116
+
117
+ it_verifies_contract_after_suite
118
+
119
+ it "adds recording to custom class" do
120
+ syntax.run_before
121
+
122
+ adds_recording.should have_received.add(:some_fake, ClassToOverwrite)
123
+ end
124
+ end
125
+
126
+ context "with no custom or described class" do
127
+ let(:described_class) { nil }
128
+
129
+ before do
130
+ adds_contract_verification.add(:some_fake)
131
+ end
132
+
133
+ it "does not overwrite described_class in before" do
134
+ syntax.run_before
135
+
136
+ syntax.described_class.should be_nil
137
+ end
138
+
139
+ it "does not change described_class in after" do
140
+ syntax.run_before
141
+ syntax.run_after
142
+
143
+ syntax.described_class.should be_nil
144
+ end
145
+
146
+ it_verifies_contract_after_suite
147
+
148
+ it "adds recording to class based on fake name" do
149
+ syntax.run_before
150
+
151
+ adds_recording.should have_received.add(:some_fake, ClassGuessedFromFakeName)
152
+ end
153
+ end
154
+ end