micon 0.1.6 → 0.1.7

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.
@@ -0,0 +1,75 @@
1
+ # require 'spec_helper'
2
+ #
3
+ # describe "Autoloading" do
4
+ # with_load_path "#{spec_dir}/get_constant_component/lib"
5
+ #
6
+ # before do
7
+ # self.micon = Micon::Core.new
8
+ # end
9
+ #
10
+ # after do
11
+ # remove_constants :TheRouter, :TheRad, :TheController, :SomeModule
12
+ # end
13
+ #
14
+ # describe "get_constant_component" do
15
+ # it "should autoload components" do
16
+ # micon.get_constant_component(:TheController).should == "TheController"
17
+ # end
18
+ #
19
+ # it "should not raise error if component not defined" do
20
+ # micon.get_constant_component(:TheValue).should == nil
21
+ # micon.register(:TheValue, constant: true){"TheValue"}
22
+ # micon.get_constant_component(:TheValue).should == "TheValue"
23
+ # end
24
+ #
25
+ # it "should get constants only" do
26
+ # micon.register(:TheController){"TheController"}
27
+ # micon.get_constant_component(:TheController).should == nil
28
+ #
29
+ # micon.register(:TheController, constant: true){"TheController"}
30
+ # micon.get_constant_component(:TheController).should == "TheController"
31
+ # end
32
+ # end
33
+ #
34
+ # it 'validation' do
35
+ # -> {micon.register 'TheController', constant: true}.should raise_error(/symbol/)
36
+ # -> {micon.register 'TheController'.to_sym, constant: true, scope: :custom}.should raise_error(/scope/)
37
+ # end
38
+ #
39
+ # it "should use constants as components" do
40
+ # -> {::TheRouter}.should raise_error(/uninitialized constant/)
41
+ #
42
+ # micon.register :TheRouter, constant: true do
43
+ # "TheRouter"
44
+ # end
45
+ #
46
+ # module ::TheRad
47
+ # TheRouter.should == 'TheRouter'
48
+ # end
49
+ # ::TheRouter.should == 'TheRouter'
50
+ # micon[:TheRouter].should == 'TheRouter'
51
+ # end
52
+ #
53
+ # it "should support nested constants" do
54
+ # module ::TheRad; end
55
+ # -> {::TheRad::TheView}.should raise_error(/uninitialized constant/)
56
+ #
57
+ # micon.register 'TheRad::TheView'.to_sym, constant: true do
58
+ # 'TheRad::TheView'
59
+ # end
60
+ #
61
+ # module ::SomeModule
62
+ # ::TheRad::TheView.should == 'TheRad::TheView'
63
+ # end
64
+ # ::TheRad::TheView.should == 'TheRad::TheView'
65
+ # micon['TheRad::TheView'.to_sym].should == 'TheRad::TheView'
66
+ # end
67
+ #
68
+ # it "should check if constant is already defined" do
69
+ # micon.register :TheRouter, constant: true do
70
+ # class ::TheRouter; end
71
+ # 'TheRouter'
72
+ # end
73
+ # -> {::TheRouter}.should raise_error(/redefine/)
74
+ # end
75
+ # end
@@ -0,0 +1,3 @@
1
+ micon.register :TheController, constant: true do
2
+ "TheController"
3
+ end
@@ -1,49 +1,48 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Micon custom scope" do
4
- before :each do
5
- Micon.clear
6
- Micon.metadata.clear
3
+ describe "Custom Scope" do
4
+ before do
5
+ self.micon = Micon::Core.new
7
6
  end
8
7
 
9
8
  it "activate" do
10
9
  container = {}
11
- Micon.should_not be_active(:custom)
12
- Micon.activate :custom, container
13
- Micon.should be_active(:custom)
10
+ micon.should_not be_active(:custom)
11
+ micon.activate :custom, container
12
+ micon.should be_active(:custom)
14
13
 
15
- lambda{Micon.activate :custom, container}.should raise_error(/active/)
14
+ -> {micon.activate :custom, container}.should raise_error(/active/)
16
15
 
17
- Micon.deactivate :custom
18
- lambda{Micon.deactivate :custom}.should raise_error(/not active/)
16
+ micon.deactivate :custom
17
+ -> {micon.deactivate :custom}.should raise_error(/not active/)
19
18
 
20
- Micon.should_not be_active(:custom)
21
- Micon.activate :custom, container do
22
- Micon.should be_active(:custom)
19
+ micon.should_not be_active(:custom)
20
+ micon.activate :custom, container do
21
+ micon.should be_active(:custom)
23
22
  end
24
23
  end
25
24
 
26
25
  it "check" do
27
- Micon.register(:value, :scope => :custom){"The Object"}
28
- lambda{Micon[:value]}.should raise_error(/not started/)
29
- lambda{Micon[:value] = nil}.should raise_error(/not started/)
26
+ micon.register(:value, scope: :custom){"The Object"}
27
+ -> {micon[:value]}.should raise_error(/not started/)
28
+ -> {micon[:value] = 'value'}.should raise_error(/not started/)
30
29
  end
31
30
 
32
31
  it "get" do
33
- Micon.register(:value, :scope => :custom){"The Object"}
32
+ micon.register(:value, scope: :custom){"The Object"}
34
33
  container, the_object = {}, nil
35
34
 
36
- Micon.activate :custom, container do
37
- Micon[:value].should == "The Object"
38
- the_object = Micon[:value]
35
+ micon.activate :custom, container do
36
+ micon[:value].should == "The Object"
37
+ the_object = micon[:value]
39
38
  end
40
39
 
41
- Micon.activate :custom, {} do
42
- Micon[:value].object_id.should_not == the_object.object_id
40
+ micon.activate :custom, {} do
41
+ micon[:value].object_id.should_not == the_object.object_id
43
42
  end
44
43
 
45
- Micon.activate :custom, container do
46
- Micon[:value].object_id.should == the_object.object_id
44
+ micon.activate :custom, container do
45
+ micon[:value].object_id.should == the_object.object_id
47
46
  end
48
47
 
49
48
  container.size.should == 1
@@ -51,25 +50,25 @@ describe "Micon custom scope" do
51
50
  end
52
51
 
53
52
  it "set" do
54
- Micon.register(:value, :scope => :custom){"The Object"}
53
+ micon.register(:value, scope: :custom){"The Object"}
55
54
  container = {}
56
55
 
57
- Micon.activate :custom, container do
58
- Micon[:value].should == "The Object"
59
- Micon[:value] = "Another Object"
60
- the_object = Micon[:value]
56
+ micon.activate :custom, container do
57
+ micon[:value].should == "The Object"
58
+ micon[:value] = "Another Object"
59
+ the_object = micon[:value]
61
60
  end
62
61
 
63
- Micon.activate :custom, {} do
64
- Micon[:value].should == "The Object"
62
+ micon.activate :custom, {} do
63
+ micon[:value].should == "The Object"
65
64
  end
66
65
 
67
- Micon.activate :custom, container do
68
- Micon[:value].should == "Another Object"
66
+ micon.activate :custom, container do
67
+ micon[:value].should == "Another Object"
69
68
  end
70
69
  end
71
70
 
72
71
  it "scope should return block value (from error)" do
73
- Micon.activate(:custom, {}){'value'}.should == 'value'
72
+ micon.activate(:custom, {}){'value'}.should == 'value'
74
73
  end
75
74
  end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Initialization" do
4
+ after do
5
+ remove_constants :TheRouter
6
+ end
7
+
8
+ it "clone" do
9
+ m = Micon::Core.new
10
+ m.initialize!
11
+
12
+ m.register(:the_value){'the_value'}
13
+ m[:the_value]
14
+
15
+ another = m.clone
16
+ another.metadata.should include(:the_value)
17
+ another.instance_variable_get('@registry').should include(:the_value)
18
+ another.instance_variable_get('@application').should include(:the_value)
19
+ end
20
+
21
+ it "initialize! should set caller as global, deinitialize! should remove it" do
22
+ m = Micon::Core.new
23
+ m.initialize!
24
+
25
+ ::MICON.object_id.should == m.object_id
26
+ m.deinitialize!
27
+ Object.const_defined?(:MICON).should be_false
28
+ end
29
+
30
+ it "should support isolation" do
31
+ m1 = Micon::Core.new
32
+ m1.initialize!
33
+
34
+ m1.register(:first){'first'}
35
+ m1.first.should == 'first'
36
+
37
+ m1.deinitialize!
38
+
39
+ # m2
40
+ m2 = m1.clone
41
+ m2.initialize!
42
+
43
+ m2.first.should == 'first'
44
+ m2.register(:second){'second'}
45
+ m2.second.should == 'second'
46
+ m2.deinitialize!
47
+
48
+ # m1 shouldn't have any of m2 stuff
49
+ m1.initialize!
50
+ m1.first.should == 'first'
51
+ m1.metadata.should_not include(:second)
52
+ m1.include? :second
53
+ m1.should_not include(:second)
54
+ end
55
+
56
+ # describe "constants" do
57
+ # it "deinitialize! should delete all defined constants" do
58
+ # m = Micon::Core.new
59
+ # m.initialize!
60
+ #
61
+ # m.register(:TheRouter, constant: true){'TheRouter'}
62
+ # ::TheRouter.should == 'TheRouter'
63
+ #
64
+ # m.deinitialize!
65
+ # Object.const_defined?(:TheRouter).should be_false
66
+ #
67
+ # m.initialize!
68
+ # ::TheRouter.should == 'TheRouter'
69
+ # end
70
+ # end
71
+ end
@@ -1,33 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Micon Managed" do
3
+ describe "Managed" do
4
4
  before :all do
5
- Micon.metadata.clear
5
+ self.micon = Micon::Core.new
6
6
 
7
7
  class ManagedObject
8
8
  register_as :managed_object
9
- inject :object => :object_key
9
+ inject object: :object_key
10
10
 
11
11
  class << self
12
- inject :object => :object_key
12
+ inject object: :object_key
13
13
  end
14
14
  end
15
15
  end
16
16
 
17
- before :each do
18
- Micon.clear
17
+ before do
18
+ micon.clear
19
19
  end
20
20
 
21
21
  it "scope" do
22
- scope = Micon.metadata[:managed_object]
23
- initializer, dependencies = Micon.metadata.initializers[:managed_object]
22
+ scope = micon.metadata[:managed_object]
23
+ initializer, dependencies = micon.metadata.initializers[:managed_object]
24
24
  scope.should == :application
25
25
  initializer.call.should be_a(ManagedObject)
26
26
  end
27
27
 
28
28
  it "injection" do
29
29
  the_object = "The Object"
30
- Micon.register(:object_key){the_object}
30
+ micon.register(:object_key){the_object}
31
31
 
32
32
  ManagedObject.object.should == the_object
33
33
  o = ManagedObject.new
@@ -36,16 +36,16 @@ describe "Micon Managed" do
36
36
 
37
37
  it "outjection" do
38
38
  the_object = "The Object"
39
- Micon.register(:object_key)
39
+ micon.register(:object_key)
40
40
 
41
- ManagedObject.object.should be_nil
41
+ -> {ManagedObject.object}.should raise_error(/no initializer/)
42
42
  ManagedObject.object = the_object
43
43
  ManagedObject.object.should == the_object
44
44
  end
45
45
 
46
46
  it "empty?" do
47
- Micon.should be_empty
48
- Micon[:managed_object]
49
- Micon.should_not be_empty
47
+ micon.should be_empty
48
+ micon[:managed_object]
49
+ micon.should_not be_empty
50
50
  end
51
51
  end
@@ -1,52 +1,56 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Micelaneous" do
4
- before :each do
5
- Micon.clear
6
- Micon.metadata.clear
7
- end
3
+ describe "Micelaneous" do
4
+ with_load_path "#{spec_dir}/autoload/lib"
8
5
 
9
- it "swap_metadata" do
10
- Micon.register :the_object
11
- Micon.metadata[:the_object].should_not be_nil
12
- Micon.instance_variable_get("@_r").should include(:the_object)
13
-
14
- old_metadat = Micon.swap_metadata
15
-
16
- Micon.metadata[:the_object].should be_nil
17
- Micon.instance_variable_get("@_r").should_not include(:the_object)
18
-
19
- Micon.swap_metadata old_metadat
20
- Micon.metadata[:the_object].should_not be_nil
21
- Micon.instance_variable_get("@_r").should include(:the_object)
22
- end
6
+ before do
7
+ self.micon = Micon::Core.new
8
+ end
23
9
 
24
- it "dependencies" do
25
- Micon.register :another_object, :depends_on => :the_object
26
- lambda{Micon[:another_object]}.should raise_error(/the_object/)
27
- Micon.register :the_object
28
- Micon[:another_object]
10
+ after do
11
+ remove_constants :TheRouter, :TheRad
29
12
  end
30
13
 
14
+ describe "autoloading" do
15
+ it "should autoload component definition" do
16
+ micon[:some_value].should == "some_value"
17
+ end
18
+
19
+ # it 'should autoload component - constants (and nested constants)' do
20
+ # TheRouter.should == "TheRouter"
21
+ # module ::TheRad; end
22
+ # TheRad::TheView.should == "TheView"
23
+ # end
24
+ end
25
+
31
26
  it "should not initialize twice (from error)" do
32
27
  check = mock
33
28
  check.should_receive(:environment).once.ordered
34
29
  check.should_receive(:router).once.ordered
35
30
 
36
- Micon.register :environment do
31
+ micon.register :environment do
37
32
  check.environment
38
33
  'environment'
39
34
  end
40
35
 
41
- Micon.register :router, :depends_on => :environment do
36
+ micon.register :router, depends_on: :environment do
42
37
  check.router
43
38
  'router'
44
39
  end
45
- Micon.after :environment do
40
+ micon.after :environment do
46
41
  # some code that needs :router
47
- Micon[:router]
42
+ micon[:router]
48
43
  end
49
44
 
50
- Micon[:router]
45
+ micon[:router]
51
46
  end
47
+
48
+ it "helper method generation" do
49
+ micon.register :router
50
+
51
+ micon.router?.should be_false
52
+ micon.router = 'router'
53
+ micon.router?.should be_true
54
+ micon.router.should == 'router'
55
+ end
52
56
  end
@@ -0,0 +1,3 @@
1
+ micon.register :TheView, constant: true do
2
+ "TheView"
3
+ end
@@ -0,0 +1,3 @@
1
+ micon.register :TheRouter, constant: true do
2
+ "TheRouter"
3
+ end
@@ -0,0 +1,3 @@
1
+ micon.register :some_value do
2
+ "some_value"
3
+ end
@@ -1,31 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Micon nested custom scope" do
4
- before :each do
5
- Micon.clear
6
- Micon.metadata.clear
3
+ describe "Nested custom scope" do
4
+ before do
5
+ self.micon = Micon::Core.new
7
6
  end
8
7
 
9
8
  it "with block" do
10
- Micon.register :value, :scope => :custom
9
+ micon.register :value, scope: :custom
11
10
 
12
11
  custom_a = {}
13
- Micon.activate :custom, custom_a do
14
- Micon[:value] = 'value a'
12
+ micon.activate :custom, custom_a do
13
+ micon[:value] = 'value a'
15
14
 
16
15
  custom_b = {}
17
- Micon.activate :custom, custom_b do
18
- Micon[:value].should be_nil
19
- Micon[:value] = 'value b'
20
- Micon[:value].should == 'value b'
16
+ micon.activate :custom, custom_b do
17
+ micon.should_not include(:value)
18
+ micon[:value] = 'value b'
19
+ micon[:value].should == 'value b'
21
20
  end
22
21
 
23
- Micon[:value].should == 'value a'
22
+ micon[:value].should == 'value a'
24
23
  end
25
24
  end
26
25
 
27
26
  it "should not support nested scopes without block" do
28
- Micon.activate :custom, {}
29
- lambda{Micon.activate :custom, {}}.should raise_error(/active/)
27
+ micon.activate :custom, {}
28
+ -> {micon.activate :custom, {}}.should raise_error(/active/)
30
29
  end
31
30
  end