bogus 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +53 -34
- data/Guardfile +3 -1
- data/Guardfile.cucumber +2 -0
- data/README.md +2 -1
- data/bogus.gemspec +1 -0
- data/features/.nav +2 -0
- data/features/changelog.md +8 -0
- data/features/contract_tests/custom_overwritten_class.feature +115 -0
- data/features/minitest_support.feature +228 -0
- data/lib/bogus.rb +3 -3
- data/lib/bogus/contracts/adds_contract_verification.rb +55 -0
- data/lib/bogus/{adds_recording.rb → contracts/adds_recording.rb} +2 -3
- data/lib/bogus/{contract_not_fulfilled.rb → contracts/contract_not_fulfilled.rb} +0 -0
- data/lib/bogus/{interactions_repository.rb → contracts/interactions_repository.rb} +0 -0
- data/lib/bogus/{proxy_class.rb → contracts/proxy_class.rb} +0 -0
- data/lib/bogus/{recording_proxy.rb → contracts/recording_proxy.rb} +0 -0
- data/lib/bogus/{records_double_interactions.rb → contracts/records_double_interactions.rb} +0 -0
- data/lib/bogus/{verifies_contracts.rb → contracts/verifies_contracts.rb} +0 -0
- data/lib/bogus/{active_record_accessors.rb → fakes/active_record_accessors.rb} +0 -0
- data/lib/bogus/fakes/base_class_identifier.rb +39 -0
- data/lib/bogus/{class_methods.rb → fakes/class_methods.rb} +0 -0
- data/lib/bogus/{constructor_methods.rb → fakes/constructor_methods.rb} +0 -0
- data/lib/bogus/{converts_name_to_class.rb → fakes/converts_name_to_class.rb} +0 -0
- data/lib/bogus/{copies_classes.rb → fakes/copies_classes.rb} +8 -0
- data/lib/bogus/{copies_methods.rb → fakes/copies_methods.rb} +0 -0
- data/lib/bogus/{creates_fakes.rb → fakes/creates_fakes.rb} +0 -0
- data/lib/bogus/{creates_fakes_with_stubbed_methods.rb → fakes/creates_fakes_with_stubbed_methods.rb} +0 -0
- data/lib/bogus/{fake.rb → fakes/fake.rb} +4 -12
- data/lib/bogus/{fake_registry.rb → fakes/fake_registry.rb} +0 -0
- data/lib/bogus/{fakes_classes.rb → fakes/fakes_classes.rb} +0 -0
- data/lib/bogus/{instance_methods.rb → fakes/instance_methods.rb} +0 -0
- data/lib/bogus/{makes_ducks.rb → fakes/makes_ducks.rb} +0 -0
- data/lib/bogus/{makes_substitute_methods.rb → fakes/makes_substitute_methods.rb} +0 -0
- data/lib/bogus/{makes_subtypes.rb → fakes/makes_subtypes.rb} +0 -0
- data/lib/bogus/{method_stringifier.rb → fakes/method_stringifier.rb} +0 -0
- data/lib/bogus/{overwriten_classes.rb → fakes/overwriten_classes.rb} +0 -0
- data/lib/bogus/{overwrites_classes.rb → fakes/overwrites_classes.rb} +0 -0
- data/lib/bogus/{registers_created_fakes.rb → fakes/registers_created_fakes.rb} +0 -0
- data/lib/bogus/{resets_overwritten_classes.rb → fakes/resets_overwritten_classes.rb} +0 -0
- data/lib/bogus/{responds_to_everything.rb → fakes/responds_to_everything.rb} +0 -0
- data/lib/bogus/injector.rb +4 -0
- data/lib/bogus/minitest.rb +10 -7
- data/lib/bogus/minitest/spec.rb +7 -0
- data/lib/bogus/minitest/syntax.rb +27 -0
- data/lib/bogus/public_methods.rb +4 -0
- data/lib/bogus/{rspec_adapter.rb → rspec/adapter.rb} +0 -0
- data/lib/bogus/rspec/extensions.rb +21 -0
- data/lib/bogus/rspec/syntax.rb +20 -0
- data/lib/bogus/{any_args.rb → stubbing/any_args.rb} +0 -0
- data/lib/bogus/{anything.rb → stubbing/anything.rb} +0 -0
- data/lib/bogus/{default_value.rb → stubbing/default_value.rb} +0 -0
- data/lib/bogus/{double.rb → stubbing/double.rb} +0 -0
- data/lib/bogus/{ensures_all_interactions_satisfied.rb → stubbing/ensures_all_interactions_satisfied.rb} +0 -0
- data/lib/bogus/{has_overwritten_methods.rb → stubbing/has_overwritten_methods.rb} +0 -0
- data/lib/bogus/{have_received_matcher.rb → stubbing/have_received_matcher.rb} +0 -0
- data/lib/bogus/{interaction.rb → stubbing/interaction.rb} +0 -0
- data/lib/bogus/{interaction_presenter.rb → stubbing/interaction_presenter.rb} +0 -0
- data/lib/bogus/{multi_stubber.rb → stubbing/multi_stubber.rb} +0 -0
- data/lib/bogus/{not_all_expectations_satisfied.rb → stubbing/not_all_expectations_satisfied.rb} +0 -0
- data/lib/bogus/{overwrites_methods.rb → stubbing/overwrites_methods.rb} +0 -0
- data/lib/bogus/{record_interactions.rb → stubbing/record_interactions.rb} +0 -0
- data/lib/bogus/{resets_stubbed_methods.rb → stubbing/resets_stubbed_methods.rb} +0 -0
- data/lib/bogus/{same_class.rb → stubbing/same_class.rb} +0 -0
- data/lib/bogus/{shadow.rb → stubbing/shadow.rb} +0 -0
- data/lib/bogus/{tracks_existence_of_test_doubles.rb → stubbing/tracks_existence_of_test_doubles.rb} +0 -0
- data/lib/bogus/{undefined_return_value.rb → stubbing/undefined_return_value.rb} +4 -0
- data/lib/bogus/{verifies_stub_definition.rb → stubbing/verifies_stub_definition.rb} +0 -0
- data/lib/bogus/version.rb +1 -1
- data/license.md +9 -0
- data/spec/bogus/contracts/adds_contract_verification_spec.rb +154 -0
- data/spec/bogus/contracts/adds_recording_spec.rb +43 -0
- data/spec/bogus/{interactions_repository_spec.rb → contracts/interactions_repository_spec.rb} +0 -0
- data/spec/bogus/{proxy_class_spec.rb → contracts/proxy_class_spec.rb} +0 -0
- data/spec/bogus/{records_double_interactions_spec.rb → contracts/records_double_interactions_spec.rb} +0 -0
- data/spec/bogus/{verifies_contracts_spec.rb → contracts/verifies_contracts_spec.rb} +0 -0
- data/spec/bogus/fakes/base_class_identifier_spec.rb +67 -0
- data/spec/bogus/{class_methods_spec.rb → fakes/class_methods_spec.rb} +0 -0
- data/spec/bogus/{converts_name_to_class_spec.rb → fakes/converts_name_to_class_spec.rb} +1 -1
- data/spec/bogus/{copies_classes_spec.rb → fakes/copies_classes_spec.rb} +3 -7
- data/spec/bogus/{creates_fakes_spec.rb → fakes/creates_fakes_spec.rb} +1 -1
- data/spec/bogus/{creates_fakes_with_stubbed_methods_spec.rb → fakes/creates_fakes_with_stubbed_methods_spec.rb} +0 -0
- data/spec/bogus/{fake_ar_attributes_spec.rb → fakes/fake_ar_attributes_spec.rb} +0 -0
- data/spec/bogus/{fake_configuration_spec.rb → fakes/fake_configuration_spec.rb} +0 -0
- data/spec/bogus/{fake_registry_spec.rb → fakes/fake_registry_spec.rb} +0 -0
- data/spec/bogus/fakes/fake_spec.rb +8 -0
- data/spec/bogus/{fakes_classes_spec.rb → fakes/fakes_classes_spec.rb} +0 -0
- data/spec/bogus/{faking_factories_spec.rb → fakes/faking_factories_spec.rb} +0 -0
- data/spec/bogus/{frozen_fakes_spec.rb → fakes/frozen_fakes_spec.rb} +0 -0
- data/spec/bogus/{instance_methods_spec.rb → fakes/instance_methods_spec.rb} +0 -0
- data/spec/bogus/{makes_ducks_spec.rb → fakes/makes_ducks_spec.rb} +0 -0
- data/spec/bogus/{makes_substitute_methods_spec.rb → fakes/makes_substitute_methods_spec.rb} +0 -0
- data/spec/bogus/{method_copiers_spec.rb → fakes/method_copiers_spec.rb} +0 -0
- data/spec/bogus/{overwriten_classes_spec.rb → fakes/overwriten_classes_spec.rb} +0 -0
- data/spec/bogus/{overwrites_classes_spec.rb → fakes/overwrites_classes_spec.rb} +0 -0
- data/spec/bogus/{registers_created_fakes_spec.rb → fakes/registers_created_fakes_spec.rb} +0 -0
- data/spec/bogus/{resets_overwritten_classes_spec.rb → fakes/resets_overwritten_classes_spec.rb} +0 -0
- data/spec/bogus/mocking_dsl_spec.rb +2 -2
- data/spec/bogus/{anything_spec.rb → stubbing/anything_spec.rb} +0 -0
- data/spec/bogus/{double_spec.rb → stubbing/double_spec.rb} +0 -0
- data/spec/bogus/{ensures_all_interactions_satisfied_spec.rb → stubbing/ensures_all_interactions_satisfied_spec.rb} +0 -0
- data/spec/bogus/{have_received_matcher_spec.rb → stubbing/have_received_matcher_spec.rb} +0 -0
- data/spec/bogus/{interaction_spec.rb → stubbing/interaction_spec.rb} +0 -0
- data/spec/bogus/{multi_stubber_spec.rb → stubbing/multi_stubber_spec.rb} +0 -0
- data/spec/bogus/{overwrites_methods_spec.rb → stubbing/overwrites_methods_spec.rb} +0 -0
- data/spec/bogus/{record_interactions_spec.rb → stubbing/record_interactions_spec.rb} +0 -0
- data/spec/bogus/{resets_stubbed_methods_spec.rb → stubbing/resets_stubbed_methods_spec.rb} +0 -0
- data/spec/bogus/{shadow_spec.rb → stubbing/shadow_spec.rb} +0 -0
- data/spec/bogus/{tracks_existence_of_test_doubles_spec.rb → stubbing/tracks_existence_of_test_doubles_spec.rb} +0 -0
- data/spec/bogus/stubbing/undefined_return_value_spec.rb +18 -0
- data/spec/bogus/{verifies_stub_definition_spec.rb → stubbing/verifies_stub_definition_spec.rb} +0 -0
- metadata +176 -160
- data/features/minitest/minitest_support.feature +0 -119
- data/lib/bogus/rspec_extensions.rb +0 -31
- data/spec/bogus/adds_recording_spec.rb +0 -77
data/lib/bogus.rb
CHANGED
@@ -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/
|
9
|
-
require_relative 'bogus/
|
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 :
|
5
|
+
takes :create_proxy_class, :overwrites_classes,
|
6
6
|
:overwritten_classes
|
7
7
|
|
8
|
-
def add(name, klass
|
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)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/bogus/{creates_fakes_with_stubbed_methods.rb → fakes/creates_fakes_with_stubbed_methods.rb}
RENAMED
File without changes
|
@@ -18,12 +18,12 @@ module Bogus
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def kind_of?(klass)
|
21
|
-
|
21
|
+
copied_class = self.class.__copied_class__
|
22
|
+
super || BaseClassIdentifier.base_class?(copied_class, klass)
|
22
23
|
end
|
23
24
|
|
24
|
-
|
25
|
-
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/bogus/injector.rb
CHANGED
@@ -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
|
data/lib/bogus/minitest.rb
CHANGED
@@ -37,10 +37,13 @@ module Bogus::Minitest
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
data/lib/bogus/minitest/spec.rb
CHANGED
@@ -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
|
data/lib/bogus/public_methods.rb
CHANGED
@@ -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
|
File without changes
|
@@ -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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/bogus/{not_all_expectations_satisfied.rb → stubbing/not_all_expectations_satisfied.rb}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/bogus/{tracks_existence_of_test_doubles.rb → stubbing/tracks_existence_of_test_doubles.rb}
RENAMED
File without changes
|
File without changes
|
data/lib/bogus/version.rb
CHANGED
data/license.md
ADDED
@@ -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
|