btakita-screw-unit-server 0.3.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +44 -1
- data/README.markdown +17 -5
- data/Rakefile +28 -55
- data/VERSION.yml +5 -0
- data/bin/screw_unit_server +8 -4
- data/core/CHANGES +10 -0
- data/core/EXAMPLE.html +4 -4
- data/core/README.markdown +7 -7
- data/core/example/models/man.js +2 -2
- data/core/example/spec/suite.html +1 -1
- data/core/lib/jquery-1.3.2.js +4376 -0
- data/core/lib/jquery.fn.js +2 -1
- data/core/lib/jquery.print.js +13 -12
- data/core/lib/screw.behaviors.js +11 -9
- data/core/lib/screw.builder.js +26 -11
- data/core/lib/screw.css +2 -2
- data/core/lib/screw.events.js +11 -4
- data/core/lib/screw.matchers.js +192 -13
- data/core/spec/behaviors_spec.js +11 -1
- data/core/spec/matchers_spec.js +288 -9
- data/core/spec/print_spec.js +47 -8
- data/core/spec/suite.html +2 -1
- data/core/spec/with_screw_context_spec.js +9 -0
- data/lib/screw_unit.rb +12 -17
- data/spec/functional/functional_spec.rb +15 -4
- data/spec/functional/functional_spec_helper.rb +22 -35
- data/spec/functional/functional_spec_server_starter.rb +68 -0
- data/spec/spec_suite.rb +0 -1
- data/standalone.ru +3 -0
- data/vendor/js-test-core/CHANGES +22 -0
- data/vendor/js-test-core/README +4 -10
- data/vendor/js-test-core/Rakefile +2 -1
- data/vendor/js-test-core/{spec/example_core/JsTestCore.css → bin/js-test-client} +0 -0
- data/vendor/js-test-core/bin/js-test-server +6 -0
- data/vendor/js-test-core/lib/js_test_core.rb +27 -19
- data/vendor/js-test-core/lib/js_test_core/app.rb +11 -0
- data/vendor/js-test-core/lib/js_test_core/client.rb +125 -36
- data/vendor/js-test-core/lib/js_test_core/configuration.rb +65 -0
- data/vendor/js-test-core/lib/js_test_core/representations.rb +13 -0
- data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +25 -0
- data/vendor/js-test-core/lib/js_test_core/representations/frameworks.rb +3 -0
- data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +16 -0
- data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
- data/vendor/js-test-core/lib/js_test_core/representations/suite.html.rb +57 -0
- data/vendor/js-test-core/lib/js_test_core/representations/suites.rb +3 -0
- data/vendor/js-test-core/lib/js_test_core/representations/suites/screw_unit.html.rb +81 -0
- data/vendor/js-test-core/lib/js_test_core/resources.rb +12 -8
- data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
- data/vendor/js-test-core/lib/js_test_core/resources/file.rb +43 -13
- data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
- data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +28 -0
- data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
- data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +51 -0
- data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +7 -54
- data/vendor/js-test-core/lib/js_test_core/server.rb +65 -92
- data/vendor/js-test-core/public/js_test_server.js +541 -0
- data/vendor/js-test-core/spec/{example_core/JsTestCore.js → example_framework/JsTestCore.css} +0 -0
- data/vendor/js-test-core/spec/{example_public/favicon.ico → example_framework/JsTestCore.js} +0 -0
- data/vendor/js-test-core/spec/{example_public/robots.txt → example_framework/subdir/SubDirFile.js} +0 -0
- data/vendor/js-test-core/spec/example_root/favicon.ico +0 -0
- data/vendor/js-test-core/spec/{example_public → example_root}/javascripts/foo.js +1 -1
- data/vendor/js-test-core/spec/example_root/javascripts/large_file.js +59 -0
- data/vendor/js-test-core/spec/example_root/javascripts/subdir/bar.js +1 -0
- data/vendor/js-test-core/spec/example_root/robots.txt +0 -0
- data/vendor/js-test-core/spec/{example_public → example_root}/stylesheets/example.css +0 -0
- data/vendor/js-test-core/spec/example_spec/custom_dir_and_suite/passing_spec.js +8 -0
- data/vendor/js-test-core/spec/example_spec/custom_suite.html +8 -0
- data/vendor/js-test-core/spec/example_spec/failing_spec.js +7 -0
- data/vendor/js-test-core/spec/example_spec/foo/failing_spec.js +8 -0
- data/vendor/js-test-core/spec/example_spec/foo/passing_spec.js +8 -0
- data/vendor/js-test-core/spec/example_spec/passing_spec.js +8 -0
- data/vendor/js-test-core/spec/functional/functional_spec.rb +25 -0
- data/vendor/js-test-core/spec/functional/functional_spec_helper.rb +42 -0
- data/vendor/js-test-core/spec/functional/functional_spec_server_starter.rb +77 -0
- data/vendor/js-test-core/spec/functional_suite.rb +10 -0
- data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
- data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
- data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +16 -0
- data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
- data/vendor/js-test-core/spec/spec_suite.rb +2 -1
- data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +153 -94
- data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +50 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +61 -68
- data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +149 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +14 -89
- data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +41 -106
- data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +19 -114
- data/vendor/js-test-core/standalone.ru +1 -0
- data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +77 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +5 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +142 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource/path.rb +24 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +276 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
- data/vendor/js-test-core/vendor/lucky-luciano/syntax_ideas.txt +34 -0
- metadata +145 -130
- data/core/TODO +0 -2
- data/core/lib/jquery-1.2.3.js +0 -3408
- data/core/lib/screw.assets.js +0 -36
- data/core/lib/screw.server.js +0 -21
- data/lib/screw_unit/resources.rb +0 -2
- data/lib/screw_unit/resources/spec.rb +0 -37
- data/spec/unit/js_test_core/specs/spec_dir_spec.rb +0 -43
- data/spec/unit/js_test_core/specs/spec_file_spec.rb +0 -43
- data/spec/unit/unit_spec_helper.rb +0 -120
- data/spec/unit_suite.rb +0 -10
- data/vendor/js-test-core/lib/js_test_core/rack.rb +0 -2
- data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +0 -5
- data/vendor/js-test-core/lib/js_test_core/rails_server.rb +0 -22
- data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +0 -52
- data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +0 -15
- data/vendor/js-test-core/lib/js_test_core/resources/runners.rb +0 -15
- data/vendor/js-test-core/lib/js_test_core/resources/runners/firefox_runner.rb +0 -75
- data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +0 -50
- data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +0 -17
- data/vendor/js-test-core/lib/js_test_core/resources/suite.rb +0 -24
- data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +0 -19
- data/vendor/js-test-core/lib/js_test_core/selenium.rb +0 -2
- data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +0 -5
- data/vendor/js-test-core/lib/js_test_core/thin.rb +0 -3
- data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +0 -9
- data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +0 -42
- data/vendor/js-test-core/spec/example_specs/failing_spec.js +0 -5
- data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +0 -6
- data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +0 -6
- data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +0 -45
- data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +0 -42
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +0 -26
- data/vendor/js-test-core/spec/unit/js_test_core/resources/runner_spec.rb +0 -24
- data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/firefox_runner_spec.rb +0 -197
- data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +0 -79
- data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +0 -42
- data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +0 -94
- data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +0 -44
- data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +0 -92
@@ -3,100 +3,25 @@ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
|
|
3
3
|
module JsTestCore
|
4
4
|
module Resources
|
5
5
|
describe WebRoot do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "when passed 'core'" do
|
19
|
-
it "returns a Dir representing the JsTestCore core directory" do
|
20
|
-
runner = web_root.locate('core')
|
21
|
-
runner.should == Resources::Dir.new(JsTestCore::Server.core_path, '/core')
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "when passed 'implementations'" do
|
26
|
-
it "returns a Dir representing the javascript implementations directory" do
|
27
|
-
runner = web_root.locate('implementations')
|
28
|
-
runner.should == Resources::Dir.new(JsTestCore::Server.implementation_root_path, '/implementations')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "when passed 'results'" do
|
33
|
-
it "returns a Suite" do
|
34
|
-
runner = web_root.locate('suites')
|
35
|
-
runner.should == Resources::Suite
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "when passed 'runners'" do
|
40
|
-
it "returns a Runner" do
|
41
|
-
runner = web_root.locate('runners')
|
42
|
-
runner.should be_instance_of(Resources::Runners)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "when passed a directory that is in the public_path" do
|
47
|
-
it "returns a Dir representing that directory" do
|
48
|
-
runner = web_root.locate('stylesheets')
|
49
|
-
runner.should == Resources::Dir.new("#{JsTestCore::Server.public_path}/stylesheets", '/stylesheets')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "when passed a file that is in the public_path" do
|
54
|
-
it "returns a File representing that file" do
|
55
|
-
runner = web_root.locate('robots.txt')
|
56
|
-
runner.should == Resources::File.new("#{JsTestCore::Server.public_path}/robots.txt", '/robots.txt')
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "when passed an invalid option" do
|
61
|
-
it "returns a 404 response" do
|
62
|
-
resource = web_root.locate('invalid')
|
63
|
-
|
64
|
-
end
|
6
|
+
macro("includes a link to the spec suite") do |relative_path|
|
7
|
+
it "includes a link to the spec suite" do
|
8
|
+
response = get(relative_path)
|
9
|
+
response.should be_http(
|
10
|
+
200,
|
11
|
+
{},
|
12
|
+
""
|
13
|
+
)
|
14
|
+
doc = Nokogiri::HTML(response.body)
|
15
|
+
doc.css("a[href='/specs']").should_not be_nil
|
65
16
|
end
|
66
17
|
end
|
67
18
|
|
68
|
-
describe "
|
69
|
-
|
70
|
-
attr_reader :request, :response
|
71
|
-
before do
|
72
|
-
@request = Rack::Request.new({'rack.input' => StringIO.new("")})
|
73
|
-
@response = Rack::Response.new
|
74
|
-
end
|
75
|
-
|
76
|
-
it "redirects to /specs" do
|
77
|
-
WebRoot.dispatch_specs
|
78
|
-
|
79
|
-
web_root.get(request, response)
|
80
|
-
response.should be_redirect
|
81
|
-
response.headers["Location"].should == "/specs"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "#locate /specs" do
|
86
|
-
it "dispatches to a Spec::SpecDir" do
|
87
|
-
WebRoot.dispatch_specs
|
88
|
-
|
89
|
-
resource = web_root.locate('specs')
|
90
|
-
resource.should == spec_dir('')
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
19
|
+
describe "GET " do
|
20
|
+
send("includes a link to the spec suite", "")
|
94
21
|
end
|
95
22
|
|
96
|
-
describe "
|
97
|
-
|
98
|
-
web_root.locate('specs').should be_instance_of(FileNotFound)
|
99
|
-
end
|
23
|
+
describe "GET /" do
|
24
|
+
send("includes a link to the spec suite", "/")
|
100
25
|
end
|
101
26
|
end
|
102
27
|
end
|
@@ -2,130 +2,65 @@ require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
|
|
2
2
|
|
3
3
|
module JsTestCore
|
4
4
|
describe Server do
|
5
|
-
|
6
|
-
|
7
|
-
before do
|
8
|
-
@result = ""
|
9
|
-
stub(EventMachine).send_data do |signature, data, data_length|
|
10
|
-
@result << data
|
11
|
-
end
|
12
|
-
stub(EventMachine).close_connection
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "HTTP GET" do
|
16
|
-
specify "'/core/JsTestCore.js', returns the contents of the file" do
|
17
|
-
response = get("/core/JsTestCore.js")
|
18
|
-
response.body.should == ::File.read("#{Server.core_path}/JsTestCore.js")
|
19
|
-
end
|
20
|
-
|
21
|
-
specify "'/stylesheets/example.css', returns the contents of the file" do
|
22
|
-
response = get("/stylesheets/example.css")
|
23
|
-
response.body.should == ::File.read("#{Server.public_path}/stylesheets/example.css")
|
24
|
-
end
|
25
|
-
|
26
|
-
specify "'/invalid/path', shows the full invalid path in the error message" do
|
27
|
-
lambda do
|
28
|
-
get("/invalid/path")
|
29
|
-
end.should raise_error(Exception, Regexp.new("/invalid/path"))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe ".run" do
|
34
|
-
attr_reader :server_instance
|
5
|
+
describe ".cli" do
|
6
|
+
attr_reader :server, :builder, :stdout, :rackup_path
|
35
7
|
before do
|
36
|
-
@
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
it "instantiates an instance of Server and starts a Rack Thin handler" do
|
41
|
-
host = DEFAULT_HOST
|
42
|
-
port = DEFAULT_PORT
|
8
|
+
@server = Server.new
|
9
|
+
@builder = "builder"
|
43
10
|
|
44
|
-
|
45
|
-
|
11
|
+
@stdout = StringIO.new
|
12
|
+
Server.const_set(:STDOUT, stdout)
|
46
13
|
|
47
|
-
|
14
|
+
@rackup_path = File.expand_path("#{File.dirname(__FILE__)}/../../../standalone.ru")
|
48
15
|
end
|
49
16
|
|
50
|
-
|
51
|
-
|
52
|
-
port = 80
|
53
|
-
|
54
|
-
mock(EventMachine).run.yields
|
55
|
-
mock(EventMachine).start_server(host, port, ::Thin::JsTestCoreConnection)
|
56
|
-
|
57
|
-
Server.run(spec_root_path, implementation_root_path, public_path, {:Host => host, :Port => port})
|
17
|
+
after do
|
18
|
+
Server.__send__(:remove_const, :STDOUT)
|
58
19
|
end
|
59
|
-
end
|
60
20
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
21
|
+
|
22
|
+
context "when the --framework-name and --framework-path are set" do
|
23
|
+
it "starts the server and sets SpecFile::suite_representation_class to be the ScrewUnit suite" do
|
24
|
+
project_spec_dir = File.expand_path("#{File.dirname(__FILE__)}/../..")
|
66
25
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
26
|
+
mock.proxy(Thin::Runner).new(["--port", "8081", "--rackup", rackup_path, "start"]) do |runner|
|
27
|
+
mock(runner).run!
|
28
|
+
end
|
72
29
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
30
|
+
stub.proxy(Rack::Builder).new do |builder|
|
31
|
+
mock.proxy(builder).use(JsTestCore::App)
|
32
|
+
stub.proxy(builder).use
|
33
|
+
mock(builder).run(is_a(JsTestCore::App))
|
34
|
+
mock(builder).run(is_a(Sinatra::Application))
|
35
|
+
end
|
78
36
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
37
|
+
server.cli(
|
38
|
+
"--framework-name", "screw-unit",
|
39
|
+
"--framework-path", "#{project_spec_dir}/example_framework",
|
40
|
+
"--root-path", "#{project_spec_dir}/example_root",
|
41
|
+
"--spec-path", "#{project_spec_dir}/example_spec",
|
42
|
+
"--port", "8081"
|
43
|
+
)
|
84
44
|
|
85
|
-
|
86
|
-
|
87
|
-
dir = ::File.dirname(__FILE__)
|
88
|
-
Server.implementation_root_path.should == implementation_root_path
|
45
|
+
JsTestCore::Configuration.instance.suite_representation_class.should == JsTestCore::Representations::Suites::ScrewUnit
|
46
|
+
end
|
89
47
|
end
|
90
|
-
end
|
91
48
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
stub.instance_of(Resources::WebRoot).locate('somedir') do
|
98
|
-
raise "Foobar"
|
99
|
-
end
|
100
|
-
end
|
49
|
+
context "when the --framework-name or --framework-path are not set" do
|
50
|
+
it "raises an ArgumentError" do
|
51
|
+
lambda do
|
52
|
+
server.cli
|
53
|
+
end.should raise_error(ArgumentError)
|
101
54
|
|
102
|
-
it "shows the full request path in the error message" do
|
103
55
|
lambda do
|
104
|
-
|
105
|
-
end.should raise_error(
|
106
|
-
end
|
56
|
+
server.cli("--framework-name", "screw-unit")
|
57
|
+
end.should raise_error(ArgumentError)
|
107
58
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
get('/somedir')
|
112
|
-
rescue Exception => e
|
113
|
-
no_error = false
|
114
|
-
top_of_backtrace = e.backtrace.first.split(":")
|
115
|
-
backtrace_file = ::File.expand_path(top_of_backtrace[0])
|
116
|
-
backtrace_line = Integer(top_of_backtrace[1])
|
117
|
-
backtrace_file.should == __FILE__
|
118
|
-
backtrace_line.should == top_line_of_backtrace
|
119
|
-
end
|
120
|
-
raise "There should have been an error" if no_error
|
59
|
+
lambda do
|
60
|
+
server.cli("--framework-path", "/path/to/framework")
|
61
|
+
end.should raise_error(ArgumentError)
|
121
62
|
end
|
122
63
|
end
|
123
64
|
end
|
124
|
-
|
125
|
-
describe "#root_url" do
|
126
|
-
it "returns the url of the site's root" do
|
127
|
-
server.root_url.should == "http://#{server.host}:#{server.port}"
|
128
|
-
end
|
129
|
-
end
|
130
65
|
end
|
131
66
|
end
|
@@ -1,125 +1,30 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "spec"
|
3
|
+
require "spec/autorun"
|
4
|
+
require "rack/test"
|
5
|
+
require "rr"
|
6
|
+
ARGV.push("-b")
|
3
7
|
|
4
8
|
dir = File.dirname(__FILE__)
|
5
|
-
|
9
|
+
LIBRARY_ROOT_DIR = File.expand_path("#{dir}/../..")
|
10
|
+
$LOAD_PATH.unshift File.expand_path("#{LIBRARY_ROOT_DIR}/lib")
|
6
11
|
require "js_test_core"
|
7
|
-
require "
|
12
|
+
require "nokogiri"
|
8
13
|
require "guid"
|
14
|
+
require "thin"
|
15
|
+
require "#{LIBRARY_ROOT_DIR}/spec/spec_helpers/be_http"
|
16
|
+
require "#{LIBRARY_ROOT_DIR}/spec/spec_helpers/example_group"
|
17
|
+
require "#{LIBRARY_ROOT_DIR}/spec/spec_helpers/fake_selenium_driver"
|
18
|
+
require "#{LIBRARY_ROOT_DIR}/spec/spec_helpers/show_test_exceptions"
|
9
19
|
|
10
20
|
Spec::Runner.configure do |config|
|
11
|
-
config.mock_with
|
21
|
+
config.mock_with RR::Adapters::Rspec
|
12
22
|
end
|
13
23
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
!@actual.nil?
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class Spec::Example::ExampleGroup
|
26
|
-
class << self
|
27
|
-
def thin_logging
|
28
|
-
@thin_logging = true if @thin_logging.nil?
|
29
|
-
@thin_logging
|
30
|
-
end
|
31
|
-
|
32
|
-
attr_writer :thin_logging
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class JsTestCoreTestDir < JsTestCore::Resources::Dir
|
37
|
-
def get(request, response)
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
module Spec::Example::ExampleMethods
|
43
|
-
attr_reader :core_path, :spec_root_path, :implementation_root_path, :public_path, :server, :connection
|
44
|
-
before(:all) do
|
45
|
-
dir = File.dirname(__FILE__)
|
46
|
-
@core_path = File.expand_path("#{dir}/../example_core")
|
47
|
-
JsTestCore.core_path = core_path
|
48
|
-
@spec_root_path = File.expand_path("#{dir}/../example_specs")
|
49
|
-
@implementation_root_path = File.expand_path("#{dir}/../example_public/javascripts")
|
50
|
-
@public_path = File.expand_path("#{dir}/../example_public")
|
51
|
-
end
|
52
|
-
|
53
|
-
before(:each) do
|
54
|
-
JsTestCore::Server.instance = JsTestCore::Server.new(spec_root_path, implementation_root_path, public_path)
|
55
|
-
stub(EventMachine).run do
|
56
|
-
raise "You need to mock calls to EventMachine.run or the process will hang"
|
57
|
-
end
|
58
|
-
stub(EventMachine).start_server do
|
59
|
-
raise "You need to mock calls to EventMachine.start_server or the process will hang"
|
60
|
-
end
|
61
|
-
stub(EventMachine).send_data do
|
62
|
-
raise "Calls to EventMachine.send_data must be mocked or stubbed"
|
63
|
-
end
|
64
|
-
@connection = Thin::JsTestCoreConnection.new(Guid.new)
|
65
|
-
stub(EventMachine).send_data {raise "EventMachine.send_data must be handled"}
|
66
|
-
stub(EventMachine).close_connection {raise "EventMachine.close_connection must be handled"}
|
67
|
-
@server = JsTestCore::Server.instance
|
68
|
-
Thin::Logging.silent = !self.class.thin_logging
|
69
|
-
Thin::Logging.debug = self.class.thin_logging
|
70
|
-
end
|
71
|
-
|
72
|
-
after(:each) do
|
73
|
-
JsTestCore::Resources::WebRoot.dispatch_strategy = nil
|
74
|
-
Thin::Logging.silent = true
|
75
|
-
Thin::Logging.debug = false
|
76
|
-
end
|
24
|
+
Sinatra::Application.use ShowTestExceptions
|
25
|
+
Sinatra::Application.set :raise_errors, true
|
26
|
+
Sinatra::Application.set :show_exceptions, false
|
27
|
+
JsTestCore::App.set :raise_errors, true
|
28
|
+
JsTestCore::App.set :show_exceptions, false
|
77
29
|
|
78
|
-
|
79
|
-
request(:get, url, params)
|
80
|
-
end
|
81
|
-
|
82
|
-
def post(url, params={})
|
83
|
-
request(:post, url, params)
|
84
|
-
end
|
85
|
-
|
86
|
-
def put(url, params={})
|
87
|
-
request(:put, url, params)
|
88
|
-
end
|
89
|
-
|
90
|
-
def delete(url, params={})
|
91
|
-
request(:delete, url, params)
|
92
|
-
end
|
93
|
-
|
94
|
-
def env_for(method, url, params)
|
95
|
-
Rack::MockRequest.env_for(url, params.merge({:method => method.to_s.upcase, 'js_test_core.connection' => connection}))
|
96
|
-
end
|
97
|
-
|
98
|
-
def create_request(method, url, params={})
|
99
|
-
env = env_for(method, url, params)
|
100
|
-
server.call(env)[2]
|
101
|
-
end
|
102
|
-
alias_method :request, :create_request
|
103
|
-
|
104
|
-
def spec_file(relative_path)
|
105
|
-
absolute_path = spec_root_path + relative_path
|
106
|
-
JsTestCore::Resources::File.new(absolute_path, "/specs#{relative_path}")
|
107
|
-
end
|
108
|
-
|
109
|
-
def spec_dir(relative_path="")
|
110
|
-
absolute_path = spec_root_path + relative_path
|
111
|
-
JsTestCore::Resources::Specs::SpecDir.new(absolute_path, "/specs#{relative_path}")
|
112
|
-
end
|
113
|
-
|
114
|
-
def contain_spec_file_with_correct_paths(path_relative_to_spec_root)
|
115
|
-
expected_absolute_path = spec_root_path + path_relative_to_spec_root
|
116
|
-
expected_relative_path = "/specs" + path_relative_to_spec_root
|
117
|
-
|
118
|
-
::Spec::Matchers::SimpleMatcher.new(expected_relative_path) do |globbed_files|
|
119
|
-
file = globbed_files.find do |file|
|
120
|
-
file.absolute_path == expected_absolute_path
|
121
|
-
end
|
122
|
-
file && file.relative_path == expected_relative_path
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
30
|
+
Sinatra::Application.use(JsTestCore::App)
|
@@ -0,0 +1 @@
|
|
1
|
+
JsTestCore::Server.instance.standalone_rackup(self)
|
@@ -0,0 +1,77 @@
|
|
1
|
+
Lucky Luciano, is a library that makes it easy to organize your Sinatra routes into Restful Resources.
|
2
|
+
|
3
|
+
You can define Resources with a base route, and then map relative routes in the Resource.
|
4
|
+
The base route and the relative route are simply merged to create the full route.
|
5
|
+
|
6
|
+
module Resource
|
7
|
+
class Users < LuckyLuciano::Resource
|
8
|
+
map "/users"
|
9
|
+
include UserAuthentication
|
10
|
+
|
11
|
+
get "/" do
|
12
|
+
end
|
13
|
+
|
14
|
+
get "/:user_id" do
|
15
|
+
end
|
16
|
+
|
17
|
+
post "/" do
|
18
|
+
end
|
19
|
+
|
20
|
+
put "/:user_id" do
|
21
|
+
require_login
|
22
|
+
# ...
|
23
|
+
end
|
24
|
+
|
25
|
+
delete "/:user_id" do
|
26
|
+
require_login
|
27
|
+
# ...
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class UserComments < LuckyLuciano::Resource
|
32
|
+
map "/users/:user_id/comments"
|
33
|
+
include UserAuthentication
|
34
|
+
|
35
|
+
get "/" do
|
36
|
+
end
|
37
|
+
|
38
|
+
get "/:comment_id" do
|
39
|
+
end
|
40
|
+
|
41
|
+
post "/" do
|
42
|
+
require_login
|
43
|
+
# ...
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
You can map the Resource to the Sinatra application by registering the route_handler.
|
50
|
+
|
51
|
+
class YourApp < Sinatra::Base
|
52
|
+
register(UsersResource.route_handler)
|
53
|
+
register(UserCommentsResource.route_handler)
|
54
|
+
end
|
55
|
+
|
56
|
+
Lucky Luciano also provides a named-route scheme, which is easy to search for in the code-base.
|
57
|
+
It is rather verbose and ideas are welcome to shorten it, while maintaining searchability and simplicity.
|
58
|
+
|
59
|
+
<a href="<%= Resource::Users.path("/:user_id", :user_id => @user.id, :additional_param => "param 1") %>">Bob</a>
|
60
|
+
a "Bob", :href => Resource::Users.path("/:user_id", :user_id => @user.id, :additional_param => "param 1")
|
61
|
+
|
62
|
+
<a href="<%= Resource::UserComments.path("/:comment_id", :user_id => @user.id, :comment_id => @comment.id, :additional_param => "param 1") %>">Bob's Comment</a>
|
63
|
+
a "Bob's Comment", :href => Resource::UserComments.path("/:comment_id", :user_id => @user.id, :comment_id => @comment.id, :additional_param => "param 1")
|
64
|
+
|
65
|
+
Compare with Rails named routes
|
66
|
+
|
67
|
+
<a href="<%= user_path(:user_id => @user, :additional_param => "param 1") %>">Bob</a>
|
68
|
+
a "Bob", :href => user_path(:user_id => @user, :additional_param => "param 1")
|
69
|
+
|
70
|
+
<a href="<%= user_comment_path(:user_id => @user.id, :comment_id => @comment.id, :additional_param => "param 1") %>">Bob's Comment</a>
|
71
|
+
a "Bob's Comment", :href => user_comment_path(@user, @comment)
|
72
|
+
|
73
|
+
## Who was this Lucky Luciano person?
|
74
|
+
|
75
|
+
Lucky Luciano was a mob boss and an alleged friend of Frank Sinatra.
|
76
|
+
|
77
|
+
http://news.bbc.co.uk/2/hi/special_report/1998/05/98/sinatra/94360.stm
|