rohbau 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +18 -0
- data/.rubocop_todo.yml +149 -0
- data/.travis.yml +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +1 -1
- data/README.md +404 -20
- data/README.md.template +104 -20
- data/Rakefile +1 -1
- data/bin/build_readme +3 -1
- data/examples/email_service/email_service.rb +5 -0
- data/examples/event_tube.rb +9 -0
- data/examples/my_application.rb +13 -0
- data/examples/runtime.rb +7 -24
- data/examples/service_factory_validation.rb +4 -4
- data/examples/use_case.rb +10 -0
- data/examples/user_entity.rb +20 -0
- data/examples/user_service/create_user_use_case.rb +14 -0
- data/examples/user_service/event_tube.rb +6 -0
- data/examples/user_service/request.rb +16 -0
- data/examples/user_service/runtime.rb +13 -0
- data/examples/user_service/service_factory.rb +10 -0
- data/examples/user_service/user_gateway.rb +16 -0
- data/examples/user_service.rb +1 -0
- data/examples/verify/examples.txt +31 -0
- data/examples/verify/examples_spec.rb +25 -0
- data/lib/rohbau/application.rb +5 -8
- data/lib/rohbau/default_memory_gateway.rb +0 -2
- data/lib/rohbau/entity.rb +1 -3
- data/lib/rohbau/event_tube.rb +2 -1
- data/lib/rohbau/index.rb +4 -5
- data/lib/rohbau/interface.rb +130 -0
- data/lib/rohbau/it_behaves_like.rb +0 -2
- data/lib/rohbau/minitest/exclude.rb +0 -6
- data/lib/rohbau/registry.rb +4 -6
- data/lib/rohbau/request.rb +2 -4
- data/lib/rohbau/request_cache.rb +19 -0
- data/lib/rohbau/require.rb +0 -1
- data/lib/rohbau/runtime.rb +0 -2
- data/lib/rohbau/service_factory.rb +1 -2
- data/lib/rohbau/shared_spec.rb +0 -2
- data/lib/rohbau/shared_specs/default_gateway.rb +2 -6
- data/lib/rohbau/use_case.rb +0 -3
- data/lib/rohbau/version.rb +1 -1
- data/lib/rohbau.rb +19 -1
- data/rakelib/build_readme.rake +23 -0
- data/rakelib/ci.rake +5 -0
- data/rakelib/examples.rake +16 -0
- data/rakelib/rubocop.rake +18 -0
- data/spec/event_tube_spec.rb +2 -3
- data/spec/interface_spec.rb +111 -0
- data/spec/runtime_loader_spec.rb +1 -2
- data/spec/service_factory_spec.rb +6 -9
- data/spec/shared_spec_spec.rb +0 -2
- metadata +43 -20
- data/etc/build_readme.rb +0 -14
@@ -0,0 +1,130 @@
|
|
1
|
+
require_relative 'runtime'
|
2
|
+
require_relative 'request_cache'
|
3
|
+
|
4
|
+
module Rohbau
|
5
|
+
class Interface
|
6
|
+
include RequestCache
|
7
|
+
def initialize
|
8
|
+
@calls = Hash.new { |h, k| h[k] = nil }
|
9
|
+
@call_count = Hash.new { |h, k| h[k] = 0 }
|
10
|
+
@stub_results = Hash.new { |h, k| h[k] = nil }
|
11
|
+
@stub_type_for = Hash.new { |h, k| h[k] = nil }
|
12
|
+
end
|
13
|
+
|
14
|
+
def clear_stubs
|
15
|
+
calls.clear
|
16
|
+
call_count.clear
|
17
|
+
stub_results.clear
|
18
|
+
stub_type_for.clear
|
19
|
+
end
|
20
|
+
|
21
|
+
def clear_cached_requests
|
22
|
+
RequestCache.clear
|
23
|
+
end
|
24
|
+
|
25
|
+
def calls
|
26
|
+
@calls
|
27
|
+
end
|
28
|
+
|
29
|
+
def call_count
|
30
|
+
@call_count
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def call_use_case(domain, use_case, args)
|
36
|
+
call_count[use_case] += 1 unless args.key?(:stub_result)
|
37
|
+
calls[use_case] = args
|
38
|
+
domain = camel_case(domain)
|
39
|
+
use_case = camel_case(use_case)
|
40
|
+
caller = Caller.new domain
|
41
|
+
|
42
|
+
overwrite_stub_result_for(use_case, args[:stub_result])
|
43
|
+
overwrite_stub_type_for(use_case, args[:stub_type])
|
44
|
+
|
45
|
+
caller.call use_case, args,
|
46
|
+
:stub_result => stub_results[use_case],
|
47
|
+
:stub_type => stub_type_for[use_case] || :Success
|
48
|
+
end
|
49
|
+
|
50
|
+
def overwrite_stub_result_for(use_case, stub_result)
|
51
|
+
return if stub_result.nil?
|
52
|
+
stub_results[use_case] = stub_result
|
53
|
+
end
|
54
|
+
|
55
|
+
def overwrite_stub_type_for(use_case, stub_type)
|
56
|
+
return if stub_type.nil?
|
57
|
+
stub_type_for[use_case] = stub_type
|
58
|
+
end
|
59
|
+
|
60
|
+
def stub_results
|
61
|
+
@stub_results
|
62
|
+
end
|
63
|
+
|
64
|
+
def stub_type_for
|
65
|
+
@stub_type_for
|
66
|
+
end
|
67
|
+
|
68
|
+
def camel_case(sym)
|
69
|
+
sym.to_s.split('_').each(&:capitalize!).join
|
70
|
+
end
|
71
|
+
|
72
|
+
def method_missing(domain, *args)
|
73
|
+
use_case = args[0]
|
74
|
+
input = args[1] || {}
|
75
|
+
call_use_case(domain, use_case, input)
|
76
|
+
rescue NameError => e
|
77
|
+
msg = "You tried to call a use case from the #{domain} domain, " \
|
78
|
+
"but the following error occured: #{e.inspect}"
|
79
|
+
raise msg
|
80
|
+
end
|
81
|
+
|
82
|
+
class Caller
|
83
|
+
def initialize(domain)
|
84
|
+
@domain = domain
|
85
|
+
end
|
86
|
+
|
87
|
+
def call(use_case, args, options = {})
|
88
|
+
type = options[:stub_type]
|
89
|
+
stubbed_result = options[:stub_result]
|
90
|
+
use_case = get_use_case_for(use_case, args)
|
91
|
+
|
92
|
+
if stubbed_result
|
93
|
+
stub_use_case(use_case, type, stubbed_result)
|
94
|
+
else
|
95
|
+
call_use_case(use_case, args)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def call_use_case(use_case, args)
|
102
|
+
request = RequestCache.for[domain]
|
103
|
+
input = get_input_for(use_case, args)
|
104
|
+
|
105
|
+
use_case.new(request, input).call
|
106
|
+
end
|
107
|
+
|
108
|
+
def stub_use_case(use_case, type, result)
|
109
|
+
result_class = use_case.const_get type
|
110
|
+
|
111
|
+
return result_class.new if result == true
|
112
|
+
result_class.new(result)
|
113
|
+
end
|
114
|
+
|
115
|
+
def get_input_for(use_case, args)
|
116
|
+
use_case.const_get(:Input).new(args)
|
117
|
+
end
|
118
|
+
|
119
|
+
def get_use_case_for(use_case, args)
|
120
|
+
[domain, :UseCases, use_case].inject(Object) do |ns, const|
|
121
|
+
ns.const_get(const)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def domain
|
126
|
+
@domain
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -2,7 +2,6 @@ require 'minitest/spec'
|
|
2
2
|
|
3
3
|
module Rohbau
|
4
4
|
module ItBehavesLike
|
5
|
-
|
6
5
|
def get_shared_example(spec_name)
|
7
6
|
Rohbau::SharedSpec::SpecIndex.get spec_name
|
8
7
|
end
|
@@ -17,7 +16,6 @@ module Rohbau
|
|
17
16
|
|
18
17
|
instance_eval(&shared_example)
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Rohbau
|
2
2
|
module Minitest
|
3
3
|
module Exclude
|
4
|
-
|
5
4
|
class SpecNuker
|
6
5
|
def initialize(description_name, description_caller)
|
7
6
|
spec_class = find_spec_class(description_caller)
|
@@ -39,20 +38,15 @@ module Rohbau
|
|
39
38
|
description_class.name == @description_name
|
40
39
|
end
|
41
40
|
end
|
42
|
-
|
43
41
|
end
|
44
|
-
|
45
42
|
end
|
46
43
|
end
|
47
44
|
end
|
48
45
|
|
49
46
|
module MiniTest::Spec::DSL
|
50
|
-
|
51
|
-
|
52
47
|
# only single nesting in one describe block is supported
|
53
48
|
# for now
|
54
49
|
def exclude(it_desc, reason = "")
|
55
50
|
Rohbau::Minitest::Exclude::SpecNuker.new(self.name, self).nuke!(it_desc)
|
56
51
|
end
|
57
|
-
|
58
52
|
end
|
data/lib/rohbau/registry.rb
CHANGED
@@ -14,13 +14,11 @@ module Rohbau
|
|
14
14
|
|
15
15
|
module ExternalInterface
|
16
16
|
def register(service_name, &constructor)
|
17
|
-
registrations << service_name
|
18
17
|
implementations[service_name] << constructor
|
19
|
-
this = self
|
20
18
|
|
21
|
-
|
19
|
+
define_method service_name do
|
22
20
|
cache service_name do
|
23
|
-
instance_eval(&
|
21
|
+
instance_eval(&self.class.implementations[service_name].last)
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
@@ -29,12 +27,12 @@ module Rohbau
|
|
29
27
|
implementations[service_name].pop
|
30
28
|
|
31
29
|
if implementations[service_name].empty?
|
32
|
-
|
30
|
+
remove_method service_name
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
36
34
|
def registrations
|
37
|
-
|
35
|
+
implementations.keys
|
38
36
|
end
|
39
37
|
|
40
38
|
def implementations
|
data/lib/rohbau/request.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module Rohbau
|
2
2
|
class Request
|
3
|
-
|
4
3
|
def initialize(runtime)
|
5
|
-
raise "No Runtime
|
4
|
+
raise "No Runtime instantiated (#{self.inspect})" unless runtime
|
6
5
|
@runtime = runtime
|
7
6
|
end
|
8
7
|
|
@@ -13,12 +12,11 @@ module Rohbau
|
|
13
12
|
protected
|
14
13
|
|
15
14
|
def build_service_factory
|
16
|
-
raise NotImplementedError
|
15
|
+
raise NotImplementedError
|
17
16
|
end
|
18
17
|
|
19
18
|
def runtime
|
20
19
|
@runtime
|
21
20
|
end
|
22
|
-
|
23
21
|
end
|
24
22
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rohbau
|
2
|
+
module RequestCache
|
3
|
+
def self.for
|
4
|
+
requests
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.clear
|
8
|
+
requests.clear
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def self.requests
|
14
|
+
@requests ||= Hash.new do |hash, domain|
|
15
|
+
hash[domain] = Object.const_get(domain).const_get(:Request).new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/rohbau/require.rb
CHANGED
data/lib/rohbau/runtime.rb
CHANGED
@@ -46,7 +46,6 @@ module Rohbau
|
|
46
46
|
def after_termination
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
49
|
def initialize_plugins
|
51
50
|
self.class.plugins.each do |name, plugin_class|
|
52
51
|
instance_variable_set :"@#{name}", plugin_class.new
|
@@ -89,6 +88,5 @@ module Rohbau
|
|
89
88
|
@handling_plugin = nil
|
90
89
|
end
|
91
90
|
end
|
92
|
-
|
93
91
|
end
|
94
92
|
end
|
@@ -5,7 +5,7 @@ module Rohbau
|
|
5
5
|
include Rohbau::Registry
|
6
6
|
|
7
7
|
def initialize(runtime)
|
8
|
-
raise "No Runtime
|
8
|
+
raise "No Runtime instantiated" unless runtime
|
9
9
|
@runtime = runtime
|
10
10
|
end
|
11
11
|
|
@@ -32,6 +32,5 @@ module Rohbau
|
|
32
32
|
def runtime
|
33
33
|
@runtime
|
34
34
|
end
|
35
|
-
|
36
35
|
end
|
37
36
|
end
|
data/lib/rohbau/shared_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Rohbau
|
2
2
|
module SharedSpecs
|
3
3
|
DefaultGateway = Proc.new do
|
4
|
-
|
5
4
|
describe 'add' do
|
6
5
|
it 'inserts an entity' do
|
7
6
|
subject.add entity
|
@@ -71,7 +70,6 @@ module Rohbau
|
|
71
70
|
end
|
72
71
|
|
73
72
|
describe 'all' do
|
74
|
-
|
75
73
|
it 'returns an empty array' do
|
76
74
|
assert_equal [], subject.all
|
77
75
|
end
|
@@ -83,7 +81,6 @@ module Rohbau
|
|
83
81
|
|
84
82
|
assert_equal entities, subject.all
|
85
83
|
end
|
86
|
-
|
87
84
|
end
|
88
85
|
|
89
86
|
describe 'get' do
|
@@ -131,7 +128,7 @@ module Rohbau
|
|
131
128
|
it 'adds a copy as stored entity on add' do
|
132
129
|
uid = subject.add(entity).uid
|
133
130
|
|
134
|
-
entity.uid = uid
|
131
|
+
entity.uid = uid + '1'
|
135
132
|
|
136
133
|
assert_equal uid, subject.get(uid).uid
|
137
134
|
end
|
@@ -173,7 +170,7 @@ module Rohbau
|
|
173
170
|
results = subject.bulk_add(entities)
|
174
171
|
uid = results[0].uid
|
175
172
|
|
176
|
-
entity.uid = uid
|
173
|
+
entity.uid = uid + '1'
|
177
174
|
|
178
175
|
assert_equal uid, subject.get(uid).uid
|
179
176
|
end
|
@@ -299,7 +296,6 @@ module Rohbau
|
|
299
296
|
refute_includes subject.all.map(&:uid), uid
|
300
297
|
end
|
301
298
|
end
|
302
|
-
|
303
299
|
end
|
304
300
|
end
|
305
301
|
end
|
data/lib/rohbau/use_case.rb
CHANGED
data/lib/rohbau/version.rb
CHANGED
data/lib/rohbau.rb
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
require "rohbau/version"
|
2
2
|
|
3
|
+
# Rohbau provides a set of patterns used in Domain Driven Design.
|
4
|
+
#
|
5
|
+
# Require individual parts of Rohbau to use its functionality
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# require 'rohbau/runtime'
|
9
|
+
# require 'rohbau/runtime_loader'
|
10
|
+
# module MyApplication
|
11
|
+
# class RuntimeLoader < Rohbau::RuntimeLoader
|
12
|
+
# def initialize
|
13
|
+
# super(Runtime)
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# class Runtime < Rohbau::Runtime
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# @see README for more examples
|
3
22
|
module Rohbau
|
4
|
-
# Your code goes here...
|
5
23
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
desc 'Generate README.md from README.md.template'
|
2
|
+
task :build_readme do
|
3
|
+
root = Pathname.new(File.dirname(__FILE__)).join('..')
|
4
|
+
|
5
|
+
template = root.join(ENV.fetch('TEMPLATE', 'README.md.template'))
|
6
|
+
output = root.join(ENV.fetch('OUTPUT', 'README.md'))
|
7
|
+
|
8
|
+
content = File.read(template)
|
9
|
+
content.gsub!(/include_example '(.*?)'/) do |match|
|
10
|
+
example = $1
|
11
|
+
file = root.join('examples').join("#{example}.rb")
|
12
|
+
if File.exist?(file)
|
13
|
+
File.read(file)
|
14
|
+
else
|
15
|
+
warn "#{file} is missing" unless example =~ /example_file_name/
|
16
|
+
match
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
File.open(output, 'wb') do |file|
|
21
|
+
file.write(content)
|
22
|
+
end
|
23
|
+
end
|
data/rakelib/ci.rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
desc 'Run examples'
|
2
|
+
task :examples do
|
3
|
+
examples = FileList['examples/**/*.rb'].exclude('examples/**/*_spec.rb')
|
4
|
+
examples.each do |example|
|
5
|
+
puts example
|
6
|
+
system %{ruby -Ilib:examples #{example} 2>&1}
|
7
|
+
puts
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Verify examples'
|
12
|
+
Rake::TestTask.new('examples:verify') do |t|
|
13
|
+
t.libs << 'lib'
|
14
|
+
t.test_files = FileList['examples/verify/*_spec.rb']
|
15
|
+
t.verbose = true
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
begin
|
2
|
+
require "rubocop/rake_task"
|
3
|
+
|
4
|
+
Rake::Task[:default].enhance [:rubocop]
|
5
|
+
|
6
|
+
RuboCop::RakeTask.new do |task|
|
7
|
+
task.options << "--display-cop-names"
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :rubocop do
|
11
|
+
desc 'Generate a configuration file acting as a TODO list.'
|
12
|
+
task :auto_gen_config do
|
13
|
+
exec "bundle exec rubocop --auto-gen-config"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
rescue LoadError
|
18
|
+
end
|
data/spec/event_tube_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'rohbau/event_tube'
|
3
3
|
|
4
4
|
describe Rohbau::EventTube do
|
5
|
-
let(:tube) { Class.new(Rohbau::EventTube)}
|
5
|
+
let(:tube) { Class.new(Rohbau::EventTube) }
|
6
6
|
let(:event_class) { Struct.new(:arg1) }
|
7
7
|
let(:event) { event_class.new(22) }
|
8
8
|
|
@@ -41,7 +41,7 @@ describe Rohbau::EventTube do
|
|
41
41
|
|
42
42
|
it 'processes them all on publish' do
|
43
43
|
tube.publish :my_event, event
|
44
|
-
assert_equal [event,event], @calls
|
44
|
+
assert_equal [event, event], @calls
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -59,5 +59,4 @@ describe Rohbau::EventTube do
|
|
59
59
|
assert_equal [], @calls
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
63
62
|
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rohbau/interface'
|
3
|
+
require 'bound'
|
4
|
+
|
5
|
+
describe Rohbau::Interface do
|
6
|
+
let(:interface) { Rohbau::Interface.new }
|
7
|
+
|
8
|
+
module FakeDomain
|
9
|
+
class Request
|
10
|
+
end
|
11
|
+
|
12
|
+
module UseCases
|
13
|
+
class FakeUseCase
|
14
|
+
Input = Bound.required :super_important_information
|
15
|
+
Success = Bound.required :message
|
16
|
+
Error = Bound.required :message
|
17
|
+
|
18
|
+
def initialize(request, input)
|
19
|
+
@request = request
|
20
|
+
@input = input
|
21
|
+
end
|
22
|
+
|
23
|
+
def call
|
24
|
+
Success.new :message => "original usecase output message"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'calls a use case' do
|
31
|
+
result = interface.fake_domain :fake_use_case,
|
32
|
+
:super_important_information => "23"
|
33
|
+
assert_kind_of FakeDomain::UseCases::FakeUseCase::Success, result
|
34
|
+
assert_equal 'original usecase output message', result.message
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'raises if the domain is unknown' do
|
38
|
+
assert_raises RuntimeError do
|
39
|
+
interface.really_fake_domain :equally_fake_use_case
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns success for all use_cases when run in stub mode' do
|
44
|
+
result = interface.fake_domain :fake_use_case,
|
45
|
+
:stub_result => { :message => 'a different message' }
|
46
|
+
|
47
|
+
assert_kind_of FakeDomain::UseCases::FakeUseCase::Success, result
|
48
|
+
assert_equal 'a different message', result.message
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'can return other result types' do
|
52
|
+
interface.fake_domain :fake_use_case,
|
53
|
+
:stub_type => :Error,
|
54
|
+
:stub_result => {
|
55
|
+
:message => "error"
|
56
|
+
}
|
57
|
+
|
58
|
+
result = interface.fake_domain :fake_use_case
|
59
|
+
|
60
|
+
assert_kind_of FakeDomain::UseCases::FakeUseCase::Error, result
|
61
|
+
assert_equal 'error', result.message
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns subsequent calls to the same use case as stubs' do
|
65
|
+
interface.fake_domain :fake_use_case,
|
66
|
+
:stub_result => { :message => 'a different message' }
|
67
|
+
|
68
|
+
result = interface.fake_domain :fake_use_case,
|
69
|
+
:super_important_information => "23"
|
70
|
+
|
71
|
+
assert_kind_of FakeDomain::UseCases::FakeUseCase::Success, result
|
72
|
+
assert_equal 'a different message', result.message
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'records passed arguments by use_case' do
|
76
|
+
interface.fake_domain :fake_use_case,
|
77
|
+
:super_important_information => "23"
|
78
|
+
|
79
|
+
result = interface.calls[:fake_use_case][:super_important_information]
|
80
|
+
|
81
|
+
assert_equal "23", result
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'records number of unstubbed calls to each use_case' do
|
85
|
+
interface.fake_domain :fake_use_case,
|
86
|
+
:super_important_information => "23"
|
87
|
+
|
88
|
+
interface.fake_domain :fake_use_case,
|
89
|
+
:super_important_information => "56"
|
90
|
+
|
91
|
+
interface.fake_domain :fake_use_case,
|
92
|
+
:stub_result => { :message => 'message' }
|
93
|
+
|
94
|
+
assert_equal 2, interface.call_count[:fake_use_case]
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'can clear all stubbed results' do
|
98
|
+
interface.fake_domain :fake_use_case,
|
99
|
+
:stub_result => { :message => 'a different message' }
|
100
|
+
|
101
|
+
result = interface.fake_domain :fake_use_case
|
102
|
+
assert_equal 'a different message', result.message
|
103
|
+
|
104
|
+
interface.clear_stubs
|
105
|
+
|
106
|
+
result = interface.fake_domain :fake_use_case,
|
107
|
+
:super_important_information => "23"
|
108
|
+
refute_equal 'a different message', result.message
|
109
|
+
assert_equal 'original usecase output message', result.message
|
110
|
+
end
|
111
|
+
end
|
data/spec/runtime_loader_spec.rb
CHANGED
@@ -52,7 +52,7 @@ describe Rohbau::RuntimeLoader do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
it 'does not
|
55
|
+
it 'does not instantiate twice' do
|
56
56
|
instance = my_runtime_loader.instance
|
57
57
|
|
58
58
|
my_runtime_loader.new(ExampleClass)
|
@@ -60,7 +60,6 @@ describe Rohbau::RuntimeLoader do
|
|
60
60
|
assert_same instance, my_runtime_loader.instance
|
61
61
|
end
|
62
62
|
|
63
|
-
|
64
63
|
def inject_mocked_instance_into_my_runtime_loader
|
65
64
|
instance = MiniTest::Mock.new
|
66
65
|
|
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'rohbau/service_factory'
|
3
3
|
|
4
4
|
describe Rohbau::ServiceFactory do
|
5
|
-
|
6
5
|
let(:factory_class) do
|
7
6
|
Class.new(Rohbau::ServiceFactory)
|
8
7
|
end
|
@@ -15,7 +14,7 @@ describe Rohbau::ServiceFactory do
|
|
15
14
|
Object.new
|
16
15
|
end
|
17
16
|
|
18
|
-
it 'needs a runtime instance to get
|
17
|
+
it 'needs a runtime instance to get instantiated' do
|
19
18
|
raised = assert_raises RuntimeError do
|
20
19
|
factory_class.new(nil)
|
21
20
|
end
|
@@ -38,13 +37,13 @@ describe Rohbau::ServiceFactory do
|
|
38
37
|
end
|
39
38
|
|
40
39
|
it 'is not reached with partially registers services' do
|
41
|
-
factory_class.register(:service1) {
|
40
|
+
factory_class.register(:service1) {}
|
42
41
|
refute_predicate factory_class, :external_dependencies_complied?
|
43
42
|
end
|
44
43
|
|
45
44
|
it 'is reached if all required dependencies are registered' do
|
46
|
-
factory_class.register(:service1) {
|
47
|
-
factory_class.register(:service2) {
|
45
|
+
factory_class.register(:service1) {}
|
46
|
+
factory_class.register(:service2) {}
|
48
47
|
assert_predicate factory_class, :external_dependencies_complied?
|
49
48
|
end
|
50
49
|
end
|
@@ -72,7 +71,7 @@ describe Rohbau::ServiceFactory do
|
|
72
71
|
it "can unregister services" do
|
73
72
|
factory_class.unregister(:test_service)
|
74
73
|
|
75
|
-
assert_raises(NoMethodError) {factory.test_service}
|
74
|
+
assert_raises(NoMethodError) { factory.test_service }
|
76
75
|
end
|
77
76
|
|
78
77
|
describe "with more than one service registered" do
|
@@ -99,11 +98,9 @@ describe Rohbau::ServiceFactory do
|
|
99
98
|
factory_class.unregister(:test_service)
|
100
99
|
factory_class.unregister(:test_service)
|
101
100
|
|
102
|
-
assert_raises(NoMethodError) {factory.test_service}
|
101
|
+
assert_raises(NoMethodError) { factory.test_service }
|
103
102
|
end
|
104
103
|
end
|
105
104
|
end
|
106
|
-
|
107
105
|
end
|
108
|
-
|
109
106
|
end
|
data/spec/shared_spec_spec.rb
CHANGED
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'rohbau/shared_spec'
|
3
3
|
|
4
4
|
describe Rohbau::SharedSpec do
|
5
|
-
|
6
5
|
before do
|
7
6
|
Rohbau::SharedSpec::SpecIndex.reset
|
8
7
|
end
|
@@ -40,5 +39,4 @@ describe Rohbau::SharedSpec do
|
|
40
39
|
assert_equal nil, index.get(:something)
|
41
40
|
end
|
42
41
|
end
|
43
|
-
|
44
42
|
end
|