scorpion-ioc 0.6.2 → 1.0.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 +144 -30
- data/Gemfile +17 -13
- data/README.md +24 -69
- data/Rakefile +12 -0
- data/app/README +1 -0
- data/bin/rspec +2 -1
- data/config.ru +2 -2
- data/config/environment.rb +1 -0
- data/lib/scorpion-ioc.rb +3 -1
- data/lib/scorpion.rb +32 -45
- data/lib/scorpion/attribute.rb +14 -34
- data/lib/scorpion/attribute_set.rb +11 -13
- data/lib/scorpion/chain_hunter.rb +4 -4
- data/lib/scorpion/dependency.rb +22 -58
- data/lib/scorpion/dependency/argument_dependency.rb +4 -4
- data/lib/scorpion/dependency/builder_dependency.rb +5 -5
- data/lib/scorpion/dependency/captured_dependency.rb +4 -6
- data/lib/scorpion/dependency/class_dependency.rb +3 -17
- data/lib/scorpion/dependency/module_dependency.rb +1 -1
- data/lib/scorpion/dependency_map.rb +16 -16
- data/lib/scorpion/error.rb +12 -9
- data/lib/scorpion/hunt.rb +33 -34
- data/lib/scorpion/hunter.rb +6 -6
- data/lib/scorpion/locale/en.yml +2 -2
- data/lib/scorpion/method.rb +11 -1
- data/lib/scorpion/object.rb +16 -31
- data/lib/scorpion/rack.rb +1 -1
- data/lib/scorpion/rack/middleware.rb +2 -1
- data/lib/scorpion/rails.rb +6 -6
- data/lib/scorpion/rails/active_record.rb +4 -4
- data/lib/scorpion/rails/active_record/association.rb +3 -3
- data/lib/scorpion/rails/active_record/relation.rb +3 -2
- data/lib/scorpion/rails/controller.rb +2 -2
- data/lib/scorpion/rails/job.rb +1 -1
- data/lib/scorpion/rails/mailer.rb +1 -1
- data/lib/scorpion/rails/nest.rb +11 -11
- data/lib/scorpion/rails/railtie.rb +2 -2
- data/lib/scorpion/rspec.rb +2 -2
- data/lib/scorpion/rspec/helper.rb +3 -3
- data/lib/scorpion/stinger.rb +19 -18
- data/lib/scorpion/version.rb +3 -3
- data/scorpion.gemspec +13 -13
- data/spec/internal/db/schema.rb +1 -1
- data/spec/lib/scorpion/attribute_set_spec.rb +4 -22
- data/spec/lib/scorpion/attribute_spec.rb +3 -8
- data/spec/lib/scorpion/chain_hunter_spec.rb +1 -1
- data/spec/lib/scorpion/dependency/argument_dependency_spec.rb +3 -7
- data/spec/lib/scorpion/dependency/builder_dependency_spec.rb +7 -7
- data/spec/lib/scorpion/dependency/module_dependency_spec.rb +3 -3
- data/spec/lib/scorpion/dependency_map_spec.rb +4 -25
- data/spec/lib/scorpion/dependency_spec.rb +18 -45
- data/spec/lib/scorpion/error_spec.rb +1 -1
- data/spec/lib/scorpion/hunt_spec.rb +16 -28
- data/spec/lib/scorpion/hunter_spec.rb +29 -21
- data/spec/lib/scorpion/object_spec.rb +20 -19
- data/spec/lib/scorpion/rack/middleware_spec.rb +4 -4
- data/spec/lib/scorpion/rack_spec.rb +1 -1
- data/spec/lib/scorpion/rails/active_record/association_spec.rb +3 -3
- data/spec/lib/scorpion/rails/active_record/model_spec.rb +3 -3
- data/spec/lib/scorpion/rails/active_record/relation_spec.rb +3 -3
- data/spec/lib/scorpion/rails/controller_spec.rb +8 -8
- data/spec/lib/scorpion/rails/job_spec.rb +1 -1
- data/spec/lib/scorpion/rspec/helper_spec.rb +11 -11
- data/spec/lib/scorpion_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -10
- metadata +6 -6
- data/lib/scorpion/object_constructor.rb +0 -79
- data/spec/lib/scorpion/object_constructor_spec.rb +0 -124
@@ -2,10 +2,10 @@ require "spec_helper"
|
|
2
2
|
require "scorpion/rack/middleware"
|
3
3
|
|
4
4
|
describe Scorpion::Rack::Middleware do
|
5
|
-
let(:app) { proc{ [ 200, {}, [
|
5
|
+
let(:app) { proc { [ 200, {}, [ "Sting!" ] ] } }
|
6
6
|
let(:stack) { Scorpion::Rack::Middleware.new( app ) }
|
7
7
|
let(:request) { Rack::MockRequest.new( stack ) }
|
8
|
-
let(:response) { request.get(
|
8
|
+
let(:response) { request.get("/") }
|
9
9
|
|
10
10
|
it "creates a scorpion" do
|
11
11
|
expect( stack ).to receive( :prepare_scorpion ).and_call_original
|
@@ -19,8 +19,8 @@ describe Scorpion::Rack::Middleware do
|
|
19
19
|
app.call( env )
|
20
20
|
}
|
21
21
|
|
22
|
-
request
|
23
|
-
request.get
|
22
|
+
request = Rack::MockRequest.new( Scorpion::Rack::Middleware.new( proc ) )
|
23
|
+
request.get "/"
|
24
24
|
end
|
25
25
|
|
26
26
|
it "frees the scorpion on return" do
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Scorpion::Rails::ActiveRecord::Association, type: :model do
|
4
4
|
include Scorpion::Rspec::Helper
|
5
5
|
|
6
6
|
before( :each ) do
|
7
7
|
author = Author.create! name: "Pitbull"
|
8
|
-
|
8
|
+
Todo.create! name: "Be even more awesome", author: author
|
9
9
|
end
|
10
10
|
|
11
11
|
it "shares scorpion with associations" do
|
@@ -23,4 +23,4 @@ describe Scorpion::Rails::ActiveRecord::Association, type: :model do
|
|
23
23
|
expect( todo.author.scorpion ).to be scorpion
|
24
24
|
end
|
25
25
|
|
26
|
-
end
|
26
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Scorpion::Rails::ActiveRecord::Model, type: :model do
|
4
4
|
include Scorpion::Rspec::Helper
|
5
5
|
|
6
6
|
before( :each ) do
|
7
7
|
author = Author.create! name: "Pitbull"
|
8
|
-
|
8
|
+
Todo.create! name: "Be even more awesome", author: author
|
9
9
|
end
|
10
10
|
|
11
11
|
it "shares scorpion with associations" do
|
@@ -30,4 +30,4 @@ describe Scorpion::Rails::ActiveRecord::Model, type: :model do
|
|
30
30
|
expect( Author.with_scorpion( scorpion ).named( "Pitbull" ).alphabetical.first.scorpion ).to be scorpion
|
31
31
|
end
|
32
32
|
|
33
|
-
end
|
33
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "scorpion/rails"
|
3
3
|
|
4
4
|
describe Scorpion::Rails::ActiveRecord::Relation, type: :model do
|
5
5
|
include Scorpion::Rspec::Helper
|
@@ -48,7 +48,7 @@ describe Scorpion::Rails::ActiveRecord::Relation, type: :model do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
context "find methods" do
|
51
|
-
let!( :todo ){ Todo.create! name: "Bill" }
|
51
|
+
let!( :todo ) { Todo.create! name: "Bill" }
|
52
52
|
|
53
53
|
it "shares scorpion with found records" do
|
54
54
|
expect( criteria.find( todo.id ).scorpion ).to be scorpion
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Test
|
4
4
|
module Nest
|
@@ -21,7 +21,7 @@ describe Scorpion::Rails::Controller, type: :controller do
|
|
21
21
|
scorpion.new Test::Nest::Provided
|
22
22
|
end
|
23
23
|
|
24
|
-
hunt_for String do |
|
24
|
+
hunt_for String do |_scorpion|
|
25
25
|
instance_value
|
26
26
|
end
|
27
27
|
|
@@ -45,7 +45,7 @@ describe Scorpion::Rails::Controller, type: :controller do
|
|
45
45
|
capture Test::Nest::Service # Once per request
|
46
46
|
|
47
47
|
share do
|
48
|
-
capture
|
48
|
+
capture Test::Nest::Cache # Once for all requests
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -70,9 +70,9 @@ describe Scorpion::Rails::Controller, type: :controller do
|
|
70
70
|
it "stores the scorpion in `env`" do
|
71
71
|
expect( subject ).to receive( :assign_scorpion ).and_wrap_original do |method, *args|
|
72
72
|
expect( subject.request.env ).to receive( :[]= )
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
.with( Scorpion::Rails::Controller::ENV_KEY, kind_of( Scorpion ) )
|
74
|
+
.at_least( :once )
|
75
|
+
.and_call_original
|
76
76
|
|
77
77
|
method.call( *args )
|
78
78
|
end
|
@@ -114,7 +114,7 @@ describe Scorpion::Rails::Controller, type: :controller do
|
|
114
114
|
it "spawns the same service during the same request" do
|
115
115
|
allow( subject ).to receive( :index ) do
|
116
116
|
service = subject.scorpion.fetch Test::Nest::Service
|
117
|
-
expect( subject.scorpion.fetch
|
117
|
+
expect( subject.scorpion.fetch(Test::Nest::Service) ).to be service
|
118
118
|
controller.render nothing: true
|
119
119
|
end
|
120
120
|
|
@@ -125,7 +125,7 @@ describe Scorpion::Rails::Controller, type: :controller do
|
|
125
125
|
service = subject.service
|
126
126
|
|
127
127
|
allow( subject ).to receive( :index ) do
|
128
|
-
expect( subject.scorpion.fetch
|
128
|
+
expect( subject.scorpion.fetch(Test::Nest::Service) ).not_to be service
|
129
129
|
controller.render nothing: true
|
130
130
|
end
|
131
131
|
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
load
|
1
|
+
require "spec_helper"
|
2
|
+
require "scorpion/rspec"
|
3
|
+
load "scorpion/rspec/helper.rb"
|
4
4
|
|
5
5
|
Scorpion::Rspec.prepare do
|
6
6
|
hunt_for Numeric, return: 42
|
@@ -24,11 +24,11 @@ describe Scorpion::Rspec::Helper do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "is configurable" do
|
27
|
-
expect( scorpion.fetch
|
27
|
+
expect( scorpion.fetch(String) ).to eq "Shazam!"
|
28
28
|
end
|
29
29
|
|
30
30
|
it "inherits global config" do
|
31
|
-
expect( scorpion.fetch
|
31
|
+
expect( scorpion.fetch(Numeric) ).to eq 42
|
32
32
|
end
|
33
33
|
|
34
34
|
context "hunting" do
|
@@ -37,15 +37,15 @@ describe Scorpion::Rspec::Helper do
|
|
37
37
|
hunt( :double, Regexp )
|
38
38
|
capture( :food, ScorpionRspecHelperSpec::Food )
|
39
39
|
|
40
|
-
specify{ expect( scorpion.fetch
|
41
|
-
specify{ expect( scorpion.fetch
|
42
|
-
specify{ expect( scorpion.fetch
|
43
|
-
specify{ expect( scorpion.fetch
|
40
|
+
specify { expect( scorpion.fetch(Numeric) ).to eq 5 }
|
41
|
+
specify { expect( scorpion.fetch(String) ).to eq "hello" }
|
42
|
+
specify { expect( scorpion.fetch(Regexp) ).to be_a RSpec::Mocks::TestDouble }
|
43
|
+
specify { expect( scorpion.fetch(ScorpionRspecHelperSpec::Food) ).to be food }
|
44
44
|
end
|
45
45
|
|
46
46
|
context "child context" do
|
47
47
|
it "inherits" do
|
48
|
-
expect( scorpion.fetch
|
48
|
+
expect( scorpion.fetch(String) ).to eq "Shazam!"
|
49
49
|
end
|
50
50
|
|
51
51
|
context "overrides" do
|
@@ -55,7 +55,7 @@ describe Scorpion::Rspec::Helper do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "overrides" do
|
58
|
-
expect( scorpion.fetch
|
58
|
+
expect( scorpion.fetch(String) ).to eq "KaPow"
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
data/spec/lib/scorpion_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require "simplecov"
|
2
2
|
SimpleCov.start
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
4
|
+
require "pry"
|
5
|
+
require "bundler/setup"
|
6
|
+
require "combustion"
|
7
7
|
|
8
8
|
Combustion.initialize! :all
|
9
9
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
10
|
+
require "rspec/rails"
|
11
|
+
require "scorpion"
|
12
|
+
require "scorpion/rspec"
|
13
13
|
|
14
14
|
root_path = File.expand_path( "../..", __FILE__ )
|
15
15
|
|
@@ -29,8 +29,6 @@ RSpec.configure do |config|
|
|
29
29
|
config.after(:each) { GC.enable }
|
30
30
|
|
31
31
|
config.before( :each, type: :model ) do
|
32
|
-
[ Todo, Author ].each
|
33
|
-
model.destroy_all
|
34
|
-
end
|
32
|
+
[ Todo, Author ].each(&:destroy_all)
|
35
33
|
end
|
36
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scorpion-ioc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Alexander
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -125,13 +125,16 @@ files:
|
|
125
125
|
- ".yardopts"
|
126
126
|
- CHANGELOG.md
|
127
127
|
- Gemfile
|
128
|
+
- Gemfile.lock
|
128
129
|
- Guardfile
|
129
130
|
- LICENSE
|
130
131
|
- README.md
|
131
132
|
- Rakefile
|
133
|
+
- app/README
|
132
134
|
- bin/rspec
|
133
135
|
- circle.yml
|
134
136
|
- config.ru
|
137
|
+
- config/environment.rb
|
135
138
|
- lib/scorpion-ioc.rb
|
136
139
|
- lib/scorpion.rb
|
137
140
|
- lib/scorpion/attribute.rb
|
@@ -151,7 +154,6 @@ files:
|
|
151
154
|
- lib/scorpion/method.rb
|
152
155
|
- lib/scorpion/nest.rb
|
153
156
|
- lib/scorpion/object.rb
|
154
|
-
- lib/scorpion/object_constructor.rb
|
155
157
|
- lib/scorpion/rack.rb
|
156
158
|
- lib/scorpion/rack/env.rb
|
157
159
|
- lib/scorpion/rack/middleware.rb
|
@@ -190,7 +192,6 @@ files:
|
|
190
192
|
- spec/lib/scorpion/error_spec.rb
|
191
193
|
- spec/lib/scorpion/hunt_spec.rb
|
192
194
|
- spec/lib/scorpion/hunter_spec.rb
|
193
|
-
- spec/lib/scorpion/object_constructor_spec.rb
|
194
195
|
- spec/lib/scorpion/object_spec.rb
|
195
196
|
- spec/lib/scorpion/rack/middleware_spec.rb
|
196
197
|
- spec/lib/scorpion/rack_spec.rb
|
@@ -222,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
223
|
version: '0'
|
223
224
|
requirements: []
|
224
225
|
rubyforge_project:
|
225
|
-
rubygems_version: 2.6.
|
226
|
+
rubygems_version: 2.6.13
|
226
227
|
signing_key:
|
227
228
|
specification_version: 4
|
228
229
|
summary: Add IoC to rails with minimal fuss and ceremony
|
@@ -246,7 +247,6 @@ test_files:
|
|
246
247
|
- spec/lib/scorpion/error_spec.rb
|
247
248
|
- spec/lib/scorpion/hunt_spec.rb
|
248
249
|
- spec/lib/scorpion/hunter_spec.rb
|
249
|
-
- spec/lib/scorpion/object_constructor_spec.rb
|
250
250
|
- spec/lib/scorpion/object_spec.rb
|
251
251
|
- spec/lib/scorpion/rack/middleware_spec.rb
|
252
252
|
- spec/lib/scorpion/rack_spec.rb
|
@@ -1,79 +0,0 @@
|
|
1
|
-
module Scorpion
|
2
|
-
# Builds an injectable constructor for a Scorpion::Object.
|
3
|
-
class ObjectConstructor
|
4
|
-
|
5
|
-
def initialize( base, arguments, &block )
|
6
|
-
@base = base
|
7
|
-
@arguments = arguments
|
8
|
-
@block = block
|
9
|
-
end
|
10
|
-
|
11
|
-
def define
|
12
|
-
@signature = []
|
13
|
-
@block_signature = []
|
14
|
-
@body = []
|
15
|
-
|
16
|
-
define_dependencies
|
17
|
-
build_body
|
18
|
-
|
19
|
-
add_initialize_block
|
20
|
-
add_super
|
21
|
-
|
22
|
-
assemble
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
attr_reader :base, :arguments, :block, :body
|
27
|
-
|
28
|
-
def define_dependencies
|
29
|
-
# Override the inherited injections cause we're about to define a new
|
30
|
-
# initializer.
|
31
|
-
base.instance_variable_set :@initializer_injections, AttributeSet.new
|
32
|
-
|
33
|
-
arguments.each do |key,expectation|
|
34
|
-
base.initializer_injections.define_attribute key, *Array( expectation )
|
35
|
-
base.attr_dependency key, *Array( expectation )
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def build_body
|
40
|
-
if arguments.present?
|
41
|
-
body << "injections = dependencies.slice( :#{ arguments.keys.join(', :') } )"
|
42
|
-
body << "inject_from( dependencies )"
|
43
|
-
else
|
44
|
-
body << "injections = {}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def add_super
|
49
|
-
body << "super" if base.superclass < Scorpion::Object
|
50
|
-
end
|
51
|
-
|
52
|
-
def add_initialize_block
|
53
|
-
if block
|
54
|
-
base_name = base.name || base.object_id.to_s
|
55
|
-
base_name = base_name.gsub /::/, '_'
|
56
|
-
name = "__initialize_with_block_#{ base_name }"
|
57
|
-
if block.arity != 0 || block.parameters.any?
|
58
|
-
body << "#{ name }( *args, **injections, &block )"
|
59
|
-
else
|
60
|
-
body << "#{ name }"
|
61
|
-
end
|
62
|
-
base.send :define_method, :"#{ name }", &block
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def assemble
|
67
|
-
source = %Q|def initialize( *args, **dependencies, &block )\n\t#{ body.join( "\n\t" ) }\nend|
|
68
|
-
|
69
|
-
# puts "=" * 50
|
70
|
-
# puts base.name
|
71
|
-
# puts source
|
72
|
-
# puts "=" * 50
|
73
|
-
|
74
|
-
base.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
75
|
-
#{ source }
|
76
|
-
RUBY
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,124 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Scorpion::ObjectConstructor do
|
4
|
-
|
5
|
-
it 'defines an initializer' do
|
6
|
-
klass = Class.new do
|
7
|
-
include Scorpion::Object
|
8
|
-
|
9
|
-
initialize logger: String
|
10
|
-
end
|
11
|
-
|
12
|
-
expect( klass.instance_method(:initialize).arity ).to eq -1
|
13
|
-
end
|
14
|
-
|
15
|
-
it "executes initializer code" do
|
16
|
-
expect do |b|
|
17
|
-
klass = Class.new do
|
18
|
-
include Scorpion::Object
|
19
|
-
|
20
|
-
initialize label: String, &b
|
21
|
-
end
|
22
|
-
|
23
|
-
klass.new label: "home"
|
24
|
-
end.to yield_control
|
25
|
-
end
|
26
|
-
|
27
|
-
it "creates an initializer that accepts a block" do
|
28
|
-
klass = Class.new do
|
29
|
-
include Scorpion::Object
|
30
|
-
|
31
|
-
initialize label: String do |label, &block|
|
32
|
-
block.call
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
expect do |b|
|
37
|
-
klass.new label: "apples", &b
|
38
|
-
end.to yield_control
|
39
|
-
end
|
40
|
-
|
41
|
-
it "it defines matching attributes" do
|
42
|
-
klass = Class.new do
|
43
|
-
include Scorpion::Object
|
44
|
-
|
45
|
-
initialize label: String
|
46
|
-
end
|
47
|
-
|
48
|
-
expect( klass.new( label: "apples" ).label ).to eq "apples"
|
49
|
-
end
|
50
|
-
|
51
|
-
it "invokes all initializers" do
|
52
|
-
klass = Class.new do
|
53
|
-
include Scorpion::Object
|
54
|
-
|
55
|
-
initialize label: String do |label:|
|
56
|
-
@label = label.reverse
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
derived = Class.new( klass ) do
|
61
|
-
initialize logger: Logger do |logger:|
|
62
|
-
@logger = logger.to_s.reverse.to_sym
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
expect( derived.new( logger: :unset, label: "Super" ).label ).to eq "repuS"
|
67
|
-
expect( derived.new( logger: :unset, label: "Super" ).logger ).to eq :tesnu
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
context "inheritance" do
|
72
|
-
let( :klass ) do
|
73
|
-
Class.new do
|
74
|
-
include Scorpion::Object
|
75
|
-
|
76
|
-
initialize label: String do |label:|
|
77
|
-
@label = label.reverse
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
let( :derived ) do
|
83
|
-
Class.new( klass )
|
84
|
-
end
|
85
|
-
|
86
|
-
it "inherits super initializer block" do
|
87
|
-
expect( derived.new( label: "Super" ).label ).to eq "repuS"
|
88
|
-
end
|
89
|
-
|
90
|
-
it "inherits initializer_injections" do
|
91
|
-
expect( klass.initializer_injections.count ).to eq 1
|
92
|
-
expect( klass.initializer_injections ).to eq derived.initializer_injections
|
93
|
-
end
|
94
|
-
|
95
|
-
it "can override initializer_injections" do
|
96
|
-
more_derived = Class.new( derived ) do
|
97
|
-
initialize do
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
expect( more_derived.initializer_injections.count ).to eq 0
|
102
|
-
end
|
103
|
-
|
104
|
-
it "fails if changing attribute without changing initializer" do
|
105
|
-
expect do
|
106
|
-
overriden = Class.new( klass ) do
|
107
|
-
attr_dependency :label, Integer
|
108
|
-
end
|
109
|
-
end.to raise_exception Scorpion::ContractMismatchError
|
110
|
-
end
|
111
|
-
|
112
|
-
it "works if changing attribute and changing initializer" do
|
113
|
-
expect do
|
114
|
-
overriden = Class.new( klass ) do
|
115
|
-
|
116
|
-
initialize label: Integer
|
117
|
-
attr_dependency :label, Integer
|
118
|
-
end
|
119
|
-
end.not_to raise_exception
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|