injectable_dependencies 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/injectable_dependencies.rb +2 -2
- data/lib/injectable_dependencies/version.rb +1 -1
- data/spec/injectable_dependencies_spec.rb +77 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c2a4fa90330ba1e366d71381d99f5409b0f3aa9
|
4
|
+
data.tar.gz: 8bf771ee6115358876cac74faf18dbde528c4109
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdce3240c56ce721e5811f05fe77bd9335c04895987cae462e78ecc04dbf8708297933e772a9f91a9029618fe6d86079ededb85941ddb907554c93d05959a379
|
7
|
+
data.tar.gz: f39b722a6baf935f90d0bc4a99728524d6155cb28833c915ee2ce2fcd73135cd12a0fe39e162a148754d8838c59693518806e4f9c3ad1a6905d9e3da020ba4a7
|
@@ -3,7 +3,7 @@ require 'injectable_dependencies'
|
|
3
3
|
describe InjectableDependencies do
|
4
4
|
FooDependency = :foo_dependency
|
5
5
|
|
6
|
-
let(:
|
6
|
+
let(:dependent_class) {
|
7
7
|
Class.new do
|
8
8
|
include InjectableDependencies
|
9
9
|
dependency(:foo) { FooDependency }
|
@@ -22,33 +22,33 @@ describe InjectableDependencies do
|
|
22
22
|
end
|
23
23
|
}
|
24
24
|
|
25
|
-
let(:
|
26
|
-
|
25
|
+
let(:dependent) {
|
26
|
+
dependent_class.new
|
27
27
|
}
|
28
28
|
|
29
29
|
it 'allows the class to declare dependencies' do
|
30
|
-
expect(
|
30
|
+
expect(dependent.foo).to eq FooDependency
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'does not evaluate dependencies declared by the class until they are requested' do
|
34
|
-
expect{
|
34
|
+
expect{ dependent.bar }.to raise_error(NameError)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'provides a convenience method for setting dependencies from the initializer' do
|
38
|
-
|
39
|
-
expect(
|
38
|
+
dependent = dependent_class.new(:dependencies => {:bar => :bar_dependency})
|
39
|
+
expect(dependent.bar).to eq :bar_dependency
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'provides a default initializer that allows dependency overrides' do
|
43
|
-
|
44
|
-
expect(
|
45
|
-
expect(
|
43
|
+
dependent = dependent_class_with_default_initializer.new(:dependencies => {:bar => :bar_dependency})
|
44
|
+
expect(dependent.bar).to eq :bar_dependency
|
45
|
+
expect(dependent.foo).to be FooDependency
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'does not persist dependencies between instances' do
|
49
|
-
s0 =
|
50
|
-
s1 =
|
51
|
-
s2 =
|
49
|
+
s0 = dependent_class.new
|
50
|
+
s1 = dependent_class.new(:dependencies => { :foo => :s1_dep })
|
51
|
+
s2 = dependent_class.new(:dependencies => { :foo => :s2_dep })
|
52
52
|
|
53
53
|
expect(s0.foo).to eq FooDependency
|
54
54
|
expect(s1.foo).to eq :s1_dep
|
@@ -56,11 +56,74 @@ describe InjectableDependencies do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'does not allow undeclared dependencies to be specified in initializer' do
|
59
|
-
expect{
|
59
|
+
expect{ dependent_class.new(:dependencies => {:undeclared_thing => :oops}) } \
|
60
60
|
.to raise_error(InjectableDependencies::UndeclaredDependencyError,
|
61
61
|
"Cannot override undeclared dependency 'undeclared_thing'.")
|
62
62
|
end
|
63
63
|
|
64
|
+
context 'when a class inherits from another class that has dependencies' do
|
65
|
+
let(:inheriting_class) {
|
66
|
+
Class.new(dependent_class)
|
67
|
+
}
|
68
|
+
|
69
|
+
let(:inheriting_class_with_default_initializer) {
|
70
|
+
Class.new(dependent_class_with_default_initializer)
|
71
|
+
}
|
72
|
+
|
73
|
+
let(:inheriting_class_with_own_deps) {
|
74
|
+
Class.new(dependent_class) do
|
75
|
+
dependency(:only_here) { :inheriting_class_dep }
|
76
|
+
end
|
77
|
+
}
|
78
|
+
|
79
|
+
let(:dependent) { inheriting_class.new }
|
80
|
+
|
81
|
+
it 'also inherits the dependency definitions' do
|
82
|
+
expect(dependent.foo).to eq FooDependency
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'does not evaluate dependencies declared by the class until they are requested' do
|
86
|
+
expect{ dependent.bar }.to raise_error(NameError)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'provides a convenience method for setting dependencies from the initializer' do
|
90
|
+
dependent = inheriting_class.new(:dependencies => {:bar => :bar_dependency})
|
91
|
+
expect(dependent.bar).to eq :bar_dependency
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'provides a default initializer that allows dependency overrides' do
|
95
|
+
dependent = inheriting_class_with_default_initializer.new(:dependencies => {:bar => :bar_dependency})
|
96
|
+
expect(dependent.bar).to eq :bar_dependency
|
97
|
+
expect(dependent.foo).to be FooDependency
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'does not persist dependencies between instances' do
|
101
|
+
s0 = inheriting_class.new
|
102
|
+
s1 = inheriting_class.new(:dependencies => { :foo => :s1_dep })
|
103
|
+
s2 = inheriting_class.new(:dependencies => { :foo => :s2_dep })
|
104
|
+
|
105
|
+
expect(s0.foo).to eq FooDependency
|
106
|
+
expect(s1.foo).to eq :s1_dep
|
107
|
+
expect(s2.foo).to eq :s2_dep
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'does not allow undeclared dependencies to be specified in initializer' do
|
111
|
+
expect{ inheriting_class.new(:dependencies => {:undeclared_thing => :oops}) } \
|
112
|
+
.to raise_error(InjectableDependencies::UndeclaredDependencyError,
|
113
|
+
"Cannot override undeclared dependency 'undeclared_thing'.")
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'can define its own dependencies' do
|
117
|
+
dependent = inheriting_class_with_own_deps.new
|
118
|
+
expect(dependent.only_here).to eq(:inheriting_class_dep)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'does not push its dependencies back up the stack' do
|
122
|
+
_ = inheriting_class_with_own_deps.new # to make sure it is created
|
123
|
+
expect{ dependent.only_here }.to raise_error(NoMethodError)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
64
127
|
context 'when a dependency is defined without a default implementation' do
|
65
128
|
context 'when the dependent class has its own initializer' do
|
66
129
|
let(:dependent_class) {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: injectable_dependencies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wilger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|