padrino-core 0.10.2 → 0.10.3
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.
- data/.document +3 -3
- data/.yardopts +1 -0
- data/{LICENSE → LICENSE.txt} +0 -0
- data/README.rdoc +2 -2
- data/lib/padrino-core/application/rendering.rb +79 -26
- data/lib/padrino-core/application/routing.rb +215 -127
- data/lib/padrino-core/application/showexceptions.rb +2 -1
- data/lib/padrino-core/application.rb +67 -57
- data/lib/padrino-core/caller.rb +10 -4
- data/lib/padrino-core/command.rb +11 -0
- data/lib/padrino-core/loader.rb +52 -24
- data/lib/padrino-core/locale/cs.yml +4 -1
- data/lib/padrino-core/locale/da.yml +4 -1
- data/lib/padrino-core/locale/de.yml +4 -1
- data/lib/padrino-core/locale/en.yml +4 -1
- data/lib/padrino-core/locale/es.yml +4 -1
- data/lib/padrino-core/locale/fr.yml +4 -1
- data/lib/padrino-core/locale/hu.yml +4 -1
- data/lib/padrino-core/locale/it.yml +4 -1
- data/lib/padrino-core/locale/ja.yml +4 -1
- data/lib/padrino-core/locale/lv.yml +34 -0
- data/lib/padrino-core/locale/nl.yml +4 -1
- data/lib/padrino-core/locale/no.yml +4 -1
- data/lib/padrino-core/locale/pl.yml +4 -1
- data/lib/padrino-core/locale/pt_br.yml +4 -1
- data/lib/padrino-core/locale/ru.yml +4 -1
- data/lib/padrino-core/locale/tr.yml +4 -1
- data/lib/padrino-core/locale/uk.yml +4 -1
- data/lib/padrino-core/locale/zh_cn.yml +4 -1
- data/lib/padrino-core/locale/zh_tw.yml +4 -1
- data/lib/padrino-core/logger.rb +119 -128
- data/lib/padrino-core/mounter.rb +46 -14
- data/lib/padrino-core/reloader.rb +5 -3
- data/lib/padrino-core/router.rb +30 -11
- data/lib/padrino-core/server.rb +14 -5
- data/lib/padrino-core/support_lite.rb +54 -20
- data/lib/padrino-core/tasks.rb +1 -3
- data/lib/padrino-core/version.rb +8 -4
- data/lib/padrino-core.rb +58 -11
- data/padrino-core.gemspec +1 -1
- data/test/fixtures/apps/simple.rb +1 -1
- data/test/helper.rb +4 -24
- data/test/mini_shoulda.rb +45 -0
- data/test/test_application.rb +19 -18
- data/test/test_core.rb +2 -2
- data/test/test_dependencies.rb +5 -5
- data/test/test_filters.rb +2 -1
- data/test/test_locale.rb +1 -1
- data/test/test_logger.rb +1 -1
- data/test/test_mounter.rb +26 -25
- data/test/test_reloader_complex.rb +5 -3
- data/test/test_reloader_simple.rb +6 -5
- data/test/test_rendering.rb +8 -5
- data/test/test_restful_routing.rb +1 -1
- data/test/test_router.rb +1 -1
- data/test/test_routing.rb +33 -12
- metadata +13 -9
data/lib/padrino-core/router.rb
CHANGED
@@ -11,13 +11,7 @@ module Padrino
|
|
11
11
|
# * Ignore server names (this solve issues with vhost and domain aliases)
|
12
12
|
# * Use hosts instead of server name for mappings (this help us with our vhost and doman aliases)
|
13
13
|
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# :to:: The class of application that you want mount
|
17
|
-
# :path:: Map the app to the given path
|
18
|
-
# :host:: Map the app to the given host
|
19
|
-
#
|
20
|
-
# ==== Examples
|
14
|
+
# @example
|
21
15
|
#
|
22
16
|
# routes = Padrino::Router.new do
|
23
17
|
# map(:path => "/", :to => PadrinoWeb, :host => "padrino.local")
|
@@ -30,17 +24,33 @@ module Padrino
|
|
30
24
|
# end
|
31
25
|
# run routes
|
32
26
|
#
|
27
|
+
# @semipublic
|
33
28
|
class Router
|
29
|
+
|
30
|
+
# Constructs a new route mapper instance
|
34
31
|
def initialize(*mapping, &block)
|
35
32
|
@mapping = []
|
36
33
|
mapping.each { |m| map(m) }
|
37
34
|
instance_eval(&block) if block
|
38
35
|
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
##
|
38
|
+
# Map a route path and host to a specified application.
|
39
|
+
#
|
40
|
+
# @param [Hash] options
|
41
|
+
# The options to map.
|
42
|
+
# @option options [Sinatra::Application] :to
|
43
|
+
# The class of the application to mount.
|
44
|
+
# @option options [String] :path ("/")
|
45
|
+
# The path to map the specified application.
|
46
|
+
# @option options [String] :host
|
47
|
+
# The host to map the specified application.
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# map(:path => "/", :to => PadrinoWeb, :host => "padrino.local")
|
51
|
+
#
|
52
|
+
# @return [Array] The sorted route mappings.
|
53
|
+
# @api semipublic
|
44
54
|
def map(options={})
|
45
55
|
path = options[:path] || "/"
|
46
56
|
host = options[:host]
|
@@ -57,6 +67,8 @@ module Padrino
|
|
57
67
|
sort!
|
58
68
|
end
|
59
69
|
|
70
|
+
# The call handler setup to route a request given the mappings specified.
|
71
|
+
# @api private
|
60
72
|
def call(env)
|
61
73
|
rPath = env["PATH_INFO"].to_s
|
62
74
|
script_name = env['SCRIPT_NAME']
|
@@ -75,5 +87,12 @@ module Padrino
|
|
75
87
|
end
|
76
88
|
[404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{rPath}"]]
|
77
89
|
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
# Sorts the mapped routes in consistent order
|
94
|
+
def sort!
|
95
|
+
@mapping = @mapping.sort_by { |h, p, m, a| -p.size }
|
96
|
+
end
|
78
97
|
end # Router
|
79
98
|
end # Padrino
|
data/lib/padrino-core/server.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
module Padrino
|
2
2
|
##
|
3
|
-
#
|
4
|
-
# thin, mongrel, webrick in that order.
|
5
|
-
#
|
6
|
-
# ==== Examples
|
3
|
+
# Runs the Padrino apps as a self-hosted server using:
|
4
|
+
# thin, mongrel, or webrick in that order.
|
7
5
|
#
|
6
|
+
# @example
|
8
7
|
# Padrino.run! # with these defaults => host: "localhost", port: "3000", adapter: the first found
|
9
8
|
# Padrino.run!("localhost", "4000", "mongrel") # use => host: "0.0.0.0", port: "3000", adapter: "mongrel"
|
10
9
|
#
|
@@ -14,12 +13,13 @@ module Padrino
|
|
14
13
|
end
|
15
14
|
|
16
15
|
##
|
17
|
-
# This module
|
16
|
+
# This module builds a Padrino server to run the project based on available handlers.
|
18
17
|
#
|
19
18
|
class Server < Rack::Server
|
20
19
|
# Server Handlers
|
21
20
|
Handlers = [:thin, :mongrel, :webrick]
|
22
21
|
|
22
|
+
# Starts the application on the available server with specified options.
|
23
23
|
def self.start(app, opts={})
|
24
24
|
options = {}.merge(opts) # We use a standard hash instead of Thor::CoreExt::HashWithIndifferentAccess
|
25
25
|
options.symbolize_keys!
|
@@ -38,6 +38,7 @@ module Padrino
|
|
38
38
|
@options, @app = options, app
|
39
39
|
end
|
40
40
|
|
41
|
+
# Starts the application on the available server with specified options.
|
41
42
|
def start
|
42
43
|
puts "=> Padrino/#{Padrino.version} has taken the stage #{Padrino.env} at http://#{options[:Host]}:#{options[:Port]}"
|
43
44
|
[:INT, :TERM].each { |sig| trap(sig) { exit } }
|
@@ -46,16 +47,24 @@ module Padrino
|
|
46
47
|
puts "<= Padrino has ended his set (crowd applauds)" unless options[:daemonize]
|
47
48
|
end
|
48
49
|
|
50
|
+
# The application the server will run.
|
49
51
|
def app
|
50
52
|
@app
|
51
53
|
end
|
52
54
|
alias :wrapped_app :app
|
53
55
|
|
56
|
+
# The options specified to the server.
|
54
57
|
def options
|
55
58
|
@options
|
56
59
|
end
|
57
60
|
|
58
61
|
private
|
62
|
+
|
63
|
+
# Detects the supported handler to use.
|
64
|
+
#
|
65
|
+
# @example
|
66
|
+
# detect_rack_handler => <ThinHandler>
|
67
|
+
#
|
59
68
|
def self.detect_rack_handler
|
60
69
|
Handlers.each do |handler|
|
61
70
|
begin
|
@@ -10,10 +10,12 @@ require 'active_support/core_ext/array/extract_options' # extract_options
|
|
10
10
|
require 'active_support/inflector/methods' # constantize
|
11
11
|
require 'active_support/inflector/inflections' # pluralize
|
12
12
|
require 'active_support/inflections' # load default inflections
|
13
|
+
require 'yaml' unless defined?(YAML) # load yaml for i18n
|
14
|
+
require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/ # ruby color suppor for win
|
13
15
|
|
14
16
|
##
|
15
|
-
# This is
|
16
|
-
# to prevent
|
17
|
+
# This is an adapted version of active_support/core_ext/string/inflections.rb
|
18
|
+
# to prevent loading several dependencies including I18n gem.
|
17
19
|
#
|
18
20
|
# Issue: https://github.com/rails/rails/issues/1526
|
19
21
|
#
|
@@ -51,7 +53,6 @@ class String
|
|
51
53
|
# in the string. It raises a NameError when the name is not in CamelCase
|
52
54
|
# or is not initialized.
|
53
55
|
#
|
54
|
-
# Examples
|
55
56
|
# "Module".constantize # => Module
|
56
57
|
# "Class".constantize # => Class
|
57
58
|
#
|
@@ -59,6 +60,18 @@ class String
|
|
59
60
|
ActiveSupport::Inflector.constantize(self)
|
60
61
|
end
|
61
62
|
|
63
|
+
##
|
64
|
+
# The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
|
65
|
+
#
|
66
|
+
# +underscore+ will also change '::' to '/' to convert namespaces to paths.
|
67
|
+
#
|
68
|
+
# "ActiveRecord".underscore # => "active_record"
|
69
|
+
# "ActiveRecord::Errors".underscore # => active_record/errors
|
70
|
+
#
|
71
|
+
def underscore
|
72
|
+
ActiveSupport::Inflector.underscore(self)
|
73
|
+
end
|
74
|
+
|
62
75
|
##
|
63
76
|
# By default, +camelize+ converts strings to UpperCamelCase. If the argument to camelize
|
64
77
|
# is set to <tt>:lower</tt> then camelize produces lowerCamelCase.
|
@@ -78,18 +91,6 @@ class String
|
|
78
91
|
end
|
79
92
|
alias_method :camelcase, :camelize
|
80
93
|
|
81
|
-
##
|
82
|
-
# The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
|
83
|
-
#
|
84
|
-
# +underscore+ will also change '::' to '/' to convert namespaces to paths.
|
85
|
-
#
|
86
|
-
# "ActiveRecord".underscore # => "active_record"
|
87
|
-
# "ActiveRecord::Errors".underscore # => active_record/errors
|
88
|
-
#
|
89
|
-
def underscore
|
90
|
-
ActiveSupport::Inflector.underscore(self)
|
91
|
-
end
|
92
|
-
|
93
94
|
##
|
94
95
|
# Create a class name from a plural table name like Rails does for table names to models.
|
95
96
|
# Note that this returns a string and not a class. (To convert to an actual class
|
@@ -148,11 +149,44 @@ module FileSet
|
|
148
149
|
end
|
149
150
|
|
150
151
|
##
|
151
|
-
#
|
152
|
-
#
|
152
|
+
# Removes indentation
|
153
|
+
# Add colors
|
154
|
+
#
|
155
|
+
# @example
|
156
|
+
# help <<-EOS.undent
|
157
|
+
# Here my help usage
|
158
|
+
# sample_code
|
159
|
+
#
|
160
|
+
# Fix
|
161
|
+
# EOS
|
162
|
+
# puts help.red.bold
|
153
163
|
#
|
154
|
-
|
155
|
-
|
164
|
+
class String
|
165
|
+
def self.colors
|
166
|
+
@_colors ||= {
|
167
|
+
:clear => 0,
|
168
|
+
:bold => 1,
|
169
|
+
:black => 30,
|
170
|
+
:red => 31,
|
171
|
+
:green => 32,
|
172
|
+
:yellow => 33,
|
173
|
+
:blue => 34,
|
174
|
+
:magenta => 35,
|
175
|
+
:cyan => 36,
|
176
|
+
:white => 37
|
177
|
+
}
|
178
|
+
end
|
179
|
+
|
180
|
+
colors.each do |color, value|
|
181
|
+
define_method(color) do
|
182
|
+
["\e[", value.to_s, "m", self, "\e[", self.class.colors[:clear], "m"] * ''
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def undent
|
187
|
+
gsub(/^.{#{slice(/^ +/).size}}/, '')
|
188
|
+
end
|
189
|
+
end
|
156
190
|
|
157
191
|
##
|
158
192
|
# Loads our locale configuration files
|
@@ -160,6 +194,6 @@ YAML::ENGINE.yamler = "syck" if defined?(YAML::ENGINE)
|
|
160
194
|
I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"] if defined?(I18n)
|
161
195
|
|
162
196
|
##
|
163
|
-
# Used to
|
197
|
+
# Used to determine if this file has already been required
|
164
198
|
#
|
165
199
|
module SupportLite; end
|
data/lib/padrino-core/tasks.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
module Padrino
|
2
|
-
|
3
2
|
##
|
4
3
|
# This module it's used for bootstrap with padrino rake
|
5
4
|
# thirdy party tasks, in your gem/plugin/extension you
|
6
5
|
# need only do this:
|
7
6
|
#
|
8
|
-
#
|
9
|
-
#
|
7
|
+
# @example
|
10
8
|
# Padrino::Tasks.files << yourtask.rb
|
11
9
|
# Padrino::Tasks.files.concat(Dir["/path/to/all/my/tasks/*.rb"])
|
12
10
|
# Padrino::Tasks.files.unshift("yourtask.rb")
|
data/lib/padrino-core/version.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
|
1
|
+
#
|
2
2
|
# Manages current Padrino version for use in gem generation.
|
3
3
|
#
|
4
4
|
# We put this in a separate file so you can get padrino version
|
5
5
|
# without include full padrino core.
|
6
6
|
#
|
7
7
|
module Padrino
|
8
|
-
VERSION = '0.10.
|
9
|
-
|
10
|
-
#
|
8
|
+
VERSION = '0.10.3' unless defined?(Padrino::VERSION)
|
9
|
+
|
10
|
+
#
|
11
|
+
# The current Padrino version.
|
12
|
+
#
|
13
|
+
# @return [String]
|
14
|
+
# The version number.
|
11
15
|
#
|
12
16
|
def self.version
|
13
17
|
VERSION
|
data/lib/padrino-core.rb
CHANGED
@@ -16,8 +16,13 @@ module Padrino
|
|
16
16
|
##
|
17
17
|
# Helper method for file references.
|
18
18
|
#
|
19
|
-
#
|
19
|
+
# @param [Array<String>] args
|
20
|
+
# The directories to join to {PADRINO_ROOT}.
|
20
21
|
#
|
22
|
+
# @return [String]
|
23
|
+
# The absolute path.
|
24
|
+
#
|
25
|
+
# @example
|
21
26
|
# # Referencing a file in config called settings.yml
|
22
27
|
# Padrino.root("config", "settings.yml")
|
23
28
|
# # returns PADRINO_ROOT + "/config/setting.yml"
|
@@ -27,21 +32,30 @@ module Padrino
|
|
27
32
|
end
|
28
33
|
|
29
34
|
##
|
30
|
-
# Helper method that return PADRINO_ENV
|
35
|
+
# Helper method that return {PADRINO_ENV}.
|
36
|
+
#
|
37
|
+
# @return [Symbol]
|
38
|
+
# The Padrino Environment.
|
31
39
|
#
|
32
40
|
def env
|
33
41
|
@_env ||= PADRINO_ENV.to_s.downcase.to_sym
|
34
42
|
end
|
35
43
|
|
36
44
|
##
|
37
|
-
#
|
45
|
+
# The resulting rack builder mapping each 'mounted' application.
|
46
|
+
#
|
47
|
+
# @return [Padrino::Router]
|
48
|
+
# The router for the application.
|
49
|
+
#
|
50
|
+
# @raise [ApplicationLoadError]
|
51
|
+
# No applications were mounted.
|
38
52
|
#
|
39
53
|
def application
|
40
54
|
raise ApplicationLoadError, "At least one app must be mounted!" unless Padrino.mounted_apps && Padrino.mounted_apps.any?
|
41
55
|
router = Padrino::Router.new
|
42
56
|
Padrino.mounted_apps.each { |app| app.map_onto(router) }
|
43
57
|
|
44
|
-
|
58
|
+
if middleware.present?
|
45
59
|
builder = Rack::Builder.new
|
46
60
|
middleware.each { |c,a,b| builder.use(c, *a, &b) }
|
47
61
|
builder.run(router)
|
@@ -55,6 +69,10 @@ module Padrino
|
|
55
69
|
# Configure Global Project Settings for mounted apps. These can be overloaded
|
56
70
|
# in each individual app's own personal configuration. This can be used like:
|
57
71
|
#
|
72
|
+
# @yield []
|
73
|
+
# The given block will be called to configure each application.
|
74
|
+
#
|
75
|
+
# @example
|
58
76
|
# Padrino.configure_apps do
|
59
77
|
# enable :sessions
|
60
78
|
# disable :raise_errors
|
@@ -64,16 +82,24 @@ module Padrino
|
|
64
82
|
@_global_configuration = block if block_given?
|
65
83
|
end
|
66
84
|
|
67
|
-
|
68
|
-
# Returns project-wide configuration settings
|
69
|
-
#
|
85
|
+
##
|
86
|
+
# Returns project-wide configuration settings defined in
|
87
|
+
# {configure_apps} block.
|
70
88
|
#
|
71
89
|
def apps_configuration
|
72
90
|
@_global_configuration
|
73
91
|
end
|
74
92
|
|
75
93
|
##
|
76
|
-
#
|
94
|
+
# Set +Encoding.default_internal+ and +Encoding.default_external+
|
95
|
+
# to +Encoding::UFT_8+.
|
96
|
+
#
|
97
|
+
# Please note that in +1.9.2+ with some template engines like +haml+
|
98
|
+
# you should turn off Encoding.default_internal to prevent problems.
|
99
|
+
#
|
100
|
+
# @see https://github.com/rtomayko/tilt/issues/75
|
101
|
+
#
|
102
|
+
# @return [NilClass]
|
77
103
|
#
|
78
104
|
def set_encoding
|
79
105
|
if RUBY_VERSION < '1.9'
|
@@ -86,9 +112,15 @@ module Padrino
|
|
86
112
|
end
|
87
113
|
|
88
114
|
##
|
89
|
-
#
|
115
|
+
# Determines whether the dependencies are locked by Bundler.
|
90
116
|
# otherwise return nil
|
91
117
|
#
|
118
|
+
# @return [:locked, :unlocked, nil]
|
119
|
+
# Returns +:locked+ if the +Gemfile.lock+ file exists, or +:unlocked+
|
120
|
+
# if only the +Gemfile+ exists.
|
121
|
+
#
|
122
|
+
# @deprecated Will be removed in 1.0.0
|
123
|
+
#
|
92
124
|
def bundle
|
93
125
|
return :locked if File.exist?(root('Gemfile.lock'))
|
94
126
|
return :unlocked if File.exist?(root("Gemfile"))
|
@@ -96,14 +128,20 @@ module Padrino
|
|
96
128
|
|
97
129
|
##
|
98
130
|
# A Rack::Builder object that allows to add middlewares in front of all
|
99
|
-
# Padrino applications
|
131
|
+
# Padrino applications.
|
132
|
+
#
|
133
|
+
# @return [Array<Array<Class, Array, Proc>>]
|
134
|
+
# The middleware classes.
|
100
135
|
#
|
101
136
|
def middleware
|
102
137
|
@middleware ||= []
|
103
138
|
end
|
104
139
|
|
105
140
|
##
|
106
|
-
# Clears all previously configured middlewares
|
141
|
+
# Clears all previously configured middlewares.
|
142
|
+
#
|
143
|
+
# @return [Array]
|
144
|
+
# An empty array
|
107
145
|
#
|
108
146
|
def clear_middleware!
|
109
147
|
@middleware = []
|
@@ -112,6 +150,15 @@ module Padrino
|
|
112
150
|
##
|
113
151
|
# Convenience method for adding a Middleware to the whole padrino app.
|
114
152
|
#
|
153
|
+
# @param [Class] m
|
154
|
+
# The middleware class.
|
155
|
+
#
|
156
|
+
# @param [Array] args
|
157
|
+
# The arguments for the middleware.
|
158
|
+
#
|
159
|
+
# @yield []
|
160
|
+
# The given block will be passed to the initialized middleware.
|
161
|
+
#
|
115
162
|
def use(m, *args, &block)
|
116
163
|
middleware << [m, args, block]
|
117
164
|
end
|
data/padrino-core.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.post_install_message << "\n\e[32m" + ("*" * 20) + "\n\e[0m"
|
32
32
|
|
33
33
|
s.add_dependency("tilt", "~> 1.3.0")
|
34
|
-
s.add_dependency("sinatra", "~> 1.
|
34
|
+
s.add_dependency("sinatra", "~> 1.3.0")
|
35
35
|
s.add_dependency("http_router", "~> 0.10.2")
|
36
36
|
s.add_dependency("thor", "~> 0.14.3")
|
37
37
|
s.add_dependency("activesupport", "~> 3.1.0")
|
@@ -14,7 +14,7 @@ end
|
|
14
14
|
|
15
15
|
SimpleDemo.controllers do
|
16
16
|
get "/" do
|
17
|
-
'The magick number is:
|
17
|
+
'The magick number is: 2767356926488785838763860464013972991031534522105386787489885890443740254365!' # Change only the number!!!
|
18
18
|
end
|
19
19
|
|
20
20
|
get "/rand" do
|
data/test/helper.rb
CHANGED
@@ -2,42 +2,22 @@ ENV['PADRINO_ENV'] = 'test'
|
|
2
2
|
PADRINO_ROOT = File.dirname(__FILE__) unless defined?(PADRINO_ROOT)
|
3
3
|
|
4
4
|
require File.expand_path('../../../load_paths', __FILE__)
|
5
|
+
require File.expand_path('../mini_shoulda', __FILE__)
|
5
6
|
require 'padrino-core'
|
6
7
|
require 'json'
|
7
|
-
require 'test/unit'
|
8
8
|
require 'rack/test'
|
9
9
|
require 'rack'
|
10
|
-
require 'shoulda'
|
11
10
|
|
12
11
|
# Rubies < 1.9 don't handle hashes in the properly order so to prevent
|
13
12
|
# this issue for now we remove extra values from mimetypes.
|
14
13
|
Rack::Mime::MIME_TYPES.delete(".xsl") # In this way application/xml respond only to .xml
|
15
14
|
|
16
|
-
|
17
|
-
# Silences the output by redirecting to stringIO
|
18
|
-
# silence_logger { ...commands... } => "...output..."
|
19
|
-
def silence_logger(&block)
|
20
|
-
$stdout = log_buffer = StringIO.new
|
21
|
-
block.call
|
22
|
-
$stdout = STDOUT
|
23
|
-
log_buffer.string
|
24
|
-
end
|
25
|
-
alias :silence_stdout :silence_logger
|
26
|
-
|
27
|
-
def silence_warnings
|
28
|
-
old_verbose, $VERBOSE = $VERBOSE, nil
|
29
|
-
yield
|
30
|
-
ensure
|
31
|
-
$VERBOSE = old_verbose
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class Class
|
15
|
+
class Sinatra::Base
|
36
16
|
# Allow assertions in request context
|
37
|
-
include
|
17
|
+
include MiniTest::Assertions
|
38
18
|
end
|
39
19
|
|
40
|
-
class
|
20
|
+
class MiniTest::Spec
|
41
21
|
include Rack::Test::Methods
|
42
22
|
|
43
23
|
# Sets up a Sinatra::Base subclass defined with the block
|
@@ -0,0 +1,45 @@
|
|
1
|
+
gem 'minitest'
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'mocha' # Load mocha after minitest
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'ruby-debug'
|
8
|
+
rescue LoadError; end
|
9
|
+
|
10
|
+
class MiniTest::Spec
|
11
|
+
class << self
|
12
|
+
alias :setup :before unless defined?(Rails)
|
13
|
+
alias :teardown :after unless defined?(Rails)
|
14
|
+
alias :should :it
|
15
|
+
alias :context :describe
|
16
|
+
def should_eventually(desc)
|
17
|
+
it("should eventually #{desc}") { skip("Should eventually #{desc}") }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
alias :assert_no_match :refute_match
|
21
|
+
alias :assert_not_nil :refute_nil
|
22
|
+
alias :assert_not_equal :refute_equal
|
23
|
+
end
|
24
|
+
|
25
|
+
class ColoredIO
|
26
|
+
def initialize(io)
|
27
|
+
@io = io
|
28
|
+
end
|
29
|
+
|
30
|
+
def print(o)
|
31
|
+
case o
|
32
|
+
when "." then @io.send(:print, o.green)
|
33
|
+
when "E" then @io.send(:print, o.red)
|
34
|
+
when "F" then @io.send(:print, o.yellow)
|
35
|
+
when "S" then @io.send(:print, o.magenta)
|
36
|
+
else @io.send(:print, o)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def puts(*o)
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
MiniTest::Unit.output = ColoredIO.new(MiniTest::Unit.output)
|
data/test/test_application.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
2
|
|
3
|
+
class PadrinoPristine < Padrino::Application; end
|
3
4
|
class PadrinoTestApp < Padrino::Application; end
|
4
5
|
class PadrinoTestApp2 < Padrino::Application; end
|
5
6
|
|
6
|
-
|
7
|
+
describe "Application" do
|
7
8
|
def setup
|
8
9
|
Padrino.clear!
|
9
10
|
end
|
@@ -15,27 +16,27 @@ class TestApplication < Test::Unit::TestCase
|
|
15
16
|
context 'for application functionality' do
|
16
17
|
|
17
18
|
should 'check default options' do
|
18
|
-
assert File.identical?(__FILE__,
|
19
|
-
assert_equal :
|
20
|
-
assert_equal :test,
|
21
|
-
assert_equal Padrino.root("views"),
|
22
|
-
assert
|
23
|
-
assert !
|
24
|
-
assert !
|
25
|
-
assert !
|
26
|
-
assert !
|
27
|
-
assert
|
19
|
+
assert File.identical?(__FILE__, PadrinoPristine.app_file)
|
20
|
+
assert_equal :padrino_pristine, PadrinoPristine.app_name
|
21
|
+
assert_equal :test, PadrinoPristine.environment
|
22
|
+
assert_equal Padrino.root("views"), PadrinoPristine.views
|
23
|
+
assert PadrinoPristine.raise_errors
|
24
|
+
assert !PadrinoPristine.logging
|
25
|
+
assert !PadrinoPristine.sessions
|
26
|
+
assert !PadrinoPristine.dump_errors
|
27
|
+
assert !PadrinoPristine.show_exceptions
|
28
|
+
assert PadrinoPristine.raise_errors
|
28
29
|
assert !Padrino.configure_apps
|
29
30
|
end
|
30
31
|
|
31
32
|
should 'check padrino specific options' do
|
32
|
-
assert !
|
33
|
-
|
34
|
-
assert_equal :
|
35
|
-
assert_equal 'StandardFormBuilder',
|
36
|
-
assert
|
37
|
-
assert !
|
38
|
-
assert !
|
33
|
+
assert !PadrinoPristine.instance_variable_get(:@_configured)
|
34
|
+
PadrinoPristine.send(:setup_application!)
|
35
|
+
assert_equal :padrino_pristine, PadrinoPristine.app_name
|
36
|
+
assert_equal 'StandardFormBuilder', PadrinoPristine.default_builder
|
37
|
+
assert PadrinoPristine.instance_variable_get(:@_configured)
|
38
|
+
assert !PadrinoPristine.reload?
|
39
|
+
assert !PadrinoPristine.flash
|
39
40
|
end
|
40
41
|
|
41
42
|
should 'set global project settings' do
|
data/test/test_core.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
2
|
|
3
|
-
|
3
|
+
describe "Core" do
|
4
4
|
def setup
|
5
5
|
Padrino.clear!
|
6
6
|
end
|
@@ -42,7 +42,7 @@ class TestCore < Test::Unit::TestCase
|
|
42
42
|
end
|
43
43
|
|
44
44
|
should 'raise application error if I instantiate a new padrino application without mounted apps' do
|
45
|
-
|
45
|
+
assert_raises(Padrino::ApplicationLoadError) { Padrino.application.new }
|
46
46
|
end
|
47
47
|
|
48
48
|
should "check before/after padrino load hooks" do
|
data/test/test_dependencies.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
2
|
|
3
|
-
|
3
|
+
describe "Dependencies" do
|
4
4
|
context 'when we require a dependency that have another dependency' do
|
5
5
|
|
6
6
|
should 'raise an error without reloading it twice' do
|
7
|
-
|
8
|
-
|
7
|
+
capture_io do
|
8
|
+
assert_raises(RuntimeError) do
|
9
9
|
Padrino.require_dependencies(
|
10
10
|
Padrino.root("fixtures/dependencies/a.rb"),
|
11
11
|
Padrino.root("fixtures/dependencies/b.rb"),
|
@@ -18,7 +18,7 @@ class TestDependencies < Test::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
should 'resolve dependency problems' do
|
21
|
-
|
21
|
+
capture_io do
|
22
22
|
Padrino.require_dependencies(
|
23
23
|
Padrino.root("fixtures/dependencies/a.rb"),
|
24
24
|
Padrino.root("fixtures/dependencies/b.rb"),
|
@@ -30,7 +30,7 @@ class TestDependencies < Test::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
should 'remove partially loaded constants' do
|
33
|
-
|
33
|
+
capture_io do
|
34
34
|
Padrino.require_dependencies(
|
35
35
|
Padrino.root("fixtures/dependencies/circular/e.rb"),
|
36
36
|
Padrino.root("fixtures/dependencies/circular/f.rb"),
|
data/test/test_filters.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
2
|
|
3
|
-
|
3
|
+
describe "Filters" do
|
4
4
|
should "filters by accept header" do
|
5
5
|
mock_app do
|
6
6
|
get '/foo', :provides => [:xml, :js] do
|
@@ -269,6 +269,7 @@ class TestFilters < Test::Unit::TestCase
|
|
269
269
|
mock_app do
|
270
270
|
before(:index, '/foo') { test = 'before' }
|
271
271
|
get :index do
|
272
|
+
''
|
272
273
|
end
|
273
274
|
end
|
274
275
|
get '/foo'
|
data/test/test_locale.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
2
|
|
3
|
-
|
3
|
+
describe "Locales" do
|
4
4
|
Dir[File.expand_path("../../lib/padrino-core/locale/*.yml", __FILE__)].each do |file|
|
5
5
|
base_original = YAML.load_file(file)
|
6
6
|
name = File.basename(file, '.yml')
|