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,15 +0,0 @@
1
- Feature: Parse HTTP requests
2
-
3
- As a web-developer
4
- I want to be able to parse HTTP requests
5
- To be able to respond accordingly
6
-
7
- Scenario: Parse HTTP request
8
- Given a HTTP request "GET /index.html HTTP/1.1\r\nUser-Agent: cucumber\r\n"
9
- And a parser
10
- When I feed the request to the parser
11
- Then the result "method" should be "GET"
12
- And the result "uri" should include "path" with "/index.html"
13
- And the result "version" should be "HTTP/1.1"
14
- And the result "headers" should have "User-Agent" with "cucumber"
15
-
@@ -1,15 +0,0 @@
1
- Feature: Implement rack interface
2
-
3
- As a developer
4
- I want to have a rack handler
5
- In order to serve rack applications
6
-
7
- Scenario: Serve a one-file rack application
8
- Given the rack test app is running
9
- When I go to "/"
10
- Then the response should contain "Rack works"
11
-
12
- Scenario: Serve a rails application
13
- Given the rails test app is running
14
- When I go to ""
15
- Then the response should contain "Yarn Test Blog"
@@ -1,14 +0,0 @@
1
- Feature: Server control
2
-
3
- As a developer
4
- I want to be able to start and stop
5
- So that I can serve files to the web
6
-
7
- Scenario: Start server
8
- When I start the server on port 3000
9
- Then I should see "Server started on port 3000"
10
-
11
- Scenario: Stop server
12
- Given the server is running
13
- When I stop the server
14
- Then I should see "Server stopped"
@@ -1,25 +0,0 @@
1
- Feature: Static file requests
2
-
3
- As a web-developer
4
- I want to be able to serve static files
5
- To provide fast content on the Internet
6
-
7
- Background:
8
- Given the server is running
9
-
10
- Scenario: Serve a static html file
11
- Given the file "index.html" exist
12
- When I go to "/index.html"
13
- Then the response should contain "Success!"
14
-
15
- Scenario: Serve an javascript file
16
- Given the file "jquery.js" exist
17
- When I go to "/jquery.js"
18
- Then the response should contain "jQuery JavaScript Library"
19
- And the response should contain "})(window);"
20
-
21
- Scenario: Show an error message if a resource doesnt exist
22
- Given the file "non-existent-file.html" does not exist
23
- When I go to "non-existent-file.html"
24
- Then the response should contain "404"
25
- Then the response should contain "does not exist"
@@ -1,34 +0,0 @@
1
- Given /^a client "([^"]*)"$/ do |client|
2
- @clients = {}
3
- end
4
-
5
- When /^client "([^"]*)" makes a "([^"]*)" seconds? request$/ do |client,speed|
6
- @responses = {}
7
- filename = "test_objects/#{speed}.rb"
8
- File.delete filename if File.exists? filename
9
- File.open(filename, 'w') { |f| f.write "sleep(#{speed}); p 'complete: #{speed}s'\n" }
10
-
11
- @clients[client] = Thread.new do
12
- result = get "/#{speed}.rb"
13
- @responses[client] = result.body
14
- end
15
- end
16
-
17
- Then /^client "([^"]*)" receives a response before client "([^"]*)"$/ do |c1,c2|
18
- @success = false
19
- response_listener = Thread.new do
20
- while !@success do
21
- if @responses[c1] =~ /complete/ && !@responses[c2]
22
- @success = true
23
- break
24
- elsif @responses[c2] =~ /complete/
25
- @success = false
26
- break
27
- end
28
- end
29
- end
30
-
31
- response_listener.join
32
-
33
- @success.should be_true
34
- end
@@ -1,23 +0,0 @@
1
- Given /^a parser$/ do
2
- @parser = Yarn::Parser.new
3
- end
4
-
5
- When /^I feed the request to the parser$/ do
6
- @result = @parser.run(@request)
7
- end
8
-
9
- Given /^a HTTP request "([^"]*)"$/ do |req|
10
- @request = req.gsub('\\r\\n') { "\r\n" }
11
- end
12
-
13
- Then /^the result "([^"]*)" should be "([^"]*)"$/ do |key, value|
14
- @result[key.to_sym].to_s.should == value
15
- end
16
-
17
- Then /^the result "([^"]*)" should include "([^"]*)" with "([^"]*)"$/ do |outer_key, inner_key, value|
18
- @result[outer_key.to_sym][inner_key.to_sym].to_s.should == value
19
- end
20
-
21
- Then /^the result "([^"]*)" should have "([^"]*)" with "([^"]*)"$/ do |outer_key, inner_key, value|
22
- @result[outer_key.to_sym][inner_key].to_s.should == value
23
- end
@@ -1,16 +0,0 @@
1
- require 'rack'
2
-
3
- Given /^I have a rack application "([^"]*)"$/ do |app|
4
- testfile_exists?(app).should be_true
5
- end
6
-
7
- Given /^the rack test app is running$/ do
8
- start_server(3000,"test_objects/config.ru")
9
- end
10
-
11
- Given /^the rails test app is running$/ do
12
- current_dir = Dir.pwd
13
- Dir.chdir("test_objects/rails_test")
14
- start_server(3000,"config.ru")
15
- Dir.chdir(current_dir)
16
- end
@@ -1,42 +0,0 @@
1
- include Helpers
2
-
3
- When /^I start the server on port (\d+)$/ do |port|
4
- start_server port
5
- end
6
-
7
- When /^I stop the server$/ do
8
- stop_server unless @server.nil?
9
- end
10
-
11
- Given /^the server is running$/ do
12
- start_server(3000)
13
- end
14
-
15
- Given /^the server is not running$/ do
16
- stop_server unless @server.nil?
17
- @server = nil
18
- end
19
-
20
- Given /^the file "([^"]*)" exist$/ do |file|
21
- testfile_exists?(file).should be_true
22
- end
23
-
24
- Given /^the file "([^"]*)" does not exist$/ do |file|
25
- testfile_exists?(file).should be_false
26
- end
27
-
28
- When /^I log "([^"]*)"$/ do |message|
29
- @server.log message
30
- end
31
-
32
- When /^I debug "([^"]*)"$/ do |message|
33
- @server.debug message
34
- end
35
-
36
- Then /^I should see "([^"]*)"$/ do |message|
37
- $console.contains? message
38
- end
39
-
40
- Then /^Pry$/ do
41
- binding.pry
42
- end
@@ -1,15 +0,0 @@
1
- When /^(?:|I )go to "([^"]*)"$/ do |url|
2
- @response = get url
3
- end
4
-
5
- Then /^the response should contain "([^"]*)"$/ do |content|
6
- @response.body.should include(content)
7
- end
8
-
9
- Then /^the response should be "([^"]*)"$/ do |content|
10
- @response.body.gsub(/\n?/,"").should == content
11
- end
12
-
13
- When /^I post "([^"]*)" as "([^"]*)" to "([^"]*)"$/ do |key, value, url|
14
- @response = post(url, { key.to_sym => value })
15
- end
@@ -1,20 +0,0 @@
1
- $LOAD_PATH << File.expand_path('../../../lib', __FILE__)
2
- $LOAD_PATH << File.expand_path('../../../spec', __FILE__)
3
-
4
- require 'rubygems'
5
-
6
- require 'capybara'
7
- require 'capybara/dsl'
8
- require 'capybara/cucumber'
9
- require 'capybara-webkit'
10
-
11
- require 'yarn'
12
- require 'helpers'
13
-
14
- Capybara.javascript_driver = :webkit
15
- Capybara.default_driver = :webkit
16
-
17
- Capybara.run_server = false
18
- Capybara.app_host = "http://127.0.0.1:3000"
19
-
20
- Capybara.default_wait_time = 5
@@ -1,5 +0,0 @@
1
- include Helpers
2
-
3
- After do |scenario|
4
- stop_server
5
- end
@@ -1,92 +0,0 @@
1
- require 'uri'
2
- require 'faraday'
3
-
4
- module Helpers
5
- def send_data(data)
6
- socket = TCPSocket.new(@server.host, @server.port)
7
- socket.write data
8
- out = socket.read
9
- socket.close
10
- out
11
- end
12
-
13
- def get(url)
14
- setup
15
- if url == ""
16
- @connection.get "/"
17
- else
18
- @connection.get "test_objects#{url}"
19
- end
20
- end
21
-
22
- def post(url, data)
23
- setup
24
- @connection.post url, data
25
- end
26
-
27
- def stop_server
28
- @thread.kill if @thread
29
- @server.workers.each { |worker_id| Process.kill("INT", worker_id) } if @server and !@server.workers.empty?
30
- @server.stop if @server
31
- sleep 0.1 # enable socket to close before next test
32
- end
33
-
34
- def start_server(port=3000,rack="off")
35
- $console ||= MockIO.new
36
- @server = Yarn::Server.new({ port: port, output: $console, rack: rack, debug: true })
37
- @thread = Thread.new { @server.start }
38
- sleep 0.1 until @server.socket # wait for socket to be created
39
- end
40
-
41
-
42
- def testfile_exists?(filename)
43
- File.exists? File.join(File.join(File.dirname(__FILE__), "/../"), "test_objects/#{filename}")
44
- end
45
-
46
- def valid_html?(response)
47
- begin
48
- lambda { Nokogiri::HTML(response) { |config| config.strict } }
49
- rescue Nokogiri::HTML::SyntaxError
50
- false
51
- else
52
- true
53
- end
54
- end
55
- private
56
-
57
- def setup
58
- host = "127.0.0.1"
59
- port = "3000"
60
- uri = URI.parse("http://#{host}:#{port}")
61
- @connection = Faraday.new(uri)
62
- end
63
- end
64
-
65
- class MockIO
66
- def initialize(content="")
67
- @contents ||= []
68
- @contents << content
69
- end
70
-
71
- def puts(string)
72
- @contents << string
73
- end
74
-
75
- def gets
76
- @contents.last
77
- end
78
-
79
- def contains?(string)
80
- @contents.each do |line|
81
- if line.include? string
82
- return true
83
- end
84
- end
85
- false
86
- end
87
-
88
- def include?(string)
89
- contains?(string)
90
- end
91
- end
92
-
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Rack
4
- module Handler
5
-
6
- include Helpers
7
-
8
- # describe Yarn do
9
- # after do
10
- # @thread.kill
11
- # end
12
-
13
- # it "should start the server" do
14
- # @thread = Thread.new { Yarn.run("test_objects/config.ru") }
15
- # response = get("/").body
16
- # response.gsub(/\n?/,"").should == "Rack works"
17
- # end
18
- # end
19
- end
20
- end
21
-
@@ -1,17 +0,0 @@
1
- $LOAD_PATH << File.expand_path('../../../lib', __FILE__)
2
-
3
- require 'rubygems'
4
- require 'bundler/setup'
5
- require 'simplecov'
6
-
7
- SimpleCov.start do
8
- add_filter "/spec/"
9
- add_filter "lib/rack/handler/"
10
- end
11
-
12
- require 'yarn'
13
- require 'helpers'
14
-
15
- RSpec.configure do |config|
16
- config.include Helpers
17
- end
@@ -1,98 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Yarn
4
- describe AbstractHandler do
5
- describe "Common behaviour" do
6
-
7
- before(:each) do
8
- @dummy_request = "GET /resource/1 HTTP/1.1\r\n "
9
-
10
- @session = mock('TCPSocket')
11
- @session.stub(:gets)
12
- @session.stub(:close)
13
-
14
- @handler = AbstractHandler.new
15
- @handler.session = @session
16
- @handler.stub(:read_request).and_return(@dummy_request)
17
- end
18
-
19
- describe "#read_request" do
20
- it "should return a string from a feed" do
21
- @handler.unstub!(:read_request)
22
- @handler.session = StringIO.new
23
- @handler.session.string = "line1\nline2\nline3"
24
-
25
- @handler.read_request.should == "line1\nline2\nline3"
26
- end
27
-
28
- it "should handle POST body" do
29
- @req = "POST /app HTTP/1.1\nCookie: $key=value;\nContent-Length: 17;\n\r\nfield1=1&field2=2"
30
- @handler.unstub!(:read_request)
31
- @handler.session = StringIO.new
32
- @handler.session.string = @req
33
-
34
- @handler.read_request.should == @req
35
- end
36
- end
37
-
38
- describe "#parse_request" do
39
- it "should invoke the Parser" do
40
- @handler.parser.should_receive(:run)
41
-
42
- @handler.parse_request
43
- end
44
-
45
- it "should set the bad-request header if parsing fails" do
46
- bad_request = "BAD Warble warble request"
47
- @handler.response.status.should be_nil
48
-
49
- @session.stub(:gets).and_return(bad_request)
50
- @handler.parse_request
51
-
52
- @handler.response.status.should == 400
53
- end
54
- end
55
-
56
- describe "#return_response" do
57
- it "should write the response to the socket" do
58
- @handler.session.should_receive(:puts).at_least(1).times
59
- @handler.stub(:response).and_return("HTTP/1.1 201 OK")
60
- @handler.return_response
61
- end
62
- end
63
-
64
- describe "#persistent?" do
65
- it "should return true if the Connection header is set to keep-alive" do
66
- @handler.request = { headers: { "Connection" => "keep-alive" } }
67
-
68
- @handler.persistent?.should be_true
69
- end
70
-
71
- it "should return false if the Connection header is set to close" do
72
- @handler.request = { headers: { "Connection" => "close" } }
73
-
74
- @handler.persistent?.should be_false
75
- end
76
- end
77
-
78
- describe "#run" do
79
- it "should call all relevant template methods" do
80
- @handler.stub(:client_address)
81
- @handler.should_receive(:parse_request).once
82
- @handler.should_receive(:prepare_response).once
83
- @handler.should_receive(:return_response).once
84
-
85
- @handler.run(@session)
86
- end
87
- end
88
-
89
- describe "#client_address" do
90
- it "should return the clients address" do
91
- @handler.session.stub(:peeraddr).and_return([nil,nil,"some_host"])
92
-
93
- @handler.client_address.should == "some_host"
94
- end
95
- end
96
- end
97
- end
98
- end