yarn 0.1.0 → 0.1.1

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.
Files changed (87) hide show
  1. data/lib/rack/handler/yarn.rb +3 -7
  2. data/lib/yarn/abstract_handler.rb +19 -4
  3. data/lib/yarn/directory_lister.rb +3 -2
  4. data/lib/yarn/error_page.rb +3 -0
  5. data/lib/yarn/logging.rb +7 -0
  6. data/lib/yarn/parser.rb +3 -0
  7. data/lib/yarn/rack_handler.rb +4 -0
  8. data/lib/yarn/request_handler.rb +23 -13
  9. data/lib/yarn/response.rb +8 -1
  10. data/lib/yarn/server.rb +16 -3
  11. data/lib/yarn/statuses.rb +53 -52
  12. data/lib/yarn/version.rb +2 -1
  13. metadata +27 -108
  14. data/.autotest +0 -5
  15. data/.gitignore +0 -11
  16. data/.rspec +0 -2
  17. data/Gemfile +0 -7
  18. data/LICENCE +0 -22
  19. data/Rakefile +0 -4
  20. data/cucumber.yml +0 -3
  21. data/features/concurrency.feature +0 -13
  22. data/features/dynamic_request.feature +0 -18
  23. data/features/logger.feature +0 -16
  24. data/features/parser.feature +0 -15
  25. data/features/rack.feature +0 -15
  26. data/features/server.feature +0 -14
  27. data/features/static_request.feature +0 -25
  28. data/features/step_definitions/concurrency_steps.rb +0 -34
  29. data/features/step_definitions/parser_steps.rb +0 -23
  30. data/features/step_definitions/rack_steps.rb +0 -16
  31. data/features/step_definitions/server_steps.rb +0 -42
  32. data/features/step_definitions/web_steps.rb +0 -15
  33. data/features/support/env.rb +0 -20
  34. data/features/support/hooks.rb +0 -5
  35. data/spec/helpers.rb +0 -92
  36. data/spec/rack/handler/yarn_spec.rb +0 -21
  37. data/spec/spec_helper.rb +0 -17
  38. data/spec/yarn/abstract_handler_spec.rb +0 -98
  39. data/spec/yarn/directory_lister_spec.rb +0 -41
  40. data/spec/yarn/error_page_spec.rb +0 -33
  41. data/spec/yarn/logging_spec.rb +0 -53
  42. data/spec/yarn/parser_spec.rb +0 -122
  43. data/spec/yarn/rack_handler_spec.rb +0 -55
  44. data/spec/yarn/request_handler_spec.rb +0 -164
  45. data/spec/yarn/response_spec.rb +0 -36
  46. data/spec/yarn/server_spec.rb +0 -102
  47. data/test_objects/.gitignore +0 -10
  48. data/test_objects/config.ru +0 -6
  49. data/test_objects/index.html +0 -13
  50. data/test_objects/jquery.js +0 -8865
  51. data/test_objects/rails_test/.gitignore +0 -5
  52. data/test_objects/rails_test/Gemfile +0 -34
  53. data/test_objects/rails_test/README +0 -261
  54. data/test_objects/rails_test/Rakefile +0 -7
  55. data/test_objects/rails_test/app/assets/images/rails.png +0 -0
  56. data/test_objects/rails_test/app/assets/javascripts/application.js +0 -6
  57. data/test_objects/rails_test/app/assets/stylesheets/application.css +0 -7
  58. data/test_objects/rails_test/app/assets/stylesheets/scaffolds.css.scss +0 -56
  59. data/test_objects/rails_test/app/mailers/.gitkeep +0 -0
  60. data/test_objects/rails_test/app/models/.gitkeep +0 -0
  61. data/test_objects/rails_test/app/views/layouts/application.html.erb +0 -15
  62. data/test_objects/rails_test/app/views/posts/_form.html.erb +0 -25
  63. data/test_objects/rails_test/app/views/posts/edit.html.erb +0 -6
  64. data/test_objects/rails_test/app/views/posts/index.html.erb +0 -20
  65. data/test_objects/rails_test/app/views/posts/new.html.erb +0 -5
  66. data/test_objects/rails_test/app/views/posts/show.html.erb +0 -15
  67. data/test_objects/rails_test/config.ru +0 -4
  68. data/test_objects/rails_test/config/database.yml +0 -25
  69. data/test_objects/rails_test/config/locales/en.yml +0 -5
  70. data/test_objects/rails_test/doc/README_FOR_APP +0 -2
  71. data/test_objects/rails_test/lib/assets/.gitkeep +0 -0
  72. data/test_objects/rails_test/lib/tasks/.gitkeep +0 -0
  73. data/test_objects/rails_test/log/.gitkeep +0 -0
  74. data/test_objects/rails_test/public/404.html +0 -26
  75. data/test_objects/rails_test/public/422.html +0 -26
  76. data/test_objects/rails_test/public/500.html +0 -26
  77. data/test_objects/rails_test/public/favicon.ico +0 -0
  78. data/test_objects/rails_test/public/robots.txt +0 -5
  79. data/test_objects/rails_test/script/rails +0 -6
  80. data/test_objects/rails_test/test/fixtures/.gitkeep +0 -0
  81. data/test_objects/rails_test/test/fixtures/posts.yml +0 -9
  82. data/test_objects/rails_test/test/functional/.gitkeep +0 -0
  83. data/test_objects/rails_test/test/integration/.gitkeep +0 -0
  84. data/test_objects/rails_test/test/unit/.gitkeep +0 -0
  85. data/test_objects/rails_test/vendor/assets/stylesheets/.gitkeep +0 -0
  86. data/test_objects/rails_test/vendor/plugins/.gitkeep +0 -0
  87. data/yarn.gemspec +0 -29
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
- require 'nokogiri'
3
-
4
- module Yarn
5
-
6
- describe DirectoryLister do
7
-
8
- describe "#list" do
9
- it "returns valid HTML for a directory" do
10
- response = DirectoryLister.list("lib")
11
- response.should_not be_nil
12
- valid_html?(response).should be_true
13
- end
14
-
15
- it "returns valid HTML a long path" do
16
- response = DirectoryLister.list("lib/yarn")
17
- response.should_not be_nil
18
- valid_html?(response).should be_true
19
- end
20
- end
21
-
22
- describe "#format_size" do
23
- it "should format bytes into B" do
24
- DirectoryLister.format_size(1.0).should == "1.00B"
25
- end
26
- it "should format bytes into KB" do
27
- DirectoryLister.format_size(1024.0).should == "1.00KB"
28
- end
29
- it "should format bytes into MB" do
30
- DirectoryLister.format_size(1024**2).should == "1.00MB"
31
- end
32
- it "should format bytes into GB" do
33
- DirectoryLister.format_size(1024**3).should == "1.00GB"
34
- end
35
- it "should format bytes into TB" do
36
- DirectoryLister.format_size(1024.0**4).should == "1.00TB"
37
- end
38
- end
39
- end
40
-
41
- end
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Yarn
4
- describe ErrorPage do
5
- before(:each) do
6
- @handler = RequestHandler.new
7
- end
8
-
9
- describe "#serve_404_page" do
10
- it "should set the HTTP code" do
11
- @handler.serve_404_page
12
- @handler.response.status.should == 404
13
- end
14
-
15
- it "should set the body" do
16
- @handler.serve_404_page
17
- @handler.response.body.should_not be_empty
18
- end
19
- end
20
-
21
- describe "#serve_500_page" do
22
- it "should set the HTTP code" do
23
- @handler.serve_500_page
24
- @handler.response.status.should == 500
25
- end
26
-
27
- it "should set the body" do
28
- @handler.serve_500_page
29
- @handler.response.body.should_not be_empty
30
- end
31
- end
32
- end
33
- end
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Yarn
4
-
5
- class TestLoggging
6
- include Logging
7
- end
8
-
9
- describe Logging do
10
-
11
- describe "#log" do
12
- it "should make the logging methods available" do
13
- @server = Server.new(output: $output, debug: true)
14
- @server.should respond_to(:log)
15
- @server.should respond_to(:debug)
16
- @server.stop
17
- end
18
-
19
- it "should be available in the handler classes" do
20
- @handler = RequestHandler.new
21
-
22
- @handler.should respond_to(:log)
23
- @handler.should respond_to(:debug)
24
- end
25
-
26
- it "should send the message to output" do
27
- test_logger = TestLoggging.new
28
- test_logger.output.should_receive(:puts).once
29
-
30
- test_logger.log "testing"
31
- end
32
-
33
- it "should handles arrays" do
34
- test_logger = TestLoggging.new
35
- test_logger.output.should_receive(:puts).twice
36
-
37
- test_logger.log [1,2]
38
- end
39
-
40
- end
41
-
42
- describe "#debug" do
43
- it "should invoke the log method with a message" do
44
- $debug = true
45
- test_logger = TestLoggging.new
46
- test_logger.should_receive(:log).with("DEBUG: testing").once
47
-
48
- test_logger.debug "testing"
49
- end
50
- end
51
-
52
- end
53
- end
@@ -1,122 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Yarn
4
- describe Parser do
5
- before do
6
- @parser = Parser.new
7
- end
8
-
9
- describe "#parse request_line" do
10
- it "parses all request method types" do
11
- ['OPTIONS','GET','HEAD','POST','PUT','DELETE','TRACE','CONNECT'].each do |method|
12
- @parser.run(method + ' / HTTP/1.1')[:method].to_s.should == method
13
- end
14
- end
15
-
16
- it "parses no-resource URI" do
17
- @parser.run("GET * HTTP/1.1")[:uri].to_s.should == "*"
18
- end
19
-
20
- it "parses the host" do
21
- result = @parser.run("GET http://www.test.com/index.html HTTP/1.1")
22
- result[:uri][:host].to_s.should == "www.test.com"
23
- end
24
-
25
- it "parses the path" do
26
- result = @parser.run("GET http://www.test.com/index.html HTTP/1.1")
27
- result[:uri][:path].to_s.should == "/index.html"
28
- end
29
-
30
- it "parses absolute URI" do
31
- result = @parser.run("GET http://187.123.231.12:8976/some/resource HTTP/1.1")
32
- result[:uri][:host].should == "187.123.231.12"
33
- result[:uri][:port].should == "8976"
34
- result[:uri][:path].should == "/some/resource"
35
- end
36
-
37
- it "parses absolute paths" do
38
- result = @parser.run("GET /another/resource HTTP/1.1")
39
- result[:uri][:path].should == "/another/resource"
40
- end
41
-
42
- it "parses HTTP version" do
43
- result = @parser.run("GET /another/resource HTTP/1.1")
44
- result[:version].to_s.should == "HTTP/1.1"
45
- end
46
-
47
- it "parses crlf" do
48
- lambda { @parser.run("GET / HTTP/1.1\r\n") }.should_not raise_error
49
- lambda { @parser.run("GET / HTTP/1.1") }.should_not raise_error
50
- end
51
- end
52
-
53
- describe "#parse parameters" do
54
- it "parses query in the url" do
55
- result = @parser.run("GET /page?param1=1&param2=2 HTTP/1.1\n")
56
- result[:uri][:query].should == "param1=1&param2=2"
57
- end
58
-
59
- it "should parse query on rails assets" do
60
- result = @parser.run("GET assets/application.js?body=0 HTTP/1.1\n")
61
- result[:uri][:query].should == "body=0"
62
- result[:uri][:path].should == "assets/application.js"
63
- end
64
- end
65
-
66
- describe "#parse headers" do
67
- it "accepts a request with no headers" do
68
- result = @parser.run("GET /another/resource HTTP/1.1\r\n")
69
- result[:headers].should be_empty
70
- end
71
-
72
- it "parses a Content-Length header" do
73
- request = "POST /resource/1/save HTTP/1.1\r\nContent-Length: 345\r\n"
74
- result = @parser.run(request)
75
-
76
- result[:headers]["Content-Length"].should == "345"
77
- end
78
-
79
- it "parses a Cookie header" do
80
- cookie = "Cookie: $Version=1; Skin=new;"
81
- request = "POST /form HTTP/1.1\r\n#{cookie}\r\n"
82
- result = @parser.run(request)
83
- result[:headers]["Cookie"].should == "$Version=1; Skin=new;"
84
- end
85
-
86
- it "parses multiple headers" do
87
- cookie = "Cookie: $Version=1; Skin=new;"
88
- user_agent_value = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"
89
- user_agent = "User-Agent: #{user_agent_value}"
90
- request = "POST /form HTTP/1.1\r\n#{cookie}\r\n#{user_agent}"
91
- result = @parser.run(request)
92
-
93
- result[:headers].length.should == 2
94
- result[:headers]["User-Agent"].should == user_agent_value
95
- end
96
-
97
- it "parses an empty header" do
98
- lambda { @parser.run("GET / HTTP/1.1\r\nAccept: \r\n") }.should_not raise_error
99
- lambda { @parser.run("GET / HTTP/1.1\r\nAccept:") }.should_not raise_error
100
- end
101
- end
102
-
103
- describe "#parse POST body" do
104
- it "should parse POST body" do
105
- header = "Cookie: $Version=1; Skin=new;"
106
- body = "attr=test"
107
- request = "POST /form HTTP/1.1\r\n#{header}\r\n\r\n#{body}"
108
- result = @parser.run(request)
109
- result[:body].should == body
110
- end
111
-
112
- it "should parse POST body with added line ending" do
113
- header = "Cookie: $Version=1; Skin=new;"
114
- body = "attr=test&attr2=some_other_value&attr3=1231682368125361823"
115
- request = "POST /form HTTP/1.1\r\n#{header}\r\n\r\n#{body}"
116
- result = @parser.run(request)
117
- result[:body].should == body
118
- end
119
- end
120
-
121
- end
122
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Yarn
4
- describe RackHandler do
5
-
6
- before(:each) do
7
- @app = mock('app')
8
- @handler = RackHandler.new(@app, { host: "www.hostname.com", port: 8888 })
9
- @handler.request = @handler.parser.run "GET http://www.hostname.com:8888/some_controller/some_action?param1=1&param2=2 HTTP/1.1"
10
- end
11
-
12
- describe "#prepare_response" do
13
- it "should call make_env" do
14
- @app.stub(:call).and_return([200, {}, []])
15
- @handler.prepare_response
16
- @handler.env.should_not be_nil
17
- end
18
-
19
- it "should call the rack app" do
20
- @app.should_receive(:call)
21
- @handler.prepare_response
22
- end
23
- end
24
-
25
- describe "#make_env" do
26
- before(:each) do
27
- @env = @handler.make_env
28
- end
29
-
30
- it "should set the REQUEST_METHOD" do
31
- @env["REQUEST_METHOD"].should == "GET"
32
- end
33
-
34
- it "should set the SCRIPT_NAME" do
35
- @env["SCRIPT_NAME"].should == ""
36
- end
37
-
38
- it "should set the PATH_INFO" do
39
- @env["PATH_INFO"].should == "/some_controller/some_action"
40
- end
41
-
42
- it "should set the QUERY_STRING" do
43
- @env["QUERY_STRING"].should == "param1=1&param2=2"
44
- end
45
-
46
- it "should set the SERVER_NAME" do
47
- @env["SERVER_NAME"].should == "www.hostname.com"
48
- end
49
-
50
- it "should set the SERVER PORT" do
51
- @env["SERVER_PORT"].should == "8888"
52
- end
53
- end
54
- end
55
- end
@@ -1,164 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Yarn
4
- describe RequestHandler do
5
-
6
- describe "Static requests" do
7
-
8
- before(:each) do
9
- @handler = RequestHandler.new
10
- @handler.session = @session
11
-
12
- @file_content = "<html><body>success!</body></html>"
13
- @file = File.open("index.html", 'w') do |file|
14
- file.write @file_content
15
- end
16
- Dir.mkdir("testdir") unless Dir.exists?("testdir")
17
- end
18
-
19
- after(:each) do
20
- File.delete("index.html") if File.exists?("index.html")
21
- File.delete("testdir/index.html") if File.exists?("testdir/index.html")
22
- Dir.delete("testdir") if Dir.exists?("testdir")
23
- end
24
-
25
- describe "#prepare_response" do
26
- it "should handle a directory" do
27
- File.delete("index.html")
28
- @handler.stub(:extract_path).and_return("testdir")
29
- @handler.should_receive(:serve_directory).once
30
- @handler.prepare_response
31
- end
32
-
33
- it "returns a file if it exists" do
34
- @file = File.new("test.html", "w")
35
- @handler.stub(:extract_path).and_return("test.html")
36
- @handler.should_receive(:serve_file).once
37
- @handler.prepare_response
38
- File.delete("test.html")
39
- end
40
-
41
- it "handles missing files" do
42
- @handler.stub(:extract_path).and_return("non-existing.html")
43
- @handler.should_receive(:serve_404_page).once
44
- @handler.prepare_response
45
- end
46
- end
47
-
48
- describe "#serve_file" do
49
- it "should read an existing file" do
50
- @handler.should_receive(:read_file).once
51
- @handler.serve_file("index.html")
52
- end
53
- end
54
-
55
- describe "#serve_directory" do
56
- it "should read index file if it exists" do
57
- File.new("testdir/index.html", "w")
58
- @handler.should_receive(:read_file).once
59
- @handler.serve_directory("testdir")
60
- end
61
-
62
- it "should list a directory" do
63
- File.delete "index.html"
64
- DirectoryLister.should_receive(:list).once
65
- @handler.serve_directory(Dir.pwd)
66
- end
67
- end
68
-
69
- describe "#read_file" do
70
- it "should return the contents of a file" do
71
- @handler.response.body.should be_empty
72
- @handler.read_file("index.html").should == [@file_content]
73
- end
74
- end
75
-
76
- describe "#get_mime_type" do
77
- it "should return false if the filetype cannot be detected" do
78
- @handler.get_mime_type("dumbfile.asdf").should be_false
79
- end
80
-
81
- it "should detect plain text files" do
82
- @handler.get_mime_type("file.txt").should == "text/plain"
83
- end
84
-
85
- it "should return false if the path doent have an extension" do
86
- @handler.get_mime_type("asdfasdf").should be_false
87
- end
88
-
89
- it "should detect css files" do
90
- @handler.get_mime_type("stylesheet.css").should == "text/css"
91
- end
92
-
93
- it "should detect javascript files" do
94
- @handler.get_mime_type("jquery.js").should == "text/javascript"
95
- end
96
-
97
- it "should detect html files" do
98
- @handler.get_mime_type("index.html").should == "text/html"
99
- end
100
-
101
- it "should detect image files" do
102
- ["png", "jpg", "jpeg", "gif", "tiff"].each do |filetype|
103
- @handler.get_mime_type("image.#{filetype}").should == "image/#{filetype}"
104
- end
105
- end
106
-
107
- it "should detect application formats" do
108
- formats = ["zip","pdf","postscript","x-tar","x-dvi"]
109
- formats.each do |filetype|
110
- @handler.get_mime_type("file.#{filetype}").should == "application/#{filetype}"
111
- end
112
- end
113
- end
114
-
115
- describe "#extract_path" do
116
- it "should remove any leading /'s" do
117
- @handler.request = { :uri => { :path => "/asdf" } }
118
- @handler.extract_path.should == "asdf"
119
- end
120
-
121
- it "should replace %20 with space" do
122
- @handler.request = { :uri => { :path => "asdf%20sdf%20" } }
123
- @handler.extract_path.should == "asdf sdf"
124
- end
125
-
126
- it "should return / if the path is /" do
127
- @handler.request = { :uri => { :path => "/" } }
128
- @handler.extract_path.should == "/"
129
- end
130
- end
131
- end
132
-
133
- describe "Dynamic requests" do
134
- before(:each) do
135
- @file_content = "!#/bin/ruby\nputs 'Success!'"
136
- @file = File.open("app.rb", 'w') do |file|
137
- file.write @file_content
138
- end
139
- end
140
-
141
- after(:each) do
142
- File.delete "app.rb" if File.exists? "app.rb"
143
- end
144
-
145
- describe "#prepare_response" do
146
- it "should execute the contents of a ruby file if it exists" do
147
- handler = RequestHandler.new
148
- handler.stub(:extract_path).and_return("app.rb")
149
- handler.prepare_response
150
- handler.response.body.should include "Success!\n"
151
- end
152
-
153
- it "should should handle interpreter errors" do
154
- handler = RequestHandler.new
155
- File.open("app.rb", 'w') { |f| f.write "this resolves in an error" }
156
- handler.stub(:extract_path).and_return("app.rb")
157
- handler.prepare_response
158
- handler.response.status.should == 500
159
- end
160
-
161
- end
162
- end
163
- end
164
- end