injectable_dependencies 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e5a62a3f85f8aa713eda4c0931e8f3274b26d92
4
- data.tar.gz: 86d374a14c54ffd19d55960d03f7949580c78929
3
+ metadata.gz: 5c2a4fa90330ba1e366d71381d99f5409b0f3aa9
4
+ data.tar.gz: 8bf771ee6115358876cac74faf18dbde528c4109
5
5
  SHA512:
6
- metadata.gz: d9d6040425e5bf06d404b3649fbe8776b5ed21fe5cf17977895723200956cce7bd123c8b2e2aa320162684e55d61cb9fb60ae0dace8761b5e49e1565322a28b1
7
- data.tar.gz: 76a00acbd1367c1eab96f65e59b00343f472775709b813d5d71dccf4f3239bfa8fc14e6b67effdddeda45f94200634d1968f28113a1826c850a1c5759a4960ca
6
+ metadata.gz: cdce3240c56ce721e5811f05fe77bd9335c04895987cae462e78ecc04dbf8708297933e772a9f91a9029618fe6d86079ededb85941ddb907554c93d05959a379
7
+ data.tar.gz: f39b722a6baf935f90d0bc4a99728524d6155cb28833c915ee2ce2fcd73135cd12a0fe39e162a148754d8838c59693518806e4f9c3ad1a6905d9e3da020ba4a7
@@ -34,11 +34,11 @@ module InjectableDependencies
34
34
  protected
35
35
 
36
36
  def dependencies
37
- @dependencies ||= []
37
+ @@dependencies ||= []
38
38
  end
39
39
 
40
40
  def no_default_dependencies
41
- @no_default_dependencies ||= []
41
+ @@no_default_dependencies ||= []
42
42
  end
43
43
  end
44
44
 
@@ -1,3 +1,3 @@
1
1
  module InjectableDependencies
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -3,7 +3,7 @@ require 'injectable_dependencies'
3
3
  describe InjectableDependencies do
4
4
  FooDependency = :foo_dependency
5
5
 
6
- let(:dependant_class) {
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(:dependant) {
26
- dependant_class.new
25
+ let(:dependent) {
26
+ dependent_class.new
27
27
  }
28
28
 
29
29
  it 'allows the class to declare dependencies' do
30
- expect(dependant.foo).to eq FooDependency
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{ dependant.bar }.to raise_error(NameError)
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
- dependant = dependant_class.new(:dependencies => {:bar => :bar_dependency})
39
- expect(dependant.bar).to eq :bar_dependency
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
- dependant = dependent_class_with_default_initializer.new(:dependencies => {:bar => :bar_dependency})
44
- expect(dependant.bar).to eq :bar_dependency
45
- expect(dependant.foo).to be FooDependency
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 = dependant_class.new
50
- s1 = dependant_class.new(:dependencies => { :foo => :s1_dep })
51
- s2 = dependant_class.new(:dependencies => { :foo => :s2_dep })
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{ dependant_class.new(:dependencies => {:undeclared_thing => :oops}) } \
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.2.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-05-29 00:00:00.000000000 Z
11
+ date: 2014-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport