waw 0.2.2
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/LICENCE.rdoc +25 -0
- data/README.rdoc +32 -0
- data/bin/waw +32 -0
- data/bin/waw-profile +26 -0
- data/bin/waw-start +26 -0
- data/bin/wspec +33 -0
- data/layouts/empty/Rakefile +14 -0
- data/layouts/empty/config.ru +5 -0
- data/layouts/empty/config/commons.cfg +31 -0
- data/layouts/empty/config/devel.cfg +21 -0
- data/layouts/empty/ignore +7 -0
- data/layouts/empty/logs/dontforgetme +0 -0
- data/layouts/empty/resources/messages.rs +1 -0
- data/layouts/empty/test/wspec/site_respond.wspec +3 -0
- data/layouts/empty/test/wspec/test_all.rb +13 -0
- data/layouts/empty/waw.deploy +1 -0
- data/layouts/empty/waw.routing +6 -0
- data/layouts/static/dependencies +1 -0
- data/layouts/static/public/.wawaccess +18 -0
- data/layouts/static/public/css/style.css +0 -0
- data/layouts/static/public/images/dontforgetme +0 -0
- data/layouts/static/public/js/project.js +0 -0
- data/layouts/static/public/pages/.wawaccess +30 -0
- data/layouts/static/public/pages/404.wtpl +1 -0
- data/layouts/static/public/pages/index.wtpl +5 -0
- data/layouts/static/public/templates/.wawaccess +9 -0
- data/layouts/static/public/templates/layout.wtpl +17 -0
- data/layouts/static/test/wspec/static_pages_are_served.wspec +21 -0
- data/layouts/static/waw.routing +8 -0
- data/lib/waw.rb +99 -0
- data/lib/waw/commands/command.rb +115 -0
- data/lib/waw/commands/profile_command.rb +66 -0
- data/lib/waw/commands/start_command.rb +59 -0
- data/lib/waw/config.rb +110 -0
- data/lib/waw/controller.rb +25 -0
- data/lib/waw/controllers/action/action.rb +91 -0
- data/lib/waw/controllers/action/action_utils.rb +30 -0
- data/lib/waw/controllers/action/js_generation.rb +116 -0
- data/lib/waw/controllers/action_controller.rb +133 -0
- data/lib/waw/controllers/error/backtrace.rb +54 -0
- data/lib/waw/controllers/error_handler.rb +62 -0
- data/lib/waw/controllers/json_controller.rb +31 -0
- data/lib/waw/controllers/no_cache.rb +22 -0
- data/lib/waw/controllers/static/match.rb +80 -0
- data/lib/waw/controllers/static/waw_access.rb +235 -0
- data/lib/waw/controllers/static/waw_access_dsl.rb +48 -0
- data/lib/waw/controllers/static_controller.rb +37 -0
- data/lib/waw/default_config.cfg +14 -0
- data/lib/waw/environment_utils.rb +57 -0
- data/lib/waw/errors.rb +4 -0
- data/lib/waw/ext.rb +3 -0
- data/lib/waw/ext/core.rb +4 -0
- data/lib/waw/ext/core/hash.rb +47 -0
- data/lib/waw/ext/core/logger.rb +10 -0
- data/lib/waw/ext/core/module.rb +20 -0
- data/lib/waw/ext/core/object.rb +29 -0
- data/lib/waw/ext/rack.rb +19 -0
- data/lib/waw/ext/rack/builder.rb +43 -0
- data/lib/waw/ext/rack/delegator.rb +51 -0
- data/lib/waw/ext/rack/urlmap.rb +55 -0
- data/lib/waw/ext/wlang.rb +1 -0
- data/lib/waw/ext/wlang/hosted_language.rb +21 -0
- data/lib/waw/fullstate.rb +8 -0
- data/lib/waw/fullstate/on_class.rb +37 -0
- data/lib/waw/fullstate/on_instance.rb +27 -0
- data/lib/waw/fullstate/variable.rb +36 -0
- data/lib/waw/kern.rb +6 -0
- data/lib/waw/kern/app.rb +48 -0
- data/lib/waw/kern/empty/waw.deploy +0 -0
- data/lib/waw/kern/empty/waw.routing +1 -0
- data/lib/waw/kern/freezed_state.rb +32 -0
- data/lib/waw/kern/hooks.rb +53 -0
- data/lib/waw/kern/lifecycle.rb +248 -0
- data/lib/waw/kern/living_state.rb +87 -0
- data/lib/waw/kern/utils.rb +27 -0
- data/lib/waw/resource_collection.rb +100 -0
- data/lib/waw/restart.rb +32 -0
- data/lib/waw/routing.rb +43 -0
- data/lib/waw/routing/action_routing.rb +78 -0
- data/lib/waw/routing/dsl.rb +45 -0
- data/lib/waw/routing/feedback.rb +23 -0
- data/lib/waw/routing/form_validation_feedback.rb +36 -0
- data/lib/waw/routing/javascript.rb +17 -0
- data/lib/waw/routing/redirect.rb +26 -0
- data/lib/waw/routing/refresh.rb +17 -0
- data/lib/waw/routing/routing_rule.rb +16 -0
- data/lib/waw/scope_utils.rb +69 -0
- data/lib/waw/session.rb +51 -0
- data/lib/waw/testing.rb +1 -0
- data/lib/waw/tools/mail.rb +4 -0
- data/lib/waw/tools/mail/mail.rb +119 -0
- data/lib/waw/tools/mail/mail_agent.rb +123 -0
- data/lib/waw/tools/mail/mailbox.rb +62 -0
- data/lib/waw/tools/mail/template.rb +38 -0
- data/lib/waw/utils/dsl_helper.rb +116 -0
- data/lib/waw/validation.rb +175 -0
- data/lib/waw/validation/and_validator.rb +27 -0
- data/lib/waw/validation/array_validations.rb +38 -0
- data/lib/waw/validation/boolean_validator.rb +32 -0
- data/lib/waw/validation/comparison_validations.rb +45 -0
- data/lib/waw/validation/date_validator.rb +31 -0
- data/lib/waw/validation/default_validator.rb +30 -0
- data/lib/waw/validation/dsl_ruby_extensions.rb +11 -0
- data/lib/waw/validation/errors.rb +17 -0
- data/lib/waw/validation/ext.rb +3 -0
- data/lib/waw/validation/file_validator.rb +30 -0
- data/lib/waw/validation/float_validator.rb +19 -0
- data/lib/waw/validation/helpers.rb +67 -0
- data/lib/waw/validation/integer_validator.rb +16 -0
- data/lib/waw/validation/isin_validator.rb +24 -0
- data/lib/waw/validation/mandatory_validator.rb +17 -0
- data/lib/waw/validation/missing_validator.rb +17 -0
- data/lib/waw/validation/not_validator.rb +20 -0
- data/lib/waw/validation/or_validator.rb +34 -0
- data/lib/waw/validation/regexp_validator.rb +29 -0
- data/lib/waw/validation/same_validator.rb +16 -0
- data/lib/waw/validation/signature.rb +157 -0
- data/lib/waw/validation/size_validations.rb +44 -0
- data/lib/waw/validation/string_validator.rb +15 -0
- data/lib/waw/validation/validator.rb +48 -0
- data/lib/waw/wawgen.rb +2 -0
- data/lib/waw/wawgen/create.rb +166 -0
- data/lib/waw/wawgen/project.rb +25 -0
- data/lib/waw/wspec.rb +5 -0
- data/lib/waw/wspec/browser.rb +240 -0
- data/lib/waw/wspec/dsl.rb +201 -0
- data/lib/waw/wspec/html_analysis.rb +136 -0
- data/lib/waw/wspec/html_analysis/tag.rb +56 -0
- data/lib/waw/wspec/runner.rb +70 -0
- data/lib/waw/wspec/scenario.rb +35 -0
- data/lib/waw/wspec/suite.rb +54 -0
- data/test/bricks/error_handler/config/test.cfg +2 -0
- data/test/bricks/error_handler/logs/webapp.log +1411 -0
- data/test/bricks/error_handler/test/error_handler.wspec +16 -0
- data/test/bricks/error_handler/waw.deploy +1 -0
- data/test/bricks/error_handler/waw.routing +27 -0
- data/test/integration/waw_create_integration_test.rb +24 -0
- data/test/spec/assumptions_spec.rb +30 -0
- data/test/spec/controllers/action_controller_spec.rb +14 -0
- data/test/spec/controllers/static/waw_access_spec.rb +112 -0
- data/test/spec/environment_utils_spec.rb +15 -0
- data/test/spec/ext/core/hash_spec.rb +58 -0
- data/test/spec/fixtures.rb +41 -0
- data/test/spec/fixtures/action/config/default.cfg +2 -0
- data/test/spec/fixtures/action/lib/action_controller_test.rb +12 -0
- data/test/spec/fixtures/action/waw.deploy +1 -0
- data/test/spec/fixtures/action/waw.routing +6 -0
- data/test/spec/fixtures/empty/waw.deploy +0 -0
- data/test/spec/fixtures/empty/waw.routing +0 -0
- data/test/spec/fullstate/on_class_spec.rb +59 -0
- data/test/spec/fullstate/on_instance_spec.rb +59 -0
- data/test/spec/fullstate/session_spec.rb +43 -0
- data/test/spec/fullstate/variable_spec.rb +55 -0
- data/test/spec/resource_collection_spec.rb +50 -0
- data/test/spec/test_all.rb +9 -0
- data/test/spec/tools/mail/mail_agent_spec.rb +116 -0
- data/test/spec/tools/mail/mail_spec.rb +56 -0
- data/test/spec/tools/mail/mailbox_spec.rb +57 -0
- data/test/spec/tools/mail/template_spec.rb +47 -0
- data/test/spec/validation/array_validation_spec.rb +63 -0
- data/test/spec/validation/array_validator_spec.rb +17 -0
- data/test/spec/validation/date_validation_spec.rb +35 -0
- data/test/spec/validation/default_validation_spec.rb +37 -0
- data/test/spec/validation/disjuctive_validation_spec.rb +33 -0
- data/test/spec/validation/errors_spec.rb +37 -0
- data/test/spec/validation/file_validator_spec.rb +34 -0
- data/test/spec/validation/mail_validation_spec.rb +51 -0
- data/test/spec/validation/missing_validation_spec.rb +43 -0
- data/test/spec/validation/same_validation_spec.rb +24 -0
- data/test/spec/validation/signature_intuition_spec.rb +37 -0
- data/test/spec/validation/signature_spec.rb +164 -0
- data/test/spec/validation/validation_spec.rb +28 -0
- data/test/spec/wspec/html_analysis/tag_spec.rb +38 -0
- data/test/spec/wspec/html_analysis_spec.rb +170 -0
- data/test/unit/test_all.rb +8 -0
- data/test/unit/waw/app_test.rb +126 -0
- data/test/unit/waw/app_test/config/commons.cfg +2 -0
- data/test/unit/waw/app_test/config/devel.cfg +1 -0
- data/test/unit/waw/config_test.rb +54 -0
- data/test/unit/waw/controllers/action_controller_test.rb +76 -0
- data/test/unit/waw/controllers/action_test.rb +35 -0
- data/test/unit/waw/controllers/example_action_controller_test.rb +24 -0
- data/test/unit/waw/controllers/multiple_action_controller_test.rb +78 -0
- data/test/unit/waw/controllers/static/example/css/example.css +1 -0
- data/test/unit/waw/controllers/static/example/index.html +1 -0
- data/test/unit/waw/controllers/static/example/js/example.js +1 -0
- data/test/unit/waw/controllers/static/example/pages/hello.wtpl +1 -0
- data/test/unit/waw/controllers/static/waw_access_test.rb +76 -0
- data/test/unit/waw/ext/rack_test.rb +74 -0
- data/test/unit/waw/resource_collection_test.rb +49 -0
- data/test/unit/waw/resources.txt +4 -0
- data/test/unit/waw/routing/routing_test.rb +26 -0
- data/test/unit/waw/utils/dsl_helper_test.rb +79 -0
- data/test/unit/waw/utils/dsl_helper_test_extensions1.rb +4 -0
- data/test/unit/waw/validation/signature_test.rb +193 -0
- data/test/unit/waw/validation_test.rb +319 -0
- data/test/unit/waw/wspec/html_analysis_test.html +81 -0
- data/test/unit/waw/wspec/html_analysis_test.rb +26 -0
- metadata +272 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'waw'
|
|
3
|
+
module Waw
|
|
4
|
+
module Controllers
|
|
5
|
+
class ActionController < ::Waw::Controller
|
|
6
|
+
class ActionTest < Test::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
class A < ::Waw::ActionController
|
|
9
|
+
|
|
10
|
+
signature{}
|
|
11
|
+
def hello(params)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.url
|
|
15
|
+
"/services"
|
|
16
|
+
end
|
|
17
|
+
def url
|
|
18
|
+
"/services"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_id
|
|
24
|
+
assert_equal "services_hello", A.hello.id
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_href
|
|
28
|
+
assert_equal "/services/hello", A.hello.href
|
|
29
|
+
assert_equal "/services/hello?who=blambeau", A.hello.href(:who => 'blambeau')
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'waw'
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
module Waw
|
|
4
|
+
module Controllers
|
|
5
|
+
class ExampleActionControllerTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
class A < ::Waw::ActionController
|
|
8
|
+
|
|
9
|
+
signature {}
|
|
10
|
+
def say_hello(params)
|
|
11
|
+
:ok
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_show_what_happened
|
|
17
|
+
assert A.respond_to?(:say_hello)
|
|
18
|
+
assert ::Waw::ActionController::Action === A.say_hello
|
|
19
|
+
assert_equal [:success, :ok], A.instance.say_hello({})
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'waw'
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
module Waw
|
|
4
|
+
module Controllers
|
|
5
|
+
class MultipleActionControllerTest < Test::Unit::TestCase
|
|
6
|
+
class A < ::Waw::ActionController
|
|
7
|
+
signature {}
|
|
8
|
+
def action_1(params)
|
|
9
|
+
"A.action_1"
|
|
10
|
+
end
|
|
11
|
+
signature {}
|
|
12
|
+
def action_2(params)
|
|
13
|
+
"A.action_2"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
class B < ::Waw::ActionController
|
|
17
|
+
signature {}
|
|
18
|
+
def action_1(params)
|
|
19
|
+
"B.action_1"
|
|
20
|
+
end
|
|
21
|
+
signature {}
|
|
22
|
+
def action_3(params)
|
|
23
|
+
"B.action_3"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_controllers
|
|
28
|
+
assert [A, B].all?{|c| ::Waw::ActionController.controllers.include?(c)}
|
|
29
|
+
assert A.controllers.object_id==::Waw::ActionController.controllers.object_id
|
|
30
|
+
assert B.controllers.object_id==::Waw::ActionController.controllers.object_id
|
|
31
|
+
assert A.controllers.object_id==B.controllers.object_id
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_actions
|
|
35
|
+
assert_equal 2, A.actions.size
|
|
36
|
+
assert_equal 2, B.actions.size
|
|
37
|
+
assert_equal [:action_1, :action_2], A.actions.keys.sort{|k1,k2| k1.to_s <=> k2.to_s}
|
|
38
|
+
assert_equal [:action_1, :action_3], B.actions.keys.sort{|k1,k2| k1.to_s <=> k2.to_s}
|
|
39
|
+
assert A.actions.object_id != B.actions.object_id
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_has_action?
|
|
43
|
+
assert A.has_action?(:action_1)
|
|
44
|
+
assert A.has_action?(:action_2)
|
|
45
|
+
assert !A.has_action?(:action_3)
|
|
46
|
+
assert B.has_action?(:action_1)
|
|
47
|
+
assert !B.has_action?(:action_2)
|
|
48
|
+
assert B.has_action?(:action_3)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_find_action
|
|
52
|
+
assert ::Waw::ActionController::Action===A.find_action(:action_1)
|
|
53
|
+
assert ::Waw::ActionController::Action===A.find_action(:action_2)
|
|
54
|
+
assert_nil A.find_action(:action_3)
|
|
55
|
+
assert ::Waw::ActionController::Action===B.find_action(:action_1)
|
|
56
|
+
assert ::Waw::ActionController::Action===B.find_action(:action_3)
|
|
57
|
+
assert_nil B.find_action(:action_2)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_find_action_on_instance
|
|
61
|
+
assert ::Waw::ActionController::Action===A.instance.find_action(:action_1)
|
|
62
|
+
assert ::Waw::ActionController::Action===A.instance.find_action(:action_2)
|
|
63
|
+
assert_nil A.instance.find_action(:action_3)
|
|
64
|
+
assert ::Waw::ActionController::Action===B.instance.find_action(:action_1)
|
|
65
|
+
assert ::Waw::ActionController::Action===B.instance.find_action(:action_3)
|
|
66
|
+
assert_nil B.instance.find_action(:action_2)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_action_execution
|
|
70
|
+
assert_equal [:success, "A.action_1"], A[:action_1].execute
|
|
71
|
+
assert_equal [:success, "A.action_2"], A[:action_2].execute
|
|
72
|
+
assert_equal [:success, "B.action_1"], B[:action_1].execute
|
|
73
|
+
assert_equal [:success, "B.action_3"], B[:action_3].execute
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* example.css */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* index.html */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* example.js */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Hello +{who}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'waw'
|
|
3
|
+
module Waw
|
|
4
|
+
class StaticController < ::Waw::Controller
|
|
5
|
+
# Waw version of .htaccess files
|
|
6
|
+
class WawAccessTest < Test::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
FIRST_WAW_ACCESS = <<-EOF
|
|
9
|
+
wawaccess do
|
|
10
|
+
strategy :allow_all
|
|
11
|
+
match '.wtpl' do
|
|
12
|
+
{:message => 'serving .wtpl'}
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
EOF
|
|
16
|
+
|
|
17
|
+
SECOND_WAW_ACCESS = <<-EOF
|
|
18
|
+
wawaccess do
|
|
19
|
+
match '.html' do
|
|
20
|
+
{:message => 'serving .html'}
|
|
21
|
+
end
|
|
22
|
+
match '.brick' do
|
|
23
|
+
{:message => 'serving .brick'}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
EOF
|
|
27
|
+
|
|
28
|
+
def test_dsl
|
|
29
|
+
first = WawAccess.new(nil, nil).dsl_merge(FIRST_WAW_ACCESS)
|
|
30
|
+
second = WawAccess.new(nil, nil).dsl_merge(SECOND_WAW_ACCESS)
|
|
31
|
+
|
|
32
|
+
first.folder = "/home"
|
|
33
|
+
second.folder = "/home/css"
|
|
34
|
+
second.parent = first
|
|
35
|
+
assert_nil first.parent
|
|
36
|
+
assert_equal "", first.identifier(false)
|
|
37
|
+
assert_equal ".wawaccess", first.identifier(true)
|
|
38
|
+
assert_equal "css/.wawaccess", second.identifier
|
|
39
|
+
assert_equal first, first.root
|
|
40
|
+
assert_equal first, second.root
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_find_wawaccess_for
|
|
44
|
+
wawaccess = WawAccess.load_hierarchy(File.join(File.dirname(__FILE__), 'example'))
|
|
45
|
+
assert_equal '.wawaccess', wawaccess.find_wawaccess_for('/').identifier
|
|
46
|
+
assert_equal '.wawaccess', wawaccess.find_wawaccess_for('/index.html').identifier
|
|
47
|
+
assert_equal '.wawaccess', wawaccess.find_wawaccess_for('/unexisting').identifier
|
|
48
|
+
assert_equal 'css/.wawaccess', wawaccess.find_wawaccess_for('/css').identifier
|
|
49
|
+
assert_equal 'css/.wawaccess', wawaccess.find_wawaccess_for('css').identifier
|
|
50
|
+
assert_equal 'css/.wawaccess', wawaccess.find_wawaccess_for('/css/example.css').identifier
|
|
51
|
+
assert_equal 'js/.wawaccess', wawaccess.find_wawaccess_for('/js/example.js').identifier
|
|
52
|
+
assert_equal 'pages/.wawaccess', wawaccess.find_wawaccess_for('/pages').identifier
|
|
53
|
+
assert_equal 'pages/.wawaccess', wawaccess.find_wawaccess_for('/pages/').identifier
|
|
54
|
+
assert_equal 'pages/.wawaccess', wawaccess.find_wawaccess_for('/pages/hello.wtpl').identifier
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def assert_successfull_serve(what, content=nil, msg = "#{what} is sucessfully served")
|
|
58
|
+
status, headers, value = what
|
|
59
|
+
value = value.join("\n") if Array===value
|
|
60
|
+
contenttype = headers['Content-Type']
|
|
61
|
+
assert_equal(200, status, msg)
|
|
62
|
+
assert_equal(content, value) if content
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_on_example
|
|
66
|
+
wawaccess = WawAccess.load_hierarchy(File.join(File.dirname(__FILE__), 'example'))
|
|
67
|
+
assert WawAccess===wawaccess
|
|
68
|
+
# assert_successfull_serve wawaccess.do_path_serve('/css/example.css'), "/* example.css */"
|
|
69
|
+
assert_successfull_serve wawaccess.do_path_serve('/'), "Hello blambeau"
|
|
70
|
+
# assert_successfull_serve wawaccess.do_path_serve('/hello.wtpl'), "Hello blambeau"
|
|
71
|
+
# assert_successfull_serve wawaccess.do_path_serve('/pages/hello.wtpl'), "Hello blambeau"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require 'waw'
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
module Waw
|
|
4
|
+
class RackExtensionTest < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
class AnApp
|
|
7
|
+
include Rack::Delegator
|
|
8
|
+
def initialize(name)
|
|
9
|
+
@name = name
|
|
10
|
+
end
|
|
11
|
+
def to_s
|
|
12
|
+
"#{self.class}('#{@name}')"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Creates a typical rack application under @app
|
|
17
|
+
def setup
|
|
18
|
+
@app1 = AnApp.new('/')
|
|
19
|
+
@app2 = AnApp.new('/webserv/event')
|
|
20
|
+
@app3 = AnApp.new('/webserv/people')
|
|
21
|
+
@urlmap2 = ::Rack::URLMap.new(
|
|
22
|
+
'/event' => @app2,
|
|
23
|
+
'/people' => @app3
|
|
24
|
+
)
|
|
25
|
+
@json = ::Waw::JSONController.new(@urlmap2)
|
|
26
|
+
@urlmap1 = ::Rack::URLMap.new(
|
|
27
|
+
'/' => @app1,
|
|
28
|
+
'/webserv' => @json
|
|
29
|
+
)
|
|
30
|
+
@session = ::Rack::Session::Pool.new(@urlmap1, :domain => "www.waw.org", :expire_after => 65)
|
|
31
|
+
@logger = ::Rack::CommonLogger.new(@session, STDOUT)
|
|
32
|
+
@restart = ::Waw::Restart.new(@logger)
|
|
33
|
+
@app = ::Waw::Kern::App.new
|
|
34
|
+
@app.app = @restart
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_find_rack_app
|
|
38
|
+
app = @app
|
|
39
|
+
assert_equal @app1, app.find_rack_app('/')
|
|
40
|
+
assert_equal @app1, app.find_rack_app('/'){|theapp| AnApp===theapp}
|
|
41
|
+
assert ::Waw::JSONController===app.find_rack_app('/webserv')
|
|
42
|
+
assert_equal @app2, app.find_rack_app('/webserv/event'){|theapp| AnApp===theapp}
|
|
43
|
+
assert_equal @app2, app.find_rack_app('/webserv/event/and_an_action_name'){|theapp| AnApp===theapp}
|
|
44
|
+
assert_equal @app3, app.find_rack_app('/webserv/people'){|theapp| AnApp===theapp}
|
|
45
|
+
assert_equal @app3, app.find_rack_app('/webserv/people/and_an_action_name'){|theapp| AnApp===theapp}
|
|
46
|
+
assert_equal @logger, app.find_rack_app{|theapp| ::Rack::CommonLogger===theapp}
|
|
47
|
+
assert_equal @json, app.find_rack_app{|theapp| ::Waw::JSONController===theapp}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_find_url_of
|
|
51
|
+
assert_equal '/', @app.find_url_of(@app)
|
|
52
|
+
[@logger, @session, @urlmap1, @app1].each {|app| assert_equal '/', @app.find_url_of(app)}
|
|
53
|
+
[@json, @urlmap2].each{|app| assert_equal '/webserv', @app.find_url_of(app)}
|
|
54
|
+
[@app2].each{|app| assert_equal '/webserv/event', @app.find_url_of(app)}
|
|
55
|
+
[@app3].each{|app| assert_equal '/webserv/people', @app.find_url_of(app)}
|
|
56
|
+
assert_equal nil, @app.find_url_of(self)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_visit
|
|
60
|
+
paths = Hash.new{|h,k| h[k] = []}
|
|
61
|
+
@app.visit{|path, app|
|
|
62
|
+
paths[path] << app
|
|
63
|
+
}
|
|
64
|
+
expected = {
|
|
65
|
+
'/' => [@app, @restart, @logger, @session, @urlmap1, @app1],
|
|
66
|
+
'/webserv' => [@json, @urlmap2],
|
|
67
|
+
'/webserv/event' => [@app2],
|
|
68
|
+
'/webserv/people' => [@app3]
|
|
69
|
+
}
|
|
70
|
+
assert_equal expected, paths
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'waw'
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
module Waw
|
|
4
|
+
class ResourceCollectionTest < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
class Trash
|
|
7
|
+
def self.write(*args) end
|
|
8
|
+
def self.close(*args) end
|
|
9
|
+
end
|
|
10
|
+
def setup
|
|
11
|
+
Waw.logger = Logger.new(Trash)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_resources_on_string
|
|
15
|
+
r = ResourceCollection.parse_resources <<-EOF
|
|
16
|
+
first_one "Hello world"
|
|
17
|
+
second_one 2
|
|
18
|
+
third_one 2*33
|
|
19
|
+
EOF
|
|
20
|
+
assert r.has_resource?(:first_one)
|
|
21
|
+
assert_equal "Hello world", r.first_one
|
|
22
|
+
assert_equal "Hello world", r[:first_one]
|
|
23
|
+
assert_equal 2, r.second_one
|
|
24
|
+
assert_equal 66, r.third_one
|
|
25
|
+
assert !r.has_resource?(:missing)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_resources_on_file
|
|
29
|
+
r = ResourceCollection.parse_resource_file(File.join(File.dirname(__FILE__), 'resources.txt'))
|
|
30
|
+
assert r.has_resource?(:first_one)
|
|
31
|
+
assert_equal "Hello world", r.first_one
|
|
32
|
+
assert_equal "Hello world", r[:first_one]
|
|
33
|
+
assert_equal 2, r.second_one
|
|
34
|
+
assert_equal 66, r.third_one
|
|
35
|
+
assert !r.has_resource?(:missing)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_on_missing_resources
|
|
39
|
+
r = ResourceCollection.parse_resources <<-EOF
|
|
40
|
+
first_one "Hello world"
|
|
41
|
+
second_one 2
|
|
42
|
+
third_one 2*33
|
|
43
|
+
EOF
|
|
44
|
+
assert_equal nil, r.hello
|
|
45
|
+
assert_equal "world", r.hello("world")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'waw'
|
|
3
|
+
module Waw
|
|
4
|
+
class RoutingTest < Test::Unit::TestCase
|
|
5
|
+
include Waw::Routing::Methods
|
|
6
|
+
|
|
7
|
+
def test_installation_on_routing_itself
|
|
8
|
+
result = ["success", "ok"]
|
|
9
|
+
assert Routing.matches?("success/ok", result)
|
|
10
|
+
assert Routing.matches?("success/*", result)
|
|
11
|
+
result = ["success", ["ok"]]
|
|
12
|
+
assert Routing.matches?("success/ok", result)
|
|
13
|
+
assert Routing.matches?("success/*", result)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_matches
|
|
17
|
+
result = ["success", "ok"]
|
|
18
|
+
assert matches?("success/ok", result)
|
|
19
|
+
assert matches?("success/*", result)
|
|
20
|
+
result = ["success", ["ok"]]
|
|
21
|
+
assert matches?("success/ok", result)
|
|
22
|
+
assert matches?("success/*", result)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'waw/utils/dsl_helper'
|
|
3
|
+
|
|
4
|
+
# Tests the DSLHelper class
|
|
5
|
+
class DSLHelperTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
# Ensures an expanded path on a test-relative file
|
|
8
|
+
def relative(file)
|
|
9
|
+
File.join(File.dirname(__FILE__), file)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Tests some test hypotheses
|
|
13
|
+
def test_hypotheses
|
|
14
|
+
assert_equal true, String.method_defined?(:upcase)
|
|
15
|
+
assert_equal false, String.method_defined?(:a_method_that_doesnt_exists)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Tests DSLHelper.is_intrusive?
|
|
19
|
+
def test_is_intrusive?
|
|
20
|
+
assert_equal true, DSLHelper.is_intrusive?(String => [:upcase])
|
|
21
|
+
assert_equal true, DSLHelper.is_intrusive?(String => [:upcase, :a_method_that_doesnt_exists])
|
|
22
|
+
assert_equal false, DSLHelper.is_intrusive?(String => [:a_method_that_doesnt_exists])
|
|
23
|
+
assert_equal true, DSLHelper.is_intrusive?(String => [:upcase], DSLHelperTest => [:test_hypotheses])
|
|
24
|
+
assert_equal true, DSLHelper.is_intrusive?(String => [:a_method_that_doesnt_exists], DSLHelperTest => [:test_hypotheses])
|
|
25
|
+
assert_equal false, DSLHelper.is_intrusive?(String => [:a_method_that_doesnt_exists], DSLHelperTest => [:a_method_that_doesnt_exists])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Tests DSLHelper.find_instance_method
|
|
29
|
+
def test_find_instance_method
|
|
30
|
+
assert_not_nil DSLHelper.find_instance_method(String, :upcase)
|
|
31
|
+
assert_nil DSLHelper.find_instance_method(String, :a_method_that_doesnt_exists)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Tests dry usage of the class
|
|
35
|
+
def test_dry_usage
|
|
36
|
+
DSLHelper.new(String => [:upcase, :downcase]) do
|
|
37
|
+
Kernel.load relative('dsl_helper_test_extensions1.rb')
|
|
38
|
+
assert_equal "hello", "hello".upcase
|
|
39
|
+
assert_equal "HELLO", "HELLO".downcase
|
|
40
|
+
end
|
|
41
|
+
assert_equal "HELLO", "hello".upcase
|
|
42
|
+
assert_equal "hello", "HELLO".downcase
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Tests normal usage of the class
|
|
46
|
+
def test_normal_usage
|
|
47
|
+
helper = DSLHelper.new(String => [:upcase, :downcase])
|
|
48
|
+
2.times do
|
|
49
|
+
helper.save
|
|
50
|
+
Kernel.load relative('dsl_helper_test_extensions1.rb')
|
|
51
|
+
assert_equal "hello", "hello".upcase
|
|
52
|
+
assert_equal "HELLO", "HELLO".downcase
|
|
53
|
+
helper.restore
|
|
54
|
+
assert_equal "HELLO", "hello".upcase
|
|
55
|
+
assert_equal "hello", "HELLO".downcase
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Tests that bad usage leads to friendly errors
|
|
60
|
+
def test_it_handles_bad_usage_friendly
|
|
61
|
+
helper = DSLHelper.new(String => [:upcase, :downcase])
|
|
62
|
+
assert_nothing_raised do helper.save end
|
|
63
|
+
assert_raise RuntimeError do helper.save end
|
|
64
|
+
assert_nothing_raised do helper.restore end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Tests stability of usage errors
|
|
68
|
+
def test_it_is_stable_to_usage_errors
|
|
69
|
+
helper = DSLHelper.new(String => [:upcase, :downcase])
|
|
70
|
+
helper.save
|
|
71
|
+
Kernel.load relative('dsl_helper_test_extensions1.rb')
|
|
72
|
+
assert_equal "hello", "hello".upcase
|
|
73
|
+
assert_raise RuntimeError do helper.save end
|
|
74
|
+
assert_equal "hello", "hello".upcase
|
|
75
|
+
assert_nothing_raised do helper.restore end
|
|
76
|
+
assert_equal "HELLO", "hello".upcase
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|