ramaze 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/Rakefile +52 -19
  2. data/bin/ramaze +19 -6
  3. data/doc/CHANGELOG +33 -0
  4. data/doc/COPYING +1 -1
  5. data/doc/FAQ +92 -0
  6. data/doc/GPL +340 -0
  7. data/doc/INSTALL +34 -0
  8. data/doc/ProjectInfo +53 -0
  9. data/doc/README +187 -110
  10. data/doc/readme_chunks/appendix.txt +13 -0
  11. data/doc/readme_chunks/examples.txt +38 -0
  12. data/doc/readme_chunks/features.txt +82 -0
  13. data/doc/readme_chunks/getting_help.txt +5 -0
  14. data/doc/readme_chunks/getting_started.txt +18 -0
  15. data/doc/readme_chunks/installing.txt +41 -0
  16. data/doc/readme_chunks/introduction.txt +18 -0
  17. data/doc/readme_chunks/principles.txt +41 -0
  18. data/doc/readme_chunks/thanks.txt +59 -0
  19. data/doc/tutorial/todolist.txt +546 -0
  20. data/examples/blog/main.rb +1 -1
  21. data/examples/blog/src/controller.rb +13 -11
  22. data/examples/blog/src/element.rb +11 -6
  23. data/examples/blog/src/model.rb +8 -23
  24. data/examples/blog/template/edit.xhtml +3 -1
  25. data/examples/blog/template/index.xhtml +4 -4
  26. data/examples/caching.rb +4 -4
  27. data/examples/element.rb +10 -7
  28. data/examples/hello.rb +3 -4
  29. data/examples/simple.rb +5 -3
  30. data/examples/templates/template/external.amrita +19 -0
  31. data/examples/templates/template/{external.rmze → external.zmr} +2 -2
  32. data/examples/templates/template_amrita2.rb +48 -0
  33. data/examples/templates/template_erubis.rb +5 -2
  34. data/examples/templates/{template_ramaze.rb → template_ezamar.rb} +13 -7
  35. data/examples/templates/template_haml.rb +4 -1
  36. data/examples/templates/template_liquid.rb +2 -1
  37. data/examples/templates/template_markaby.rb +2 -1
  38. data/examples/todolist/conf/benchmark.yaml +35 -0
  39. data/examples/todolist/conf/debug.yaml +34 -0
  40. data/examples/todolist/conf/live.yaml +33 -0
  41. data/examples/todolist/conf/silent.yaml +31 -0
  42. data/examples/todolist/conf/stage.yaml +33 -0
  43. data/examples/todolist/main.rb +18 -0
  44. data/examples/todolist/public/404.jpg +0 -0
  45. data/examples/todolist/public/css/coderay.css +105 -0
  46. data/examples/todolist/public/css/ramaze_error.css +42 -0
  47. data/{lib/proto → examples/todolist}/public/error.xhtml +0 -0
  48. data/examples/todolist/public/favicon.ico +0 -0
  49. data/examples/todolist/public/js/jquery.js +1923 -0
  50. data/examples/todolist/public/ramaze.png +0 -0
  51. data/examples/todolist/src/controller/main.rb +56 -0
  52. data/examples/todolist/src/element/page.rb +26 -0
  53. data/examples/todolist/src/model.rb +14 -0
  54. data/examples/todolist/template/index.xhtml +17 -0
  55. data/examples/todolist/template/new.xhtml +7 -0
  56. data/examples/todolist/todolist.db +9 -0
  57. data/examples/whywiki/main.rb +3 -8
  58. data/examples/whywiki/template/show.xhtml +4 -0
  59. data/lib/proto/public/error.zmr +77 -0
  60. data/lib/proto/src/controller/main.rb +2 -1
  61. data/lib/proto/src/element/page.rb +2 -1
  62. data/lib/proto/src/model.rb +3 -2
  63. data/lib/ramaze.rb +7 -9
  64. data/lib/ramaze/adapter.rb +51 -0
  65. data/lib/ramaze/adapter/cgi.rb +23 -0
  66. data/lib/ramaze/adapter/fcgi.rb +22 -0
  67. data/lib/ramaze/adapter/mongrel.rb +7 -86
  68. data/lib/ramaze/adapter/webrick.rb +14 -133
  69. data/lib/ramaze/cache/memcached.rb +6 -0
  70. data/lib/ramaze/cache/yaml_store.rb +3 -1
  71. data/lib/ramaze/controller.rb +292 -2
  72. data/lib/ramaze/dispatcher.rb +85 -213
  73. data/lib/ramaze/error.rb +10 -0
  74. data/lib/ramaze/global.rb +8 -0
  75. data/lib/ramaze/helper/aspect.rb +30 -7
  76. data/lib/ramaze/helper/auth.rb +16 -9
  77. data/lib/ramaze/helper/cache.rb +40 -35
  78. data/lib/ramaze/helper/feed.rb +1 -1
  79. data/lib/ramaze/helper/flash.rb +34 -0
  80. data/lib/ramaze/helper/link.rb +8 -2
  81. data/lib/ramaze/helper/openid.rb +63 -0
  82. data/lib/ramaze/helper/redirect.rb +12 -11
  83. data/lib/ramaze/helper/stack.rb +5 -7
  84. data/lib/ramaze/inform.rb +12 -1
  85. data/lib/ramaze/snippets/kernel/aquire.rb +1 -1
  86. data/lib/ramaze/snippets/kernel/{self_method.rb → method.rb} +3 -18
  87. data/lib/ramaze/snippets/kernel/{rescue_require.rb → pretty_inspect.rb} +7 -6
  88. data/lib/ramaze/snippets/method/name.rb +22 -0
  89. data/lib/ramaze/snippets/{kernel → ramaze}/autoreload.rb +0 -0
  90. data/lib/ramaze/snippets/ramaze/caller_info.rb +14 -0
  91. data/lib/ramaze/snippets/{kernel → ramaze}/caller_lines.rb +3 -10
  92. data/lib/ramaze/snippets/rdoc/usage_no_exit.rb +49 -23
  93. data/lib/ramaze/snippets/string/DIVIDE.rb +0 -1
  94. data/lib/ramaze/store/default.rb +58 -2
  95. data/lib/ramaze/store/yaml.rb +161 -0
  96. data/lib/ramaze/template.rb +27 -86
  97. data/lib/ramaze/template/amrita2.rb +14 -19
  98. data/lib/ramaze/template/erubis.rb +15 -38
  99. data/lib/ramaze/template/ezamar.rb +100 -0
  100. data/lib/ramaze/template/ezamar/element.rb +166 -0
  101. data/lib/ramaze/template/ezamar/engine.rb +124 -0
  102. data/lib/ramaze/template/ezamar/morpher.rb +155 -0
  103. data/lib/ramaze/template/haml.rb +16 -43
  104. data/lib/ramaze/template/liquid.rb +11 -51
  105. data/lib/ramaze/template/markaby.rb +44 -42
  106. data/lib/ramaze/tool/mime.rb +18 -0
  107. data/lib/ramaze/tool/mime_types.yaml +615 -0
  108. data/lib/ramaze/trinity/request.rb +20 -196
  109. data/lib/ramaze/trinity/response.rb +4 -33
  110. data/lib/ramaze/trinity/session.rb +150 -72
  111. data/lib/ramaze/version.rb +1 -1
  112. data/spec/adapter_spec.rb +20 -0
  113. data/spec/public/favicon.ico +0 -0
  114. data/spec/public/ramaze.png +0 -0
  115. data/spec/public/test_download.css +141 -0
  116. data/spec/{tc_request.rb → request_tc_helper.rb} +45 -21
  117. data/spec/spec_all.rb +77 -34
  118. data/spec/spec_helper.rb +8 -157
  119. data/spec/spec_helper_context.rb +72 -0
  120. data/spec/spec_helper_requester.rb +52 -0
  121. data/spec/spec_helper_simple_http.rb +433 -0
  122. data/spec/tc_adapter_mongrel.rb +3 -15
  123. data/spec/tc_adapter_webrick.rb +4 -14
  124. data/spec/tc_cache.rb +3 -5
  125. data/spec/tc_controller.rb +22 -12
  126. data/spec/tc_dependencies.rb +13 -0
  127. data/spec/tc_element.rb +8 -7
  128. data/spec/tc_error.rb +13 -7
  129. data/spec/tc_global.rb +16 -18
  130. data/spec/tc_helper_aspect.rb +2 -4
  131. data/spec/tc_helper_auth.rb +15 -14
  132. data/spec/tc_helper_cache.rb +5 -7
  133. data/spec/tc_helper_feed.rb +0 -2
  134. data/spec/tc_helper_flash.rb +103 -0
  135. data/spec/tc_helper_form.rb +4 -6
  136. data/spec/tc_helper_link.rb +1 -3
  137. data/spec/tc_helper_redirect.rb +23 -8
  138. data/spec/tc_helper_stack.rb +31 -15
  139. data/spec/tc_morpher.rb +1 -3
  140. data/spec/tc_params.rb +48 -7
  141. data/spec/tc_request_mongrel.rb +9 -0
  142. data/spec/tc_request_webrick.rb +5 -0
  143. data/spec/tc_session.rb +41 -25
  144. data/spec/tc_store.rb +55 -6
  145. data/spec/tc_store_yaml.rb +71 -0
  146. data/spec/tc_template_amrita2.rb +3 -3
  147. data/spec/tc_template_erubis.rb +2 -3
  148. data/spec/{tc_template_ramaze.rb → tc_template_ezamar.rb} +15 -5
  149. data/spec/tc_template_haml.rb +4 -3
  150. data/spec/tc_template_liquid.rb +3 -4
  151. data/spec/tc_template_markaby.rb +4 -6
  152. data/spec/tc_tidy.rb +1 -3
  153. data/spec/template/amrita2/{data.html → data.amrita} +0 -0
  154. data/spec/template/amrita2/{index.html → index.amrita} +0 -0
  155. data/spec/template/amrita2/{sum.html → sum.amrita} +0 -0
  156. data/spec/template/ezamar/another/long/action.zmr +1 -0
  157. data/spec/template/ezamar/combined.zmr +1 -0
  158. data/spec/template/{ramaze/file_only.rmze → ezamar/file_only.zmr} +0 -0
  159. data/spec/template/{ramaze/index.rmze → ezamar/index.zmr} +0 -0
  160. data/spec/template/{ramaze/nested.rmze → ezamar/nested.zmr} +0 -0
  161. data/spec/template/ezamar/some__long__action.zmr +1 -0
  162. data/spec/template/{ramaze/sum.rmze → ezamar/sum.zmr} +0 -0
  163. metadata +181 -123
  164. data/doc/allison/LICENSE +0 -184
  165. data/doc/allison/README +0 -37
  166. data/doc/allison/allison.css +0 -300
  167. data/doc/allison/allison.gif +0 -0
  168. data/doc/allison/allison.js +0 -307
  169. data/doc/allison/allison.rb +0 -287
  170. data/doc/allison/cache/BODY +0 -588
  171. data/doc/allison/cache/CLASS_INDEX +0 -4
  172. data/doc/allison/cache/CLASS_PAGE +0 -1
  173. data/doc/allison/cache/FILE_INDEX +0 -4
  174. data/doc/allison/cache/FILE_PAGE +0 -1
  175. data/doc/allison/cache/FONTS +0 -1
  176. data/doc/allison/cache/FR_INDEX_BODY +0 -1
  177. data/doc/allison/cache/IMGPATH +0 -1
  178. data/doc/allison/cache/INDEX +0 -1
  179. data/doc/allison/cache/JAVASCRIPT +0 -307
  180. data/doc/allison/cache/METHOD_INDEX +0 -4
  181. data/doc/allison/cache/METHOD_LIST +0 -1
  182. data/doc/allison/cache/SRC_PAGE +0 -1
  183. data/doc/allison/cache/STYLE +0 -322
  184. data/doc/allison/cache/URL +0 -1
  185. data/doc/changes.txt +0 -2021
  186. data/doc/changes.xml +0 -2024
  187. data/lib/ramaze/snippets/kernel/silently.rb +0 -13
  188. data/lib/ramaze/snippets/thread/deadQUESTIONMARK.rb +0 -11
  189. data/lib/ramaze/template/haml/actionview_stub.rb +0 -20
  190. data/lib/ramaze/template/ramaze.rb +0 -177
  191. data/lib/ramaze/template/ramaze/element.rb +0 -166
  192. data/lib/ramaze/template/ramaze/morpher.rb +0 -156
  193. data/spec/tc_test.rb +0 -17
@@ -5,7 +5,7 @@ module Ramaze #:nodoc:
5
5
  module Version #:nodoc:
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- TINY = 7
8
+ TINY = 8
9
9
 
10
10
  STRING = [MAJOR, MINOR, TINY].join('.')
11
11
  end
@@ -0,0 +1,20 @@
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/spec_helper'
5
+
6
+ class TCAdapterController < Ramaze::Controller
7
+ def index
8
+ "The index"
9
+ end
10
+ end
11
+
12
+ context "Adapter" do
13
+ ramaze ramaze_options.merge( :port => '7007..7010', :mapping => {'/' => TCAdapterController} )
14
+
15
+ context "multiple" do
16
+ specify "simple request" do
17
+ get('/').should == "The index"
18
+ end
19
+ end
20
+ end
Binary file
Binary file
@@ -0,0 +1,141 @@
1
+ /*#############################################################
2
+ * Name: Light
3
+ * Date: 2006-08-20
4
+ * Description: Bright and smooth.
5
+ * Author: Viktor Persson
6
+ * URL: http://templates.arcsin.se
7
+ *
8
+ * Feel free to use and modify but please provide credits.
9
+ * #############################################################*/
10
+
11
+ /* standard elements */
12
+ {
13
+ margin: 0;
14
+ padding: 0;
15
+ }
16
+ a {
17
+ color: #567;
18
+ }
19
+ a:hover {
20
+ color: #28E;
21
+ }
22
+ body {
23
+ background: #F2F2F2 url(/media/bg.gif) repeat-y center top;
24
+ color: #555A60;
25
+ font: normal 62.5% "Lucida Sans Unicode",sans-serif;
26
+ margin: 0;
27
+ }
28
+ p,cite,code,ul {
29
+ font-size: 1.0em;
30
+ padding-bottom: 1.2em;
31
+ }
32
+ h1 {
33
+ font-size: 1.4em;
34
+ margin-bottom: 4px;
35
+ }
36
+ li {
37
+ list-style: url(/media/li.gif);
38
+ margin-left: 18px;
39
+ }
40
+ code {
41
+ background: url(/media/bgcode.gif);
42
+ border: 1px solid #F6F6F6;
43
+ color: #666;
44
+ display: block;
45
+ font: normal 1.1em "Lucida Sans Unicode",serif;
46
+ margin-bottom: 12px;
47
+ padding: 8px 10px;
48
+ white-space: pre;
49
+ }
50
+ cite {
51
+ background: url(/media/quote.gif) no-repeat;
52
+ color: #456;
53
+ display: block;
54
+ font: normal 1.4em "Lucida Sans Unicode",serif;
55
+ padding-left: 28px;
56
+ }
57
+ h1,h2,h3 {
58
+ color: #579;
59
+ padding-top: 6px;
60
+ }
61
+ *
62
+ /* misc */
63
+ .clearer {
64
+ clear: both;
65
+ }
66
+
67
+ /* structure */
68
+ .container {
69
+ margin: 0 auto;
70
+ width: 730px;
71
+ }
72
+
73
+ /* title */
74
+ .title {
75
+ float: left;
76
+ margin-top: 22px;
77
+ text-align: center;
78
+ width: 220px;
79
+ }
80
+ .title h1 {
81
+ font: normal 2em Verdana,sans-serif;
82
+ }
83
+ .title h2 {
84
+ color: #999;
85
+ font: normal 1.1em Verdana,sans-serif;
86
+ }
87
+
88
+ /* navigation */
89
+ .navigation {
90
+ background: url(/media/holder.jpg) no-repeat;
91
+ height: 100px;
92
+ padding: 0 16px;
93
+ }
94
+ .navigation a {
95
+ border-left: 1px solid #DDD;
96
+ border-right: 1px solid #FFF;
97
+ color: #89A;
98
+ float: right;
99
+ font: bold 1.2em "Trebuchet MS",sans-serif;
100
+ margin-top: 9px;
101
+ padding: 58px 18px 8px;
102
+ text-align: center;
103
+ text-decoration: none;
104
+ }
105
+ .navigation a:hover {
106
+ background: #FFF url(/media/navhover.gif) repeat-x;
107
+ color: #28E;
108
+ padding: 56px 18px 10px;
109
+ }
110
+
111
+ /* holders */
112
+ .holder {
113
+ background: url(/media/bgholder.jpg) repeat-y;
114
+ padding: 0 32px;
115
+ }
116
+ .holder_top,.footer {
117
+ clear: both;
118
+ background: url(/media/holder.jpg) no-repeat;
119
+ height: 40px;
120
+ }
121
+
122
+ /* footer */
123
+ .footer {
124
+ background-position: left bottom;
125
+ color: #666;
126
+ font-size: 1.1em;
127
+ text-align: center;
128
+ }
129
+
130
+ form {
131
+ text-align: right;
132
+ }
133
+
134
+ form input {
135
+ width: 95%;
136
+ }
137
+
138
+ form textarea {
139
+ width: 95%;
140
+ height: 30em;
141
+ }
@@ -3,9 +3,9 @@
3
3
 
4
4
  require 'spec/spec_helper'
5
5
 
6
- include Ramaze
6
+ class TCRequestController < Ramaze::Controller
7
+ trait :public => 'spec/public'
7
8
 
8
- class TCRequestController < Template::Ramaze
9
9
  def is_post() request.post?.to_s end
10
10
  def is_get() request.get?.to_s end
11
11
  def is_put() request.put?.to_s end
@@ -31,11 +31,6 @@ class TCRequestController < Template::Ramaze
31
31
  request['foo']
32
32
  end
33
33
 
34
- def test_get_set(arg)
35
- request['foo'] = arg
36
- request['foo']
37
- end
38
-
39
34
  def test_headers
40
35
  end
41
36
 
@@ -45,9 +40,10 @@ class TCRequestController < Template::Ramaze
45
40
  end
46
41
 
47
42
  context "Request" do
48
- context "POST" do
49
- ramaze( :adapter => :mongrel, :mapping => {'/' => TCRequestController} )
43
+ options = ramaze_options rescue {:adapter => :webrick}
44
+ ramaze options.merge( :mapping => {'/' => TCRequestController})
50
45
 
46
+ context "POST" do
51
47
  specify "give me the result of request.post?" do
52
48
  post("is_post").should == 'true'
53
49
  end
@@ -64,9 +60,11 @@ context "Request" do
64
60
 
65
61
  context "PUT" do
66
62
  specify "put a ressource" do
67
- address = "http://localhost:7007/put_inspect/#{CGI.escape(__FILE__)}"
68
- response = `curl -S -s -T #{__FILE__} #{address}`
69
- file = File.read(__FILE__)
63
+ image = 'favicon.ico'
64
+ image_path = File.join('spec', 'public', image)
65
+ address = "http://localhost:7007/put_inspect/#{image}"
66
+ response = `curl -S -s -T #{image_path} #{address}`
67
+ file = File.read(image_path)
70
68
 
71
69
  response[1..-2].should == file
72
70
  end
@@ -88,7 +86,8 @@ context "Request" do
88
86
  end
89
87
 
90
88
  specify "give me back what i gave" do
91
- get("/get_inspect?one=two&three=four").should == {'one' => 'two', 'three' => 'four'}.inspect
89
+ params = {'one' => 'two', 'three' => 'four'}
90
+ get("/get_inspect", params).should == params.inspect
92
91
  end
93
92
 
94
93
  specify "my ip" do
@@ -96,16 +95,41 @@ context "Request" do
96
95
  end
97
96
 
98
97
  specify "request[key]" do
99
- get('test_get?foo=bar').should == 'bar'
100
- end
101
-
102
- specify "request[key] = value" do
103
- get('test_get_set/bar').should == 'bar'
98
+ get('/test_get', 'foo' => 'bar').should == 'bar'
104
99
  end
100
+ end
105
101
 
106
- specify "header" do
107
- raw_get('/test_headers').status.should == %w[200 OK]
108
- raw_get('/test_headers').content_type.should == "text/html"
102
+ context "send files" do
103
+ specify "threaded concurrently" do
104
+ css_path = 'test_download.css'
105
+ image_path = 'favicon.ico'
106
+ static_css = File.read("spec/public/#{css_path}").strip
107
+ static_image = File.read("spec/public/#{image_path}").strip
108
+
109
+ images = []
110
+ csses = []
111
+ threads = []
112
+
113
+ times = 100
114
+
115
+ times.times do
116
+ threads << Thread.new do
117
+ csses << get(css_path)
118
+ images << get(image_path)
119
+ end
120
+ end
121
+
122
+ threads.each do |t|
123
+ t.join
124
+ end
125
+
126
+ images.each do |image|
127
+ image.should == static_image
128
+ end
129
+
130
+ csses.each do |css|
131
+ css.should == static_css
132
+ end
109
133
  end
110
134
  end
111
135
  end
@@ -2,12 +2,29 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  require 'pp'
5
+
6
+ begin
7
+ require 'systemu'
8
+ rescue LoadError
9
+ puts "Please install systemu for better-looking results"
10
+
11
+ # small drop-in replacement for systemu... far from perfect though, so please
12
+ # install the library
13
+
14
+ def systemu command
15
+ stdout = `#{command} 2>&1`
16
+ status, stdout, stderr = $?, stdout, ''
17
+ end
18
+ end
19
+
5
20
  begin
6
21
  require 'term/ansicolor'
7
22
  class String
8
23
  include Term::ANSIColor
9
24
  end
10
25
  rescue LoadError
26
+ puts "Please install term-ansicolor for better-looking results"
27
+
11
28
  class String
12
29
 
13
30
  # this will be set in case term/ansicolor cannot be
@@ -24,50 +41,76 @@ end
24
41
 
25
42
  $stdout.sync = true
26
43
 
27
- specs = 0
28
- failures = 0
29
- problematic = {}
30
-
31
- Dir['spec/**/tc_*.rb'].each do |test_case|
32
- print "rspec #{test_case.ljust(48)} "
33
- out = `ruby #{test_case}`
34
- out.split("\n").each do |line|
35
- if line =~ /(\d+) specifications?, (\d+) failures?/
36
- s, f = $1.to_i, $2.to_i
37
-
38
- specs += s
39
- failures += f
40
-
41
- message = "[#{s.to_s.rjust(3)} specs | "
42
-
43
- if f.nonzero? or $?.exitstatus != 0
44
- problematic[test_case] = out
45
- message << "#{f.to_s.rjust(3)} failed ]"
46
- puts message.red
47
- else
48
- message << "all passed ]"
49
- puts message.green
44
+ total_specs = 0
45
+ total_fails = 0
46
+ failed = {}
47
+ specs = Dir[File.join('spec', 'tc_*.rb')].sort
48
+ width = specs.sort_by{|s| s.size }.last.size
49
+
50
+ result_format = lambda do |str|
51
+ str = " #{ str } ".center(22, '=')
52
+ "[ #{str} ]"
53
+ end
54
+
55
+ specs.each do |spec|
56
+ print "Running #{spec}... ".ljust(width + 20)
57
+ status, stdout, stderr = systemu("ruby #{spec}")
58
+ hash = {:status => status, :stdout => stdout, :stderr => stderr}
59
+
60
+ if stdout =~ /Usually you should not worry about this failure, just install the/
61
+
62
+ lib = stdout.scan(/^no such file to load -- (.*?)$/).flatten.first
63
+ print result_format["needs #{lib}"].red
64
+
65
+ elsif status.exitstatus.nonzero? or stdout.empty? or not stderr.empty?
66
+
67
+ failed[spec] = hash
68
+ print result_format['failed'].red
69
+
70
+ else
71
+ stdout.each do |line|
72
+ if line =~ /(\d+) specifications?, (\d+) failures?/
73
+ s, f = $1.to_i, $2.to_i
74
+ ss, sf = s.to_s.rjust(3), f.to_s.rjust(3)
75
+
76
+ total_specs += s
77
+ total_fails += f
78
+
79
+ message = "[ #{ss} specs - "
80
+
81
+ if f.nonzero?
82
+ failed[spec] = hash
83
+ print((message << "#{f} failed ]").red)
84
+ else
85
+ print((message << "all passed ]").green)
86
+ end
50
87
  end
51
88
  end
52
89
  end
90
+ puts
53
91
  end
54
92
 
55
- puts "-" * 80
56
- problematic.each do |key, value|
57
- puts key.center(80)
58
- puts "v" * 80
93
+ failed.each do |name, hash|
94
+ status, stdout, stderr = hash.values_at(:status, :stdout, :stderr)
95
+
96
+ puts "[ #{name} ]".center(80, '-')
97
+ puts "ExitStatus:".yellow
98
+ pp status
99
+ puts
100
+ puts "StdOut:".yellow
101
+ puts stdout
59
102
  puts
60
- puts value
61
- puts "-" * 80
103
+ puts "StdErr:".yellow
104
+ puts stderr
62
105
  end
63
106
 
64
107
  puts
65
- puts "#{specs} specifications, #{failures} failures"
108
+ puts "#{total_specs} specifications, #{total_fails} failures"
66
109
  puts
67
110
 
68
- unless (problems = problematic.keys.join(', ')).empty?
69
- puts "These failed: #{problems}"
70
- else
111
+ if failed.empty?
71
112
  puts "No failing specifications, let's add some tests!"
113
+ puts
114
+ else
115
+ puts "These failed: #{failed.keys.join(', ')}"
72
116
  end
73
- puts
@@ -1,6 +1,8 @@
1
1
  # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
+ require 'timeout'
5
+
4
6
  $:.unshift File.join(File.dirname(File.expand_path(__FILE__)), '..', 'lib')
5
7
 
6
8
  require 'ramaze'
@@ -12,162 +14,11 @@ end
12
14
 
13
15
  require 'spec'
14
16
 
15
- require 'timeout'
16
- require 'open-uri'
17
- require 'net/http'
18
-
19
- # provides get/post methods for use inside your
20
- # Spec::Runner
21
-
22
- module StatelessContext
23
- def raw_get url = ''
24
- url = "http://localhost:#{Ramaze::Global.port}" + "/#{url}".squeeze('/')
25
- Timeout.timeout(1) do
26
- open(url)
27
- end
28
- end
29
-
30
- # just GET an [url]
31
-
32
- def get url = ''
33
- raw_get(url).read.strip
34
- end
35
-
36
- # POST to an url the given params
37
-
38
- def post url = '', params = {}
39
- url = "http://localhost:#{Ramaze::Global.port}" + "/#{url}".squeeze('/')
40
- uri = URI.parse(url)
41
- Timeout.timeout(1) do
42
- res = Net::HTTP.post_form(uri, params)
43
- result = res.body.to_s.strip
44
- #p res => result
45
- result
46
- end
47
- end
48
- end
49
-
50
- include StatelessContext
51
-
52
- # provides a convinient Context for your requests
53
- # so you can simulate sessions and consecutive requests
54
-
55
- class Context
56
- attr_accessor :cookie
57
-
58
- # initialize the context with an url to obtain your cookie
59
-
60
- def initialize(url = '/', base = nil)
61
- @base = base
62
- @cookie_url = with_base(url)
63
- @history = []
64
- reset
65
- end
66
-
67
- # combines the url given with the @base given, sanitizes
68
- # the result a bit.
69
-
70
- def with_base(url = '/')
71
- url = url.to_s.squeeze('/')
72
- if @base
73
- unless url[0...@base.size] == @base
74
- url = [@base, url].join('/')
75
- end
76
- end
77
- url.strip.squeeze('/')
78
- end
79
-
80
- # reset your session
81
-
82
- def reset(url = @cookie_url)
83
- @cookie = obtain_cookie( with_base(url) )
84
- end
85
-
86
- # just get a cookie, doesn't reset your session
87
-
88
- def obtain_cookie(url = @cookie_url)
89
- open(url).meta['set-cookie']
90
- end
91
-
92
- # our custom little open, take into account parameters and
93
- # the port the server is running on
94
- # the parameters are used for the session but could use
95
- # any headers you wanna use for the request
96
-
97
- def open url, hash = {}
98
- unless @history.empty?
99
- hash = {'HTTP_REFERER' => @history.last}.merge(hash)
100
- end
101
- url = with_base(url)
102
- uri = "http://localhost:#{Global.port}#{url}"
103
- puts "GET: #{uri}"
104
- result = Kernel.open(uri, hash)
105
- @history << url
106
- result
107
- end
108
-
109
- # use Context#open with our cookie
110
- # you can pass any header you want with an hash
111
-
112
- def get url = '', headers = {}
113
- open(url, {'Set-Cookie' => @cookie}.merge(headers)).read
114
- end
115
-
116
- # Net::HTTP.post_form with the cookie
117
- # params are for the POST-parameters
118
-
119
- def post url_param = '', params = {}, limit = 10
120
- raise "Too many redirections" if limit <= 0
121
-
122
- params['Set-Cookie'] = @cookie
123
- url = "http://localhost:#{Ramaze::Global.port}"
124
- new = with_base("/#{url_param.gsub(url, '')}")
125
- url << new
126
-
127
- uri = URI.parse(url)
128
- puts "POST: #{uri}"
129
- res = Net::HTTP.post_form(uri, params)
130
- @history << uri.path
131
-
132
- case res
133
- when Net::HTTPSuccess
134
- result = res.body.to_s.strip
135
- result
136
- when Net::HTTPRedirection
137
- post(res['location'], params, limit - 1)
138
- else
139
- res.error!
140
- end
141
- end
142
-
143
- # like post, but seval the returned string
144
- # very comfortable if you just do {'foo' => 'bar'}.inspect in your template
145
- # and in your specs you can
146
- # epost('/foo').should == {'foo' => 'bar'}
147
-
148
- def epost opt = '', params = {}
149
- seval(post(opt, params))
150
- end
151
-
152
- # like get, but seval the returned string
153
- # very comfortable if you just do {'foo' => 'bar'}.inspect in your template
154
- # and in your specs you can
155
- # eget('/foo').should == {'foo' => 'bar'}
17
+ require 'spec/spec_helper_simple_http'
18
+ require 'spec/spec_helper_requester'
19
+ require 'spec/spec_helper_context'
156
20
 
157
- def eget opt = ''
158
- seval(get(opt))
159
- end
160
-
161
- # a very simple wrapper for eval that returns the
162
- # error-message instead of the result of the eval
163
- # in case there are errors.
164
-
165
- def seval(string)
166
- eval(string)
167
- rescue Object => ex
168
- ex.message
169
- end
170
- end
21
+ include Requester
171
22
 
172
23
  module Spec::Runner::ContextEval::ModuleMethods
173
24
 
@@ -177,7 +28,7 @@ module Spec::Runner::ContextEval::ModuleMethods
177
28
  def ramaze_start hash = {}
178
29
  options = {
179
30
  :mode => :debug,
180
- :adapter => :webrick,
31
+ :adapter => :mongrel,
181
32
  :run_loose => true,
182
33
  :error_page => false,
183
34
  :port => 7007,
@@ -210,6 +61,6 @@ rescue LoadError => ex
210
61
  puts ex
211
62
  puts "Can't run #{$0}: #{ex}"
212
63
  puts "Usually you should not worry about this failure, just install the"
213
- puts "library and try again (if you want to use that featureit later on)"
64
+ puts "library and try again (if you want to use that feature later on)"
214
65
  exit
215
66
  end