ramaze 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/Rakefile +26 -6
  2. data/bin/ramaze +8 -1
  3. data/doc/AUTHORS +13 -11
  4. data/doc/CHANGELOG +472 -13
  5. data/doc/LEGAL +22 -0
  6. data/doc/README +1 -4
  7. data/doc/TODO +7 -2
  8. data/doc/changes.txt +472 -13
  9. data/doc/changes.xml +472 -13
  10. data/doc/meta/announcement.txt +21 -23
  11. data/doc/readme_chunks/appendix.txt +0 -3
  12. data/doc/readme_chunks/features.txt +1 -1
  13. data/examples/auth/auth.rb +49 -0
  14. data/examples/auth/template/layout.haml +20 -0
  15. data/examples/auth/template/login.haml +16 -0
  16. data/examples/blog/spec/blog.rb +1 -0
  17. data/examples/caching.rb +5 -6
  18. data/examples/css.rb +37 -0
  19. data/examples/layout.rb +3 -17
  20. data/examples/simple_auth.rb +23 -0
  21. data/examples/sourceview/public/images/file.gif +0 -0
  22. data/examples/sourceview/public/images/folder.gif +0 -0
  23. data/examples/sourceview/public/images/tv-collapsable-last.gif +0 -0
  24. data/examples/sourceview/public/images/tv-collapsable.gif +0 -0
  25. data/examples/sourceview/public/images/tv-expandable-last.gif +0 -0
  26. data/examples/sourceview/public/images/tv-expandable.gif +0 -0
  27. data/examples/sourceview/public/images/tv-item-last.gif +0 -0
  28. data/examples/sourceview/public/images/tv-item.gif +0 -0
  29. data/examples/sourceview/public/jquery.js +11 -0
  30. data/examples/sourceview/public/jquery.treeview.css +47 -0
  31. data/examples/sourceview/public/jquery.treeview.js +223 -0
  32. data/examples/sourceview/public/sourceview.js +16 -0
  33. data/examples/sourceview/sourceview.rb +74 -0
  34. data/examples/sourceview/template/index.haml +43 -0
  35. data/examples/templates/template/external.nag +28 -0
  36. data/examples/templates/template/external.xsl +57 -0
  37. data/examples/templates/template_amrita2.rb +2 -4
  38. data/examples/templates/template_erubis.rb +1 -1
  39. data/examples/templates/template_haml.rb +1 -1
  40. data/examples/templates/template_liquid.rb +2 -4
  41. data/examples/templates/template_markaby.rb +2 -4
  42. data/examples/templates/template_nagoro.rb +53 -0
  43. data/examples/templates/template_remarkably.rb +2 -4
  44. data/examples/templates/template_xslt.rb +52 -0
  45. data/examples/whywiki/spec/whywiki.rb +63 -0
  46. data/examples/whywiki/start.rb +11 -13
  47. data/examples/whywiki/template/edit.xhtml +3 -3
  48. data/examples/whywiki/template/show.xhtml +5 -8
  49. data/examples/wikore/spec/wikore.rb +115 -0
  50. data/examples/wikore/src/controller.rb +81 -0
  51. data/examples/wikore/src/model.rb +51 -0
  52. data/examples/wikore/start.rb +6 -0
  53. data/examples/wikore/template/index.xhtml +8 -0
  54. data/examples/wiktacular/spec/wiktacular.rb +1 -0
  55. data/examples/wiktacular/src/controller.rb +1 -1
  56. data/lib/ramaze.rb +6 -3
  57. data/lib/ramaze/action.rb +2 -13
  58. data/lib/ramaze/action/render.rb +36 -18
  59. data/lib/ramaze/adapter.rb +1 -1
  60. data/lib/ramaze/adapter/cgi.rb +0 -3
  61. data/lib/ramaze/adapter/evented_mongrel.rb +7 -0
  62. data/lib/ramaze/adapter/mongrel.rb +4 -13
  63. data/lib/ramaze/adapter/swiftiplied_mongrel.rb +7 -0
  64. data/lib/ramaze/cache.rb +12 -7
  65. data/lib/ramaze/contrib.rb +22 -0
  66. data/lib/ramaze/contrib/auto_params.rb +128 -0
  67. data/lib/ramaze/contrib/auto_params/get_args.rb +56 -0
  68. data/lib/ramaze/contrib/gzip_filter.rb +57 -0
  69. data/lib/ramaze/contrib/route.rb +40 -0
  70. data/lib/ramaze/contrib/sequel/fill.rb +12 -0
  71. data/lib/ramaze/controller.rb +17 -6
  72. data/lib/ramaze/controller/resolve.rb +51 -14
  73. data/lib/ramaze/dispatcher.rb +15 -13
  74. data/lib/ramaze/dispatcher/action.rb +4 -3
  75. data/lib/ramaze/dispatcher/directory.rb +3 -3
  76. data/lib/ramaze/dispatcher/error.rb +1 -1
  77. data/lib/ramaze/dispatcher/file.rb +17 -6
  78. data/lib/ramaze/error.rb +3 -0
  79. data/lib/ramaze/gestalt.rb +28 -8
  80. data/lib/ramaze/global.rb +26 -6
  81. data/lib/ramaze/global/globalstruct.rb +31 -6
  82. data/lib/ramaze/helper.rb +2 -1
  83. data/lib/ramaze/helper/aspect.rb +2 -2
  84. data/lib/ramaze/helper/auth.rb +6 -9
  85. data/lib/ramaze/helper/cache.rb +89 -9
  86. data/lib/ramaze/helper/cgi.rb +2 -2
  87. data/lib/ramaze/helper/formatting.rb +44 -0
  88. data/lib/ramaze/helper/link.rb +7 -5
  89. data/lib/ramaze/helper/partial.rb +6 -4
  90. data/lib/ramaze/helper/redirect.rb +24 -9
  91. data/lib/ramaze/helper/stack.rb +6 -1
  92. data/lib/ramaze/inform/growl.rb +1 -1
  93. data/lib/ramaze/inform/informer.rb +2 -1
  94. data/lib/ramaze/inform/informing.rb +6 -0
  95. data/lib/ramaze/inform/syslog.rb +1 -0
  96. data/lib/ramaze/snippets/array/put_within.rb +24 -0
  97. data/lib/ramaze/snippets/dictionary.rb +499 -0
  98. data/lib/ramaze/snippets/numeric/filesize_format.rb +19 -0
  99. data/lib/ramaze/snippets/ordered_set.rb +31 -0
  100. data/lib/ramaze/snippets/string/DIVIDE.rb +1 -1
  101. data/lib/ramaze/snippets/string/snake_case.rb +1 -1
  102. data/lib/ramaze/snippets/struct/values_at.rb +5 -1
  103. data/lib/ramaze/snippets/thread/into.rb +25 -0
  104. data/lib/ramaze/sourcereload.rb +39 -19
  105. data/lib/ramaze/spec/helper.rb +4 -1
  106. data/lib/ramaze/spec/helper/{context.rb → browser.rb} +3 -0
  107. data/lib/ramaze/spec/helper/layout.rb +3 -0
  108. data/lib/ramaze/spec/helper/minimal.rb +3 -0
  109. data/lib/ramaze/spec/helper/mock_http.rb +8 -5
  110. data/lib/ramaze/spec/helper/requester.rb +4 -1
  111. data/lib/ramaze/spec/helper/wrap.rb +15 -7
  112. data/lib/ramaze/template.rb +5 -1
  113. data/lib/ramaze/template/ezamar/engine.rb +2 -3
  114. data/lib/ramaze/template/ezamar/morpher.rb +26 -45
  115. data/lib/ramaze/template/nagoro.rb +53 -0
  116. data/lib/ramaze/template/none.rb +14 -0
  117. data/lib/ramaze/template/xslt.rb +96 -0
  118. data/lib/ramaze/tool.rb +0 -1
  119. data/lib/ramaze/tool/localize.rb +7 -2
  120. data/lib/ramaze/trinity/request.rb +1 -0
  121. data/lib/ramaze/trinity/session.rb +3 -3
  122. data/lib/ramaze/version.rb +2 -2
  123. data/rake_tasks/conf.rake +1 -2
  124. data/rake_tasks/{maintaince.rake → maintenance.rake} +25 -17
  125. data/spec/contrib/auto_params.rb +97 -0
  126. data/spec/contrib/route.rb +60 -0
  127. data/spec/contrib/sequel/fill.rb +46 -0
  128. data/spec/examples/caching.rb +1 -2
  129. data/spec/examples/css.rb +12 -0
  130. data/spec/examples/element.rb +0 -1
  131. data/spec/examples/hello.rb +0 -1
  132. data/spec/examples/simple.rb +0 -1
  133. data/spec/helper.rb +3 -2
  134. data/spec/ramaze/action/cache.rb +24 -7
  135. data/spec/ramaze/action/layout.rb +19 -11
  136. data/spec/ramaze/action/template/sub/sub_wrapper.xhtml +1 -0
  137. data/spec/ramaze/controller.rb +11 -0
  138. data/spec/ramaze/controller/template_resolving.rb +28 -27
  139. data/spec/ramaze/dispatcher.rb +32 -0
  140. data/spec/ramaze/dispatcher/directory.rb +2 -1
  141. data/spec/ramaze/element.rb +1 -1
  142. data/spec/ramaze/gestalt.rb +28 -0
  143. data/spec/ramaze/helper/aspect.rb +14 -3
  144. data/spec/ramaze/helper/cache.rb +78 -13
  145. data/spec/ramaze/helper/formatting.rb +20 -0
  146. data/spec/ramaze/helper/link.rb +2 -0
  147. data/spec/ramaze/helper/partial.rb +12 -1
  148. data/spec/ramaze/helper/redirect.rb +44 -8
  149. data/spec/ramaze/helper/stack.rb +3 -3
  150. data/spec/ramaze/helper/template/loop.xhtml +3 -0
  151. data/spec/ramaze/helper/template/num.xhtml +1 -0
  152. data/spec/ramaze/helper/template/recursive.xhtml +8 -0
  153. data/spec/ramaze/morpher.rb +25 -6
  154. data/spec/ramaze/params.rb +6 -2
  155. data/spec/ramaze/request.rb +5 -2
  156. data/spec/ramaze/session.rb +19 -0
  157. data/spec/ramaze/template.rb +2 -2
  158. data/spec/ramaze/template/amrita2.rb +2 -2
  159. data/spec/ramaze/template/erubis.rb +2 -2
  160. data/spec/ramaze/template/ezamar.rb +6 -3
  161. data/spec/ramaze/template/haml.rb +3 -3
  162. data/spec/ramaze/template/liquid.rb +1 -1
  163. data/spec/ramaze/template/markaby.rb +1 -1
  164. data/spec/ramaze/template/nagoro.rb +65 -0
  165. data/spec/ramaze/template/nagoro/another/long/action.nag +1 -0
  166. data/spec/ramaze/template/nagoro/combined.nag +1 -0
  167. data/spec/ramaze/template/nagoro/file_only.nag +1 -0
  168. data/spec/ramaze/template/nagoro/index.nag +1 -0
  169. data/spec/ramaze/template/nagoro/nested.nag +1 -0
  170. data/spec/ramaze/template/nagoro/some__long__action.nag +1 -0
  171. data/spec/ramaze/template/nagoro/sum.nag +1 -0
  172. data/spec/ramaze/template/remarkably.rb +1 -1
  173. data/spec/ramaze/template/sass.rb +1 -1
  174. data/spec/ramaze/template/xslt.rb +93 -0
  175. data/spec/ramaze/template/xslt/concat_words.xsl +16 -0
  176. data/spec/ramaze/template/xslt/index.xsl +14 -0
  177. data/spec/ramaze/template/xslt/products.xsl +32 -0
  178. data/spec/ramaze/template/xslt/ruby_version.xsl +14 -0
  179. data/spec/snippets/array/put_within.rb +32 -0
  180. data/spec/snippets/numeric/filesize_format.rb +12 -0
  181. data/spec/snippets/ordered_set.rb +56 -0
  182. data/spec/snippets/ramaze/caller_lines.rb +6 -3
  183. data/spec/snippets/string/snake_case.rb +3 -0
  184. metadata +118 -22
  185. data/doc/README.html +0 -737
  186. data/examples/fcgi.rb +0 -13
  187. data/lib/ramaze/snippets/numeric/human_readable_filesize_format.rb +0 -33
  188. data/lib/ramaze/tool/tidy.rb +0 -104
  189. data/spec/ramaze/controller/template/edit.xhtml +0 -1
  190. data/spec/ramaze/controller/template/edit/content.xhtml +0 -1
  191. data/spec/ramaze/tidy.rb +0 -12
  192. data/spec/snippets/numeric/human_readable_filesize_format.rb +0 -11
@@ -20,8 +20,8 @@ end
20
20
 
21
21
  class TCTemplateController < Ramaze::Controller
22
22
  map '/'
23
- trait :engine => Ramaze::Template::TestTemplate
24
- template_root(__DIR__/:template/:ramaze)
23
+ engine :TestTemplate
24
+ template_root __DIR__/:template/:ramaze
25
25
 
26
26
  def index *args
27
27
  end
@@ -6,8 +6,8 @@ require 'spec/helper'
6
6
  testcase_requires 'amrita2'
7
7
 
8
8
  class TCTemplateAmritaController < Ramaze::Controller
9
- template_root 'spec/ramaze/template/amrita2/'
10
- trait :engine => Ramaze::Template::Amrita2
9
+ template_root __DIR__/:amrita2
10
+ engine :Amrita2
11
11
 
12
12
  def title
13
13
  "hello world"
@@ -6,8 +6,8 @@ require 'spec/helper'
6
6
  testcase_requires 'erubis'
7
7
 
8
8
  class TCTemplateErubisController < Ramaze::Controller
9
- template_root 'spec/ramaze/template/erubis/'
10
- trait :engine => Ramaze::Template::Erubis
9
+ template_root __DIR__/:erubis
10
+ engine :Erubis
11
11
 
12
12
  def index
13
13
  'Erubis Index'
@@ -4,8 +4,9 @@
4
4
  require 'spec/helper'
5
5
 
6
6
  class TCTemplateController < Ramaze::Controller
7
- template_root 'spec/ramaze/template/ezamar'
8
- trait :engine => Ramaze::Template::Ezamar
7
+ map :/
8
+ template_root __DIR__/:ezamar
9
+ engine :Ezamar
9
10
 
10
11
  def index text
11
12
  @text = text
@@ -31,7 +32,9 @@ end
31
32
 
32
33
 
33
34
  describe "Ezamar" do
34
- ramaze(:mapping => {'/' => TCTemplateController})
35
+ before(:all) do
36
+ ramaze
37
+ end
35
38
 
36
39
  it "hello world" do
37
40
  get('/World').body.should == 'Hello, World!'
@@ -6,9 +6,9 @@ require 'spec/helper'
6
6
  testcase_requires 'ramaze/template/haml'
7
7
 
8
8
  class TCTemplateHamlController < Ramaze::Controller
9
- map '/'
10
- template_root 'spec/ramaze/template/haml/'
11
- trait :engine => Ramaze::Template::Haml
9
+ map :/
10
+ template_root __DIR__/:haml
11
+ engine :Haml
12
12
 
13
13
  helper :link
14
14
 
@@ -26,7 +26,7 @@ end
26
26
 
27
27
  class TCTemplateLiquidController < Ramaze::Controller
28
28
  template_root 'spec/ramaze/template/liquid/'
29
- trait :engine => Ramaze::Template::Liquid
29
+ engine :Liquid
30
30
  trait :liquid_options => { :filters => ProductsFilter }
31
31
 
32
32
  def index
@@ -7,7 +7,7 @@ testcase_requires 'markaby'
7
7
 
8
8
  class TCTemplateMarkabyController < Ramaze::Controller
9
9
  template_root 'spec/ramaze/template/markaby/'
10
- trait :engine => Ramaze::Template::Markaby
10
+ engine :Markaby
11
11
 
12
12
  helper :markaby
13
13
 
@@ -0,0 +1,65 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ require 'spec/helper'
5
+ testcase_requires 'nagoro'
6
+
7
+ class TCTemplateNagoroController < Ramaze::Controller
8
+ map :/
9
+ template_root __DIR__/:nagoro
10
+ engine :Nagoro
11
+
12
+ def index text
13
+ @text = text
14
+ end
15
+
16
+ def sum num1, num2
17
+ @num1, @num2 = num1.to_i, num2.to_i
18
+ end
19
+
20
+ def nested key, value
21
+ instance_variable_set("@#{key}", value)
22
+ end
23
+
24
+ def internal *args
25
+ @args = args
26
+ '<?r i = 2 ?>#{i * i} #{@args.inspect} on the table'
27
+ end
28
+
29
+ def combined
30
+ @a = 'boo'
31
+ end
32
+ end
33
+
34
+
35
+ describe "Nagoro" do
36
+ before(:all) do
37
+ ramaze
38
+ end
39
+
40
+ it "hello world" do
41
+ get('/World').body.should == 'Hello, World!'
42
+ get('/You').body.should == 'Hello, You!'
43
+ end
44
+
45
+ it "summing" do
46
+ get('/sum/1/2').body.should == '3'
47
+ end
48
+
49
+ it "nasty nested stuff" do
50
+ get('/nested/foo/bar').body.should == 'bar'
51
+ end
52
+
53
+ it "template inside controller" do
54
+ get('/internal').body.should == '4 [] on the table'
55
+ get('/internal/foo').body.should == '4 ["foo"] on the table'
56
+ end
57
+
58
+ it "without method" do
59
+ get('/file_only').body.should == "This is only the file"
60
+ end
61
+
62
+ it "combined" do
63
+ get('/combined').body.should == 'boo'
64
+ end
65
+ end
@@ -0,0 +1 @@
1
+ another long action
@@ -0,0 +1 @@
1
+ This is only the file
@@ -0,0 +1 @@
1
+ Hello, #{@text}!
@@ -0,0 +1 @@
1
+ some long action
@@ -0,0 +1 @@
1
+ #{@num1 + @num2}
@@ -6,7 +6,7 @@ testcase_requires 'remarkably/engines/html'
6
6
 
7
7
  class TCTemplateRemarkablyController < Ramaze::Controller
8
8
  template_root 'spec/ramaze/template/remarkably/'
9
- trait :engine => Ramaze::Template::Remarkably
9
+ engine :Remarkably
10
10
 
11
11
  include Remarkably::Common
12
12
 
@@ -8,7 +8,7 @@ testcase_requires 'sass/engine'
8
8
  class TCTemplateSassController < Ramaze::Controller
9
9
  map '/'
10
10
  template_root 'spec/ramaze/template/sass/'
11
- trait :engine => Ramaze::Template::Sass
11
+ engine :Sass
12
12
 
13
13
  define_method('style.css') do
14
14
  %{
@@ -0,0 +1,93 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ require 'spec/helper'
5
+
6
+ testcase_requires 'xml/libxml'
7
+ testcase_requires 'xml/xslt'
8
+ testcase_requires 'ramaze/gestalt'
9
+ testcase_requires 'rexml/document'
10
+
11
+ class TCTemplateXSLTController < Ramaze::Controller
12
+ template_root 'spec/ramaze/template/xslt/'
13
+ engine :XSLT
14
+ trait :xslt_options => { :fun_xmlns => 'urn:test' }
15
+
16
+ def index
17
+ gestalt {
18
+ hi 'tobi'
19
+ }
20
+ end
21
+
22
+ def ruby_version
23
+ @version = RUBY_VERSION
24
+
25
+ gestalt {
26
+ document
27
+ }
28
+ end
29
+
30
+ def xslt_get_ruby_version
31
+ @version
32
+ end
33
+
34
+ def products
35
+ gestalt {
36
+ order {
37
+ first
38
+ items
39
+ }
40
+ }
41
+ end
42
+
43
+ def xslt_get_products
44
+ REXML::Document.new \
45
+ gestalt {
46
+ list {
47
+ %w[Onion Bacon].each { |product|
48
+ item product
49
+ }
50
+ }
51
+ }
52
+ end
53
+
54
+ def concat_words
55
+ gestalt {
56
+ document
57
+ }
58
+ end
59
+
60
+ def xslt_concat(*args)
61
+ args.to_s
62
+ end
63
+
64
+ private
65
+
66
+ def gestalt &block
67
+ Ramaze::Gestalt.new(&block).to_s
68
+ end
69
+
70
+ end
71
+
72
+ describe "XSLT" do
73
+ ramaze(:mapping => {'/' => TCTemplateXSLTController})
74
+
75
+ it "index" do
76
+ get('/').body.should == "hi tobi"
77
+ end
78
+
79
+ it "ruby_version through external functions" do
80
+ get('/ruby_version').body.should == RUBY_VERSION
81
+ end
82
+
83
+ it "external functions returning XML data" do
84
+ get('/products').body.
85
+ gsub(/<\?.+\?>/, '').strip.
86
+ should == '<result><first>Onion</first><item>Onion</item><item>Bacon</item></result>'
87
+ end
88
+
89
+ it "parameters" do
90
+ get('/concat_words').body.should == 'oneonetwoonetwothree'
91
+ end
92
+ end
93
+
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <xsl:stylesheet version="1.0"
3
+ xmlns:test="urn:test"
4
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5
+ exclude-result-prefixes="test xsl">
6
+
7
+ <xsl:output method="text"
8
+ encoding="utf-8"/>
9
+
10
+ <xsl:template match="/document">
11
+ <xsl:value-of select="test:concat('one')"/>
12
+ <xsl:value-of select="test:concat('one', 'two')"/>
13
+ <xsl:value-of select="test:concat('one', 'two', 'three')"/>
14
+ </xsl:template>
15
+
16
+ </xsl:stylesheet>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <xsl:stylesheet version="1.0"
3
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4
+
5
+ <xsl:output method="text"
6
+ encoding="utf-8"/>
7
+
8
+ <xsl:template match="/*">
9
+ <xsl:value-of select="name(.)"/>
10
+ <xsl:text> </xsl:text>
11
+ <xsl:apply-templates/>
12
+ </xsl:template>
13
+
14
+ </xsl:stylesheet>
@@ -0,0 +1,32 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <xsl:stylesheet version="1.0"
3
+ xmlns:test="urn:test"
4
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5
+ exclude-result-prefixes="test xsl">
6
+
7
+ <xsl:output method="xml"
8
+ encoding="utf-8"/>
9
+
10
+ <xsl:template match="order">
11
+ <result>
12
+ <xsl:apply-templates/>
13
+ </result>
14
+ </xsl:template>
15
+
16
+ <xsl:template match="first">
17
+ <first>
18
+ <xsl:value-of select="test:get-products()/item[1]"/>
19
+ </first>
20
+ </xsl:template>
21
+
22
+ <xsl:template match="items">
23
+ <xsl:apply-templates select="test:get-products()" mode="list"/>
24
+ </xsl:template>
25
+
26
+ <xsl:template match="item" mode="list">
27
+ <item>
28
+ <xsl:apply-templates mode="list"/>
29
+ </item>
30
+ </xsl:template>
31
+
32
+ </xsl:stylesheet>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <xsl:stylesheet version="1.0"
3
+ xmlns:test="urn:test"
4
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5
+ exclude-result-prefixes="test xsl">
6
+
7
+ <xsl:output method="text"
8
+ encoding="utf-8"/>
9
+
10
+ <xsl:template match="/document">
11
+ <ruby-version><xsl:value-of select="test:get-ruby-version()"/></ruby-version>
12
+ </xsl:template>
13
+
14
+ </xsl:stylesheet>
@@ -0,0 +1,32 @@
1
+ require 'spec/helper'
2
+
3
+ describe 'Array#put_within' do
4
+ it 'should put a given object at a well-described position' do
5
+ array = [:foo, :bar, :baz]
6
+ array.put_within(:foobar, :after => :bar, :before => :baz)
7
+ array.should == [:foo, :bar, :foobar, :baz]
8
+ end
9
+
10
+ it 'should raise on uncertainity' do
11
+ array = [:foo, :bar, :baz]
12
+ lambda{
13
+ array.put_within(:foobar, :after => :foo, :before => :baz)
14
+ }.should raise_error(ArgumentError, "Too many elements within constrain")
15
+ end
16
+ end
17
+
18
+ describe 'Array#put_after' do
19
+ it 'should put a given object at a well-described position' do
20
+ array = [:foo, :bar, :baz]
21
+ array.put_after(:bar, :foobar)
22
+ array.should == [:foo, :bar, :foobar, :baz]
23
+ end
24
+ end
25
+
26
+ describe 'Array#put_within' do
27
+ it 'should put a given object at a well-described position' do
28
+ array = [:foo, :bar, :baz]
29
+ array.put_before(:bar, :foobar)
30
+ array.should == [:foo, :foobar, :bar, :baz]
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec/helper'
2
+
3
+ describe "Numeric#filesize_format" do
4
+ it 'it should convert filesizes to human readable format' do
5
+ 1.filesize_format.should == '1'
6
+ 1024.filesize_format.should == '1.0K'
7
+ (1 << 20).filesize_format.should == '1.0M'
8
+ (1 << 20).filesize_format.should == '1.0M'
9
+ (1 << 30).filesize_format.should == '1.0G'
10
+ (1 << 40).filesize_format.should == '1.0T'
11
+ end
12
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec/helper'
2
+
3
+ describe 'OrderedSet' do
4
+ os = OrderedSet.new(1,2,3,1)
5
+
6
+ it 'should create sets' do
7
+ OrderedSet.new.should == []
8
+ os.should == OrderedSet.new([1,2,3,1])
9
+ end
10
+
11
+ it 'should not contain duplicates' do
12
+ os.should == [1,2,3]
13
+ end
14
+
15
+ it 'should not duplicate entries' do
16
+ os << 4
17
+ os.should == [1,2,3,4]
18
+
19
+ os << 4
20
+ os.should == [1,2,3,4]
21
+ end
22
+
23
+ it 'should append with push and prepend with unshift' do
24
+ os.push 1
25
+ os.should == [2,3,4,1]
26
+
27
+ os.unshift 1
28
+ os.should == [1,2,3,4]
29
+
30
+ os.push [1,2]
31
+ os.should == [1,2,3,4,[1,2]]
32
+
33
+ os.unshift [1,2]
34
+ os.should == [[1,2],1,2,3,4]
35
+ end
36
+
37
+ it 'should support Array#[]=' do
38
+ os = OrderedSet.new(1)
39
+ os.should == [1]
40
+
41
+ os[0] = 1
42
+ os.should == [1]
43
+
44
+ os[1,0] = [3,4,5,1]
45
+ os.should == [3,4,5,1]
46
+
47
+ os[0,0] = [1,2]
48
+ os.should == [1,2,3,4,5]
49
+
50
+ os[5..5] = [7,8,1,2]
51
+ os.should == [3,4,5,7,8,1,2]
52
+
53
+ os[1..2] = 3
54
+ os.should == [3,7,8,1,2]
55
+ end
56
+ end