micon 0.1.17 → 0.1.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,70 +1,70 @@
1
1
  # require 'spec_helper'
2
- #
2
+ #
3
3
  # describe "Autoloading" do
4
4
  # with_load_path "#{spec_dir}/get_constant_component/lib"
5
- #
5
+ #
6
6
  # before do
7
7
  # self.micon = Micon::Core.new
8
8
  # end
9
- #
9
+ #
10
10
  # after do
11
11
  # remove_constants :TheRouter, :TheRad, :TheController, :SomeModule
12
12
  # end
13
- #
13
+ #
14
14
  # describe "get_constant_component" do
15
15
  # it "should autoload components" do
16
16
  # micon.get_constant_component(:TheController).should == "TheController"
17
17
  # end
18
- #
18
+ #
19
19
  # it "should not raise error if component not defined" do
20
20
  # micon.get_constant_component(:TheValue).should == nil
21
21
  # micon.register(:TheValue, constant: true){"TheValue"}
22
22
  # micon.get_constant_component(:TheValue).should == "TheValue"
23
23
  # end
24
- #
24
+ #
25
25
  # it "should get constants only" do
26
26
  # micon.register(:TheController){"TheController"}
27
27
  # micon.get_constant_component(:TheController).should == nil
28
- #
28
+ #
29
29
  # micon.register(:TheController, constant: true){"TheController"}
30
30
  # micon.get_constant_component(:TheController).should == "TheController"
31
31
  # end
32
32
  # end
33
- #
33
+ #
34
34
  # it 'validation' do
35
35
  # -> {micon.register 'TheController', constant: true}.should raise_error(/symbol/)
36
36
  # -> {micon.register 'TheController'.to_sym, constant: true, scope: :custom}.should raise_error(/scope/)
37
37
  # end
38
- #
38
+ #
39
39
  # it "should use constants as components" do
40
40
  # -> {::TheRouter}.should raise_error(/uninitialized constant/)
41
- #
41
+ #
42
42
  # micon.register :TheRouter, constant: true do
43
43
  # "TheRouter"
44
- # end
45
- #
44
+ # end
45
+ #
46
46
  # module ::TheRad
47
47
  # TheRouter.should == 'TheRouter'
48
48
  # end
49
49
  # ::TheRouter.should == 'TheRouter'
50
50
  # micon[:TheRouter].should == 'TheRouter'
51
51
  # end
52
- #
52
+ #
53
53
  # it "should support nested constants" do
54
- # module ::TheRad; end
54
+ # module ::TheRad; end
55
55
  # -> {::TheRad::TheView}.should raise_error(/uninitialized constant/)
56
- #
56
+ #
57
57
  # micon.register 'TheRad::TheView'.to_sym, constant: true do
58
58
  # 'TheRad::TheView'
59
- # end
60
- #
59
+ # end
60
+ #
61
61
  # module ::SomeModule
62
62
  # ::TheRad::TheView.should == 'TheRad::TheView'
63
63
  # end
64
64
  # ::TheRad::TheView.should == 'TheRad::TheView'
65
65
  # micon['TheRad::TheView'.to_sym].should == 'TheRad::TheView'
66
66
  # end
67
- #
67
+ #
68
68
  # it "should check if constant is already defined" do
69
69
  # micon.register :TheRouter, constant: true do
70
70
  # class ::TheRouter; end
@@ -4,9 +4,9 @@ describe "Custom Scope" do
4
4
  before do
5
5
  self.micon = Micon::Core.new
6
6
  end
7
-
7
+
8
8
  it "activate" do
9
- container = {}
9
+ container = {}
10
10
  micon.should_not be_active(:custom)
11
11
  micon.activate :custom, container
12
12
  micon.should be_active(:custom)
@@ -15,59 +15,59 @@ describe "Custom Scope" do
15
15
 
16
16
  micon.deactivate :custom
17
17
  -> {micon.deactivate :custom}.should raise_error(/not active/)
18
-
18
+
19
19
  micon.should_not be_active(:custom)
20
20
  micon.activate :custom, container do
21
21
  micon.should be_active(:custom)
22
22
  end
23
23
  end
24
-
24
+
25
25
  it "check" do
26
26
  micon.register(:value, scope: :custom){"The Object"}
27
27
  -> {micon[:value]}.should raise_error(/not started/)
28
28
  -> {micon[:value] = 'value'}.should raise_error(/not started/)
29
29
  end
30
-
30
+
31
31
  it "get" do
32
32
  micon.register(:value, scope: :custom){"The Object"}
33
33
  container, the_object = {}, nil
34
-
34
+
35
35
  micon.activate :custom, container do
36
36
  micon[:value].should == "The Object"
37
37
  the_object = micon[:value]
38
38
  end
39
-
39
+
40
40
  micon.activate :custom, {} do
41
41
  micon[:value].object_id.should_not == the_object.object_id
42
42
  end
43
-
43
+
44
44
  micon.activate :custom, container do
45
45
  micon[:value].object_id.should == the_object.object_id
46
46
  end
47
-
47
+
48
48
  container.size.should == 1
49
49
  container[:value].should == the_object
50
50
  end
51
-
51
+
52
52
  it "set" do
53
53
  micon.register(:value, scope: :custom){"The Object"}
54
54
  container = {}
55
-
55
+
56
56
  micon.activate :custom, container do
57
57
  micon[:value].should == "The Object"
58
58
  micon[:value] = "Another Object"
59
59
  the_object = micon[:value]
60
60
  end
61
-
61
+
62
62
  micon.activate :custom, {} do
63
63
  micon[:value].should == "The Object"
64
64
  end
65
-
65
+
66
66
  micon.activate :custom, container do
67
67
  micon[:value].should == "Another Object"
68
68
  end
69
69
  end
70
-
70
+
71
71
  it "scope should return block value (from error)" do
72
72
  micon.activate(:custom, {}){'value'}.should == 'value'
73
73
  end
@@ -1,23 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Initialization" do
3
+ describe "Initialization" do
4
4
  after do
5
5
  remove_constants :TheRouter
6
6
  end
7
-
7
+
8
8
  it "clone" do
9
9
  m = Micon::Core.new
10
10
  m.initialize!
11
-
11
+
12
12
  m.register(:the_value){'the_value'}
13
13
  m[:the_value]
14
-
14
+
15
15
  another = m.clone
16
16
  another.metadata.should include(:the_value)
17
17
  another.instance_variable_get('@registry').should include(:the_value)
18
18
  another.instance_variable_get('@application').should include(:the_value)
19
19
  end
20
-
20
+
21
21
  it "initialize! should set caller as global, deinitialize! should remove it" do
22
22
  m = Micon::Core.new
23
23
  m.initialize!
@@ -26,44 +26,44 @@ describe "Initialization" do
26
26
  m.deinitialize!
27
27
  Object.const_defined?(:MICON).should be_false
28
28
  end
29
-
29
+
30
30
  it "should support isolation" do
31
31
  m1 = Micon::Core.new
32
32
  m1.initialize!
33
-
33
+
34
34
  m1.register(:first){'first'}
35
35
  m1.first.should == 'first'
36
-
36
+
37
37
  m1.deinitialize!
38
-
38
+
39
39
  # m2
40
40
  m2 = m1.clone
41
41
  m2.initialize!
42
-
42
+
43
43
  m2.first.should == 'first'
44
44
  m2.register(:second){'second'}
45
45
  m2.second.should == 'second'
46
46
  m2.deinitialize!
47
-
47
+
48
48
  # m1 shouldn't have any of m2 stuff
49
49
  m1.initialize!
50
50
  m1.first.should == 'first'
51
51
  m1.metadata.should_not include(:second)
52
52
  m1.include? :second
53
- m1.should_not include(:second)
53
+ m1.should_not include(:second)
54
54
  end
55
-
55
+
56
56
  # describe "constants" do
57
57
  # it "deinitialize! should delete all defined constants" do
58
58
  # m = Micon::Core.new
59
59
  # m.initialize!
60
- #
60
+ #
61
61
  # m.register(:TheRouter, constant: true){'TheRouter'}
62
62
  # ::TheRouter.should == 'TheRouter'
63
- #
63
+ #
64
64
  # m.deinitialize!
65
65
  # Object.const_defined?(:TheRouter).should be_false
66
- #
66
+ #
67
67
  # m.initialize!
68
68
  # ::TheRouter.should == 'TheRouter'
69
69
  # end
data/spec/managed_spec.rb CHANGED
@@ -3,17 +3,17 @@ require 'spec_helper'
3
3
  describe "Managed" do
4
4
  before :all do
5
5
  self.micon = Micon::Core.new
6
-
7
- class ManagedObject
6
+
7
+ class ManagedObject
8
8
  register_as :managed_object
9
9
  inject object: :object_key
10
10
 
11
- class << self
11
+ class << self
12
12
  inject object: :object_key
13
13
  end
14
14
  end
15
15
  end
16
-
16
+
17
17
  before do
18
18
  micon.clear
19
19
  end
@@ -33,7 +33,7 @@ describe "Managed" do
33
33
  o = ManagedObject.new
34
34
  o.object.should == the_object
35
35
  end
36
-
36
+
37
37
  it "outjection" do
38
38
  the_object = "The Object"
39
39
  micon.register(:object_key)
@@ -42,7 +42,7 @@ describe "Managed" do
42
42
  ManagedObject.object = the_object
43
43
  ManagedObject.object.should == the_object
44
44
  end
45
-
45
+
46
46
  it "empty?" do
47
47
  micon.should be_empty
48
48
  micon[:managed_object]
@@ -1,24 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Miscellaneous" do
4
- with_load_path "#{spec_dir}/autoload/lib"
5
-
6
- before{self.micon = Micon::Core.new}
4
+ with_load_path "#{spec_dir}/autoload/lib"
5
+
6
+ before{self.micon = Micon::Core.new}
7
7
  after{remove_constants :TheRouter, :TheRad}
8
-
9
- describe "autoloading" do
8
+
9
+ describe "autoloading" do
10
10
  it "should autoload component definition" do
11
11
  micon[:some_value].should == "some_value"
12
12
  end
13
-
14
- # it 'should autoload component - constants (and nested constants)' do
13
+
14
+ # it 'should autoload component - constants (and nested constants)' do
15
15
  # TheRouter.should == "TheRouter"
16
16
  # module ::TheRad; end
17
17
  # TheRad::TheView.should == "TheView"
18
18
  # end
19
19
  end
20
-
21
- describe "complex circullar dependencies" do
20
+
21
+ describe "complex circullar dependencies" do
22
22
  it "should not initialize twice (from error)" do
23
23
  micon.register :kit do
24
24
  micon[:kit]
@@ -26,7 +26,7 @@ describe "Miscellaneous" do
26
26
  end
27
27
  lambda{micon[:kit]}.should raise_error(/component :kit used before it's initialization is finished/)
28
28
  end
29
-
29
+
30
30
  it "should not initialize twice if called from dependency (from error)" do
31
31
  micon.register :environment do
32
32
  micon[:router]
@@ -39,7 +39,7 @@ describe "Miscellaneous" do
39
39
 
40
40
  -> {micon[:router]}.should raise_error(/component .* used before it's initialization is finished/)
41
41
  end
42
-
42
+
43
43
  it "should allow to use circullar dependency in :after callback" do
44
44
  check = mock
45
45
  check.should_receive(:initialized).once
@@ -52,27 +52,27 @@ describe "Miscellaneous" do
52
52
  end
53
53
  micon[:kit].should == 'kit'
54
54
  end
55
-
55
+
56
56
  it "should allow circullar dependencies in :after callback" do
57
57
  micon.register :environment do
58
58
  'environment'
59
59
  end
60
-
60
+
61
61
  micon.register :router, depends_on: :environment do
62
62
  'router'
63
63
  end
64
-
64
+
65
65
  micon.after :environment do
66
66
  micon[:router]
67
67
  end
68
-
69
- micon[:router]
68
+
69
+ micon[:router]
70
70
  end
71
- end
72
-
71
+ end
72
+
73
73
  it "helper method generation" do
74
74
  micon.register :router
75
-
75
+
76
76
  micon.router?.should be_false
77
77
  micon.router = 'router'
78
78
  micon.router?.should be_true
@@ -4,25 +4,25 @@ describe "Nested custom scope" do
4
4
  before do
5
5
  self.micon = Micon::Core.new
6
6
  end
7
-
7
+
8
8
  it "with block" do
9
9
  micon.register :value, scope: :custom
10
-
10
+
11
11
  custom_a = {}
12
12
  micon.activate :custom, custom_a do
13
13
  micon[:value] = 'value a'
14
-
14
+
15
15
  custom_b = {}
16
16
  micon.activate :custom, custom_b do
17
17
  micon.should_not include(:value)
18
18
  micon[:value] = 'value b'
19
19
  micon[:value].should == 'value b'
20
20
  end
21
-
21
+
22
22
  micon[:value].should == 'value a'
23
23
  end
24
24
  end
25
-
25
+
26
26
  it "should not support nested scopes without block" do
27
27
  micon.activate :custom, {}
28
28
  -> {micon.activate :custom, {}}.should raise_error(/active/)
data/spec/spec_helper.rb CHANGED
@@ -6,9 +6,9 @@ require "micon"
6
6
  Micon::Core.send :include, Micon::Helper
7
7
 
8
8
  def micon; $micon end
9
- def micon= value
9
+ def micon= value
10
10
  $micon = value
11
11
  $micon.initialize!
12
-
12
+
13
13
  $micon
14
14
  end
@@ -1,39 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Application and Instance scopes" do
3
+ describe "Application and Instance scopes" do
4
4
  before{self.micon = Micon::Core.new}
5
-
6
- it "dependencies" do
5
+
6
+ it "dependencies" do
7
7
  micon.register(:another_object, depends_on: :the_object){"another_object"}
8
8
  -> {micon[:another_object]}.should raise_error(/the_object.*not managed/)
9
9
  micon.register(:the_object){"the_object"}
10
10
  micon[:another_object]
11
11
  end
12
-
13
- it "instance scope" do
12
+
13
+ it "instance scope" do
14
14
  micon.register(:value, scope: :instance){"The Object"}
15
-
15
+
16
16
  micon[:value].should == "The Object"
17
17
  micon[:value].object_id.should_not == micon[:value].object_id
18
18
  end
19
-
19
+
20
20
  it "application scope" do
21
21
  micon.register(:value){"The Object"}
22
-
22
+
23
23
  micon[:value].should == "The Object"
24
24
  micon[:value].object_id.should == micon[:value].object_id
25
25
  end
26
-
26
+
27
27
  it "should not allow to return nill in initializer" do
28
28
  micon.register(:value){nil}
29
29
  -> {micon[:value]}.should raise_error(/returns nill/)
30
30
  end
31
-
31
+
32
32
  it "should not allow to register component without initializer but shouldn't allow to instantiate it" do
33
33
  micon.register :value
34
34
  -> {micon[:value]}.should raise_error(/no initializer/)
35
35
  end
36
-
36
+
37
37
  it "should not allow to assign nill as component" do
38
38
  micon.register :value
39
39
  -> {micon[:value] = nil}.should raise_error(/can't assign nill/)
@@ -49,33 +49,33 @@ describe "Application and Instance scopes" do
49
49
  micon[:value] = the_object
50
50
  micon[:value].object_id.should == the_object.object_id
51
51
  end
52
-
52
+
53
53
  it "cycle reference" do
54
54
  class CycleB; end
55
-
56
- class CycleA
55
+
56
+ class CycleA
57
57
  register_as :cycle_a
58
58
  inject b: :cycle_b
59
59
  end
60
-
61
- class CycleB
60
+
61
+ class CycleB
62
62
  register_as :cycle_b
63
63
  inject a: :cycle_a
64
64
  end
65
-
65
+
66
66
  a = micon[:cycle_a]
67
67
  b = micon[:cycle_b]
68
68
  a.b.equal?(b).should be_true
69
69
  b.a.equal?(a).should be_true
70
- end
71
-
72
- it "unregister" do
70
+ end
71
+
72
+ it "unregister" do
73
73
  micon.register(:value){"The Object"}
74
74
  micon[:value].should == "The Object"
75
-
75
+
76
76
  micon.unregister :value
77
77
  -> {micon[:value]}.should raise_error(/component not managed/)
78
78
  end
79
-
79
+
80
80
  it 'delete'
81
81
  end