pancake 0.2.0 → 0.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.
Files changed (108) hide show
  1. data/bin/pancake +96 -0
  2. data/lib/pancake.rb +5 -7
  3. data/lib/pancake/configuration.rb +2 -23
  4. data/lib/pancake/core_ext/object.rb +1 -1
  5. data/lib/pancake/defaults/configuration.rb +21 -1
  6. data/lib/pancake/generators.rb +0 -3
  7. data/lib/pancake/hooks/inheritable_inner_classes.rb +15 -2
  8. data/lib/pancake/master.rb +34 -1
  9. data/lib/pancake/mixins/render.rb +1 -2
  10. data/lib/pancake/mixins/stack_helper.rb +1 -1
  11. data/lib/pancake/router.rb +18 -63
  12. data/lib/pancake/stack/configuration.rb +3 -5
  13. data/lib/pancake/stack/router.rb +10 -33
  14. data/lib/pancake/stack/stack.rb +70 -50
  15. data/{spec/helpers → lib/pancake/test}/helpers.rb +3 -3
  16. data/lib/pancake/test/matchers.rb +20 -0
  17. data/lib/pancake/vendor/hashie/.document +5 -0
  18. data/lib/pancake/vendor/hashie/.gitignore +7 -0
  19. data/lib/pancake/vendor/hashie/Gemfile +11 -0
  20. data/lib/pancake/vendor/hashie/Gemfile.lock +25 -0
  21. data/lib/pancake/{generators/templates/short/%stack_name%/LICENSE.tt → vendor/hashie/LICENSE} +1 -1
  22. data/lib/pancake/vendor/hashie/README.rdoc +101 -0
  23. data/lib/pancake/{generators/templates/micro/%stack_name%/Rakefile.tt → vendor/hashie/Rakefile} +3 -13
  24. data/lib/pancake/vendor/hashie/VERSION +1 -0
  25. data/lib/pancake/vendor/hashie/hashie.gemspec +33 -0
  26. data/lib/pancake/vendor/hashie/lib/hashie.rb +5 -0
  27. data/lib/pancake/vendor/hashie/lib/hashie/clash.rb +86 -0
  28. data/lib/pancake/vendor/hashie/lib/hashie/dash.rb +108 -0
  29. data/lib/pancake/vendor/hashie/lib/hashie/hash.rb +22 -0
  30. data/lib/pancake/vendor/hashie/lib/hashie/hash_extensions.rb +49 -0
  31. data/lib/pancake/vendor/hashie/lib/hashie/mash.rb +148 -0
  32. data/lib/pancake/vendor/hashie/spec/hashie/clash_spec.rb +42 -0
  33. data/lib/pancake/vendor/hashie/spec/hashie/dash_spec.rb +103 -0
  34. data/lib/pancake/vendor/hashie/spec/hashie/hash_spec.rb +22 -0
  35. data/lib/pancake/vendor/hashie/spec/hashie/mash_spec.rb +135 -0
  36. data/lib/pancake/vendor/hashie/spec/spec.opts +2 -0
  37. data/lib/pancake/{generators/templates/short/%stack_name%/spec/spec_helper.rb.tt → vendor/hashie/spec/spec_helper.rb} +7 -7
  38. data/spec/pancake/configuration_spec.rb +1 -1
  39. data/spec/pancake/constants_spec.rb +1 -1
  40. data/spec/pancake/defaults/configuration_spec.rb +1 -1
  41. data/spec/pancake/hooks/on_inherit_spec.rb +13 -13
  42. data/spec/pancake/inheritance_spec.rb +22 -22
  43. data/spec/pancake/middleware_spec.rb +6 -5
  44. data/spec/pancake/middlewares/logger_spec.rb +1 -1
  45. data/spec/pancake/middlewares/static_spec.rb +1 -1
  46. data/spec/pancake/mime_types_spec.rb +1 -1
  47. data/spec/pancake/mixins/publish_spec.rb +24 -24
  48. data/spec/pancake/mixins/render/template_spec.rb +1 -1
  49. data/spec/pancake/mixins/render/view_context_spec.rb +1 -1
  50. data/spec/pancake/mixins/render_spec.rb +1 -1
  51. data/spec/pancake/mixins/request_helper_spec.rb +1 -1
  52. data/spec/pancake/mixins/stack_helper_spec.rb +3 -3
  53. data/spec/pancake/pancake_spec.rb +1 -1
  54. data/spec/pancake/paths_spec.rb +30 -30
  55. data/spec/pancake/stack/router_spec.rb +24 -62
  56. data/spec/pancake/stack/stack_configuration_spec.rb +1 -1
  57. data/spec/pancake/stack/stack_spec.rb +47 -4
  58. data/spec/spec_helper.rb +3 -3
  59. metadata +56 -128
  60. data/bin/pancake-gen +0 -30
  61. data/lib/pancake/bootloaders.rb +0 -187
  62. data/lib/pancake/generators/base.rb +0 -12
  63. data/lib/pancake/generators/micro_generator.rb +0 -17
  64. data/lib/pancake/generators/short_generator.rb +0 -18
  65. data/lib/pancake/generators/templates/common/dotgitignore +0 -22
  66. data/lib/pancake/generators/templates/common/dothtaccess +0 -17
  67. data/lib/pancake/generators/templates/micro/%stack_name%/%stack_name%.rb.tt +0 -8
  68. data/lib/pancake/generators/templates/micro/%stack_name%/config.ru.tt +0 -12
  69. data/lib/pancake/generators/templates/micro/%stack_name%/pancake_init.rb.tt +0 -1
  70. data/lib/pancake/generators/templates/micro/%stack_name%/public/.empty_directory +0 -0
  71. data/lib/pancake/generators/templates/micro/%stack_name%/tmp/.empty_directory +0 -0
  72. data/lib/pancake/generators/templates/micro/%stack_name%/views/root.html.haml +0 -1
  73. data/lib/pancake/generators/templates/short/%stack_name%/README.tt +0 -7
  74. data/lib/pancake/generators/templates/short/%stack_name%/Rakefile.tt +0 -56
  75. data/lib/pancake/generators/templates/short/%stack_name%/VERSION.tt +0 -1
  76. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%.rb.tt +0 -12
  77. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/%stack_name%.rb.tt +0 -6
  78. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config.ru.tt +0 -10
  79. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config/config.rb.tt +0 -23
  80. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config/environments/development.rb.tt +0 -15
  81. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config/environments/production.rb.tt +0 -16
  82. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config/environments/staging.rb.tt +0 -17
  83. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/models/.empty_directory +0 -0
  84. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/mounts/.empty_directory +0 -0
  85. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/public/.empty_directory +0 -0
  86. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/tasks/%stack_name%.rake.tt +0 -4
  87. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/tmp/.empty_directory +0 -0
  88. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/views/root.html.haml +0 -2
  89. data/lib/pancake/generators/templates/short/%stack_name%/pancake_init.rb.tt +0 -1
  90. data/lib/pancake/generators/templates/short/%stack_name%/spec/%stack_name%_spec.rb.tt +0 -11
  91. data/lib/pancake/stack/app.rb +0 -10
  92. data/lib/pancake/stack/bootloader.rb +0 -114
  93. data/lib/pancake/stack/middleware.rb +0 -0
  94. data/lib/pancake/stacks/short.rb +0 -3
  95. data/lib/pancake/stacks/short/bootloaders.rb +0 -5
  96. data/lib/pancake/stacks/short/controller.rb +0 -184
  97. data/lib/pancake/stacks/short/default/views/base.html.haml +0 -5
  98. data/lib/pancake/stacks/short/default/views/error.html.haml +0 -12
  99. data/lib/pancake/stacks/short/stack.rb +0 -207
  100. data/spec/helpers/matchers.rb +0 -25
  101. data/spec/pancake/bootloaders_spec.rb +0 -119
  102. data/spec/pancake/stack/app_spec.rb +0 -28
  103. data/spec/pancake/stack/bootloader_spec.rb +0 -41
  104. data/spec/pancake/stack/middleware_spec.rb +0 -0
  105. data/spec/pancake/stacks/short/controller_spec.rb +0 -442
  106. data/spec/pancake/stacks/short/middlewares_spec.rb +0 -22
  107. data/spec/pancake/stacks/short/router_spec.rb +0 -150
  108. data/spec/pancake/stacks/short/stack_spec.rb +0 -117
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Hashie::Clash do
4
+ before do
5
+ @c = Hashie::Clash.new
6
+ end
7
+
8
+ it 'should be able to set an attribute via method_missing' do
9
+ @c.foo('bar')
10
+ @c[:foo].should == 'bar'
11
+ end
12
+
13
+ it 'should be able to set multiple attributes' do
14
+ @c.foo('bar').baz('wok')
15
+ @c.should == {:foo => 'bar', :baz => 'wok'}
16
+ end
17
+
18
+ it 'should convert multiple arguments into an array' do
19
+ @c.foo(1, 2, 3)
20
+ @c[:foo].should == [1,2,3]
21
+ end
22
+
23
+ it 'should be able to use bang notation to create a new Clash on a key' do
24
+ @c.foo!
25
+ @c[:foo].should be_kind_of(Hashie::Clash)
26
+ end
27
+
28
+ it 'should be able to chain onto the new Clash when using bang notation' do
29
+ @c.foo!.bar('abc').baz(123)
30
+ @c.should == {:foo => {:bar => 'abc', :baz => 123}}
31
+ end
32
+
33
+ it 'should be able to jump back up to the parent in the chain with #_end!' do
34
+ @c.foo!.bar('abc')._end!.baz(123)
35
+ @c.should == {:foo => {:bar => 'abc'}, :baz => 123}
36
+ end
37
+
38
+ it 'should merge rather than replace existing keys' do
39
+ @c.where(:abc => 'def').where(:hgi => 123)
40
+ @c.should == {:where => {:abc => 'def', :hgi => 123}}
41
+ end
42
+ end
@@ -0,0 +1,103 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ class DashTest < Hashie::Dash
4
+ property :first_name
5
+ property :email
6
+ property :count, :default => 0
7
+ end
8
+
9
+ class Subclassed < DashTest
10
+ property :last_name
11
+ end
12
+
13
+ describe Hashie::Dash do
14
+ it 'should be a subclass of Hashie::Hash' do
15
+ (Hashie::Dash < Hash).should be_true
16
+ end
17
+
18
+ it '#inspect should be ok!' do
19
+ dash = DashTest.new
20
+ dash.email = "abd@abc.com"
21
+ dash.inspect.should == "<#DashTest count=0 email=\"abd@abc.com\" first_name=nil>"
22
+ end
23
+
24
+ describe ' creating properties' do
25
+ it 'should add the property to the list' do
26
+ DashTest.property :not_an_att
27
+ DashTest.properties.include?('not_an_att').should be_true
28
+ end
29
+
30
+ it 'should create a method for reading the property' do
31
+ DashTest.new.respond_to?(:first_name).should be_true
32
+ end
33
+
34
+ it 'should create a method for writing the property' do
35
+ DashTest.new.respond_to?(:first_name=).should be_true
36
+ end
37
+ end
38
+
39
+ describe 'reading properties' do
40
+ it 'should raise an error when reading a non-existent property' do
41
+ lambda{@dash['abc']}.should raise_error(NoMethodError)
42
+ end
43
+ end
44
+
45
+ describe ' writing to properties' do
46
+ before do
47
+ @dash = DashTest.new
48
+ end
49
+
50
+ it 'should not be able to write to a non-existent property using []=' do
51
+ lambda{@dash['abc'] = 123}.should raise_error(NoMethodError)
52
+ end
53
+
54
+ it 'should be able to write to an existing property using []=' do
55
+ lambda{@dash['first_name'] = 'Bob'}.should_not raise_error
56
+ end
57
+
58
+ it 'should be able to read/write to an existing property using a method call' do
59
+ @dash.first_name = 'Franklin'
60
+ @dash.first_name.should == 'Franklin'
61
+ end
62
+ end
63
+
64
+ describe ' initializing with a Hash' do
65
+ it 'should not be able to initialize non-existent properties' do
66
+ lambda{DashTest.new(:bork => 'abc')}.should raise_error(NoMethodError)
67
+ end
68
+
69
+ it 'should set properties that it is able to' do
70
+ DashTest.new(:first_name => 'Michael').first_name.should == 'Michael'
71
+ end
72
+ end
73
+
74
+ describe ' defaults' do
75
+ before do
76
+ @dash = DashTest.new
77
+ end
78
+
79
+ it 'should return the default value for defaulted' do
80
+ DashTest.property :defaulted, :default => 'abc'
81
+ DashTest.new.defaulted.should == 'abc'
82
+ end
83
+ end
84
+ end
85
+
86
+ describe Subclassed do
87
+ it "should inherit all properties from DashTest" do
88
+ Subclassed.properties.size.should == 6
89
+ end
90
+
91
+ it "should inherit all defaults from DashTest" do
92
+ Subclassed.defaults.size.should == 6
93
+ end
94
+
95
+ it "should init without raising" do
96
+ lambda { Subclassed.new }.should_not raise_error
97
+ lambda { Subclassed.new(:first_name => 'Michael') }.should_not raise_error
98
+ end
99
+
100
+ it "should share defaults from DashTest" do
101
+ Subclassed.new.count.should == 0
102
+ end
103
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Hash do
4
+ it "should be convertible to a Hashie::Mash" do
5
+ mash = Hashie::Hash[:some => "hash"].to_mash
6
+ mash.is_a?(Hashie::Mash).should be_true
7
+ mash.some.should == "hash"
8
+ end
9
+
10
+ it "#stringify_keys! should turn all keys into strings" do
11
+ hash = Hashie::Hash[:a => "hey", 123 => "bob"]
12
+ hash.stringify_keys!
13
+ hash.should == Hashie::Hash["a" => "hey", "123" => "bob"]
14
+ end
15
+
16
+ it "#stringify_keys should return a hash with stringified keys" do
17
+ hash = Hashie::Hash[:a => "hey", 123 => "bob"]
18
+ stringified_hash = hash.stringify_keys
19
+ hash.should == Hashie::Hash[:a => "hey", 123 => "bob"]
20
+ stringified_hash.should == Hashie::Hash["a" => "hey", "123" => "bob"]
21
+ end
22
+ end
@@ -0,0 +1,135 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Hashie::Mash do
4
+ before(:each) do
5
+ @mash = Hashie::Mash.new
6
+ end
7
+
8
+ it "should inherit from hash" do
9
+ @mash.is_a?(Hash).should be_true
10
+ end
11
+
12
+ it "should be able to set hash values through method= calls" do
13
+ @mash.test = "abc"
14
+ @mash["test"].should == "abc"
15
+ end
16
+
17
+ it "should be able to retrieve set values through method calls" do
18
+ @mash["test"] = "abc"
19
+ @mash.test.should == "abc"
20
+ end
21
+
22
+ it "should test for already set values when passed a ? method" do
23
+ @mash.test?.should be_false
24
+ @mash.test = "abc"
25
+ @mash.test?.should be_true
26
+ end
27
+
28
+ it "should make all [] and []= into strings for consistency" do
29
+ @mash["abc"] = 123
30
+ @mash.key?('abc').should be_true
31
+ @mash["abc"].should == 123
32
+ end
33
+
34
+ it "should have a to_s that is identical to its inspect" do
35
+ @mash.abc = 123
36
+ @mash.to_s.should == @mash.inspect
37
+ end
38
+
39
+ it "should return nil instead of raising an error for attribute-esque method calls" do
40
+ @mash.abc.should be_nil
41
+ end
42
+
43
+ it "should return a Hashie::Mash when passed a bang method to a non-existenct key" do
44
+ @mash.abc!.is_a?(Hashie::Mash).should be_true
45
+ end
46
+
47
+ it "should return the existing value when passed a bang method for an existing key" do
48
+ @mash.name = "Bob"
49
+ @mash.name!.should == "Bob"
50
+ end
51
+
52
+ it "#initializing_reader should return a Hashie::Mash when passed a non-existent key" do
53
+ @mash.initializing_reader(:abc).is_a?(Hashie::Mash).should be_true
54
+ end
55
+
56
+ it "should allow for multi-level assignment through bang methods" do
57
+ @mash.author!.name = "Michael Bleigh"
58
+ @mash.author.should == Hashie::Mash.new(:name => "Michael Bleigh")
59
+ @mash.author!.website!.url = "http://www.mbleigh.com/"
60
+ @mash.author.website.should == Hashie::Mash.new(:url => "http://www.mbleigh.com/")
61
+ end
62
+
63
+ it "#deep_update should recursively Hashie::Mash Hashie::Mashes and hashes together" do
64
+ @mash.first_name = "Michael"
65
+ @mash.last_name = "Bleigh"
66
+ @mash.details = Hashie::Hash[:email => "michael@asf.com"].to_mash
67
+ @mash.deep_update({:details => {:email => "michael@intridea.com"}})
68
+ @mash.details.email.should == "michael@intridea.com"
69
+ end
70
+
71
+ it "should convert hash assignments into Hashie::Mashes" do
72
+ @mash.details = {:email => 'randy@asf.com', :address => {:state => 'TX'} }
73
+ @mash.details.email.should == 'randy@asf.com'
74
+ @mash.details.address.state.should == 'TX'
75
+ end
76
+
77
+ it "should not convert the type of Hashie::Mashes childs to Hashie::Mash" do
78
+ class MyMash < Hashie::Mash
79
+ end
80
+
81
+ record = MyMash.new
82
+ record.son = MyMash.new
83
+ record.son.class.should == MyMash
84
+ end
85
+
86
+ context "#initialize" do
87
+ it "should convert an existing hash to a Hashie::Mash" do
88
+ converted = Hashie::Mash.new({:abc => 123, :name => "Bob"})
89
+ converted.abc.should == 123
90
+ converted.name.should == "Bob"
91
+ end
92
+
93
+ it "should convert hashes recursively into Hashie::Mashes" do
94
+ converted = Hashie::Mash.new({:a => {:b => 1, :c => {:d => 23}}})
95
+ converted.a.is_a?(Hashie::Mash).should be_true
96
+ converted.a.b.should == 1
97
+ converted.a.c.d.should == 23
98
+ end
99
+
100
+ it "should convert hashes in arrays into Hashie::Mashes" do
101
+ converted = Hashie::Mash.new({:a => [{:b => 12}, 23]})
102
+ converted.a.first.b.should == 12
103
+ converted.a.last.should == 23
104
+ end
105
+
106
+ it "should convert an existing Hashie::Mash into a Hashie::Mash" do
107
+ initial = Hashie::Mash.new(:name => 'randy', :address => {:state => 'TX'})
108
+ copy = Hashie::Mash.new(initial)
109
+ initial.name.should == copy.name
110
+ initial.object_id.should_not == copy.object_id
111
+ copy.address.state.should == 'TX'
112
+ copy.address.state = 'MI'
113
+ initial.address.state.should == 'TX'
114
+ copy.address.object_id.should_not == initial.address.object_id
115
+ end
116
+
117
+ it "should accept a default block" do
118
+ initial = Hashie::Mash.new { |h,i| h[i] = []}
119
+ initial.default_proc.should_not be_nil
120
+ initial.default.should be_nil
121
+ initial.test.should == []
122
+ initial.test?.should be_true
123
+ end
124
+
125
+ describe "to_json" do
126
+
127
+ it "should render to_json" do
128
+ @mash.foo = :bar
129
+ @mash.bar = {"homer" => "simpson"}
130
+ expected = {"foo" => "bar", "bar" => {"homer" => "simpson"}}
131
+ JSON.parse(@mash.to_json).should == expected
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
@@ -1,13 +1,13 @@
1
- require 'spec'
2
- require 'rack/test'
3
- require 'pancake'
4
-
1
+ require 'rubygems'
2
+ require 'json'
5
3
 
6
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
- require '<%= stack_name -%>'
6
+
7
+ require 'hashie'
8
+ require 'spec'
9
+ require 'spec/autorun'
9
10
 
10
11
  Spec::Runner.configure do |config|
11
- config.include(Rack::Test::Methods)
12
- config.include(Pancake::Test::Matchers)
12
+
13
13
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Pancake::Configuration" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Pancake::Constants do
4
4
  it "should have the ENV_LOGGER_KEY constant" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Pancake configuration defaults" do
4
4
  describe "logging defaults" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Pancake::Stack inheritance" do
4
4
  describe "inheritance hooks" do
@@ -11,17 +11,17 @@ describe "Pancake::Stack inheritance" do
11
11
  Pancake::Stack.on_inherit(&blk)
12
12
  end
13
13
  end
14
-
14
+
15
15
  before(:each) do
16
16
  $collector = []
17
17
  clear_constants(:FooStack)
18
18
  Pancake::Stack.on_inherit.clear
19
19
  end
20
-
20
+
21
21
  after(:each) do
22
22
  clear_constants(:FooStack)
23
23
  end
24
-
24
+
25
25
  it "should be able to add inheritance hooks" do
26
26
  Pancake::Stack.on_inherit do |base, parent|
27
27
  $collector << base
@@ -29,32 +29,32 @@ describe "Pancake::Stack inheritance" do
29
29
  class ::FooStack < Pancake::Stack; end
30
30
  $collector.should == [FooStack]
31
31
  end
32
-
32
+
33
33
  it "should be able to add multiple inheritance hooks" do
34
34
  Pancake::Stack.on_inherit{|b,p| $collector << b}
35
35
  Pancake::Stack.on_inherit{|b,p| $collector << :foo}
36
-
36
+
37
37
  class ::FooStack < Pancake::Stack
38
38
  end
39
-
39
+
40
40
  $collector.should == [FooStack, :foo]
41
41
  end
42
-
42
+
43
43
  end
44
-
44
+
45
45
  describe "Inheriting Stacks" do
46
- before(:all) do
46
+ before(:all) do
47
47
  clear_constants(:FooStack, :BarStack)
48
48
  end
49
-
49
+
50
50
  before(:each) do
51
51
  class ::FooStack < Pancake::Stack; end
52
52
  end
53
-
53
+
54
54
  after(:each) do
55
55
  clear_constants(:FooStack, :BarStack)
56
56
  end
57
-
57
+
58
58
  describe "configuration" do
59
59
  it "should inherit the configuration with a stack" do
60
60
  class ::BarStack < ::FooStack; end
@@ -1,47 +1,47 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Pancake Inheritance" do
4
4
  describe "on inherit hook" do
5
-
5
+
6
6
  before(:each) do
7
7
  clear_constants(:MyFoo, :OtherFoo, :FutherFoo, :SomeFoo, :DeeperFoo)
8
- class ::MyFoo
8
+ class ::MyFoo
9
9
  extend Pancake::Hooks::OnInherit
10
10
  end
11
-
11
+
12
12
  ::MyFoo.on_inherit do |base, parent|
13
13
  $inherited_capture << {:base => base, :parent => parent}
14
14
  end
15
-
15
+
16
16
  $inherited_capture = []
17
17
  end
18
-
18
+
19
19
  it "should provide on_inherit callbacks" do
20
20
  class ::OtherFoo < MyFoo; end
21
21
  $inherited_capture.should == [{:base => OtherFoo, :parent => MyFoo}]
22
22
  end
23
-
23
+
24
24
  it "should inherit multiple times" do
25
25
  class ::OtherFoo < MyFoo; end
26
26
  class ::FurtherFoo < OtherFoo; end
27
27
  $inherited_capture.should == [{:base => OtherFoo, :parent => MyFoo}, {:base => FurtherFoo, :parent => OtherFoo}]
28
28
  end
29
-
29
+
30
30
  it "should allow for multiple callbacks" do
31
31
  MyFoo.on_inherit{|base, parent| $inherited_capture << :second}
32
32
  class ::OtherFoo < MyFoo; end
33
33
  $inherited_capture.should == [{:base => OtherFoo, :parent => MyFoo}, :second]
34
34
  end
35
-
35
+
36
36
  it "should allow for multiple callbacks that are inherited" do
37
37
  MyFoo.on_inherit{|base, parent| $inherited_capture << :second}
38
38
  class ::OtherFoo < MyFoo; end
39
39
  $inherited_capture = []
40
40
  OtherFoo.on_inherit{|base, parent| $inherited_capture << :inherited}
41
41
  class ::SomeFoo < OtherFoo; end
42
- $inherited_capture.should == [{:base => SomeFoo, :parent => OtherFoo}, :second, :inherited]
42
+ $inherited_capture.should == [{:base => SomeFoo, :parent => OtherFoo}, :second, :inherited]
43
43
  end
44
-
44
+
45
45
  it "should not pollute the parent with the child inherited hooks" do
46
46
  class ::OtherFoo < MyFoo; end
47
47
  $inherited_capture = []
@@ -50,51 +50,51 @@ describe "Pancake Inheritance" do
50
50
  $inherited_capture.should == [{:base => SomeFoo, :parent => MyFoo}]
51
51
  end
52
52
  end # "on inherit hook"
53
-
53
+
54
54
  describe "inheritable inner classes" do
55
-
55
+
56
56
  before(:each) do
57
57
  clear_constants(:MyFoo, :OtherFoo, :InnerFoo, :SomeFoo, :DeeperFoo)
58
-
58
+
59
59
  class ::MyFoo
60
60
  inheritable_inner_classes :InnerFoo
61
61
  class InnerFoo; end
62
62
  end
63
63
  end
64
-
64
+
65
65
  it "should inherit the inner class along with the outer class" do
66
66
  class ::OtherFoo < MyFoo; end
67
67
  OtherFoo::InnerFoo.superclass.should equal(MyFoo::InnerFoo)
68
68
  OtherFoo::InnerFoo.should_not equal(MyFoo::InnerFoo)
69
69
  end
70
-
70
+
71
71
  it "should inherit the inner class multiple times" do
72
72
  class ::OtherFoo < MyFoo; end
73
73
  class ::SomeFoo < OtherFoo; end
74
74
  class ::DeeperFoo < SomeFoo; end
75
-
75
+
76
76
  SomeFoo::InnerFoo.superclass.should equal(OtherFoo::InnerFoo)
77
77
  SomeFoo::InnerFoo.should_not equal(OtherFoo::InnerFoo)
78
78
  DeeperFoo::InnerFoo.superclass.should equal(SomeFoo::InnerFoo)
79
79
  DeeperFoo::InnerFoo.should_not equal(OtherFoo::InnerFoo)
80
80
  DeeperFoo::InnerFoo.superclass.should equal(SomeFoo::InnerFoo)
81
81
  end
82
-
82
+
83
83
  it "should allow additional inner classes to be declared without polluting the parent" do
84
84
  class ::OtherFoo < MyFoo
85
85
  inheritable_inner_classes :SomeDeepFoo
86
86
  class SomeDeepFoo; end
87
87
  end
88
-
88
+
89
89
  class ::SomeFoo < MyFoo; end
90
90
  class ::DeeperFoo < ::OtherFoo; end
91
-
91
+
92
92
  SomeFoo::InnerFoo.should inherit_from(MyFoo::InnerFoo)
93
93
  SomeFoo.const_defined?(:SomeDeepFoo).should be_false
94
-
94
+
95
95
  DeeperFoo::InnerFoo.should inherit_from(OtherFoo::InnerFoo)
96
96
  DeeperFoo::SomeDeepFoo.should inherit_from(OtherFoo::SomeDeepFoo)
97
97
  end
98
98
 
99
99
  end # "inheritable inner classes"
100
- end
100
+ end