screw-unit 0.3.3 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/CHANGES +10 -0
  2. data/Rakefile +27 -25
  3. data/VERSION.yml +4 -0
  4. data/bin/screw_unit_server +14 -4
  5. data/core/EXAMPLE.html +1 -1
  6. data/core/example/spec/suite.html +1 -1
  7. data/core/lib/jquery-1.3.2.js +4376 -0
  8. data/core/lib/jquery.fn.js +2 -1
  9. data/core/lib/screw.behaviors.js +8 -7
  10. data/core/lib/screw.builder.js +34 -19
  11. data/core/lib/screw.css +1 -1
  12. data/core/lib/screw.events.js +5 -5
  13. data/core/lib/screw.matchers.js +59 -2
  14. data/core/spec/suite.html +2 -1
  15. data/core/spec/with_screw_context_spec.js +9 -0
  16. data/lib/screw_unit.rb +13 -16
  17. data/lib/screw_unit/representations.rb +2 -0
  18. data/lib/screw_unit/{resources/spec.rb → representations/spec.html.rb} +55 -39
  19. data/spec/functional/functional_spec.rb +1 -1
  20. data/spec/functional/functional_spec_helper.rb +21 -33
  21. data/spec/functional/functional_spec_server_starter.rb +68 -0
  22. data/spec/unit/js_test_core/specs/spec_file_spec.rb +52 -18
  23. data/spec/unit/unit_spec_helper.rb +24 -91
  24. data/vendor/js-test-core/CHANGES +8 -0
  25. data/vendor/js-test-core/Rakefile +1 -0
  26. data/vendor/js-test-core/lib/js_test_core.rb +22 -14
  27. data/vendor/js-test-core/lib/js_test_core/app.rb +12 -0
  28. data/vendor/js-test-core/lib/js_test_core/client.rb +21 -9
  29. data/vendor/js-test-core/lib/js_test_core/configuration.rb +35 -0
  30. data/vendor/js-test-core/lib/js_test_core/extensions.rb +1 -1
  31. data/vendor/js-test-core/lib/js_test_core/extensions/selenium/client/driver.rb +7 -0
  32. data/vendor/js-test-core/lib/js_test_core/models.rb +8 -0
  33. data/vendor/js-test-core/lib/js_test_core/models/selenium_session.rb +80 -0
  34. data/vendor/js-test-core/lib/js_test_core/representations.rb +11 -0
  35. data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +24 -0
  36. data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +15 -0
  37. data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
  38. data/vendor/js-test-core/lib/js_test_core/representations/spec.html.rb +24 -0
  39. data/vendor/js-test-core/lib/js_test_core/resources.rb +13 -7
  40. data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
  41. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +42 -20
  42. data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
  43. data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +35 -0
  44. data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
  45. data/vendor/js-test-core/lib/js_test_core/resources/selenium_session.rb +104 -0
  46. data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +63 -0
  47. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +5 -60
  48. data/vendor/js-test-core/{vendor/thin-rest/README → spec/example_core/subdir/SubDirFile.js} +0 -0
  49. data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite/passing_spec.js +6 -0
  50. data/vendor/js-test-core/spec/example_specs/custom_suite.html +8 -0
  51. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +1 -1
  52. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +1 -1
  53. data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
  54. data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
  55. data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +27 -0
  56. data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
  57. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +35 -10
  58. data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +44 -0
  59. data/vendor/js-test-core/spec/unit/js_test_core/models/selenium_session_spec.rb +85 -0
  60. data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
  61. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +54 -63
  62. data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
  63. data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
  64. data/vendor/js-test-core/spec/unit/js_test_core/resources/selenium_session_spec.rb +362 -0
  65. data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +120 -0
  66. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +15 -19
  67. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +16 -149
  68. data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +7 -0
  69. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +4 -0
  70. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +135 -0
  71. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
  72. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
  73. data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +231 -0
  74. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
  75. data/vendor/js-test-core/vendor/{thin-rest → lucky-luciano}/spec/spec_suite.rb +1 -2
  76. metadata +134 -145
  77. data/core/lib/jquery-1.2.6.js +0 -3549
  78. data/lib/screw_unit/resources.rb +0 -2
  79. data/spec/unit/js_test_core/specs/spec_dir_spec.rb +0 -38
  80. data/vendor/js-test-core/lib/js_test_core/rack.rb +0 -2
  81. data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +0 -5
  82. data/vendor/js-test-core/lib/js_test_core/rails_server.rb +0 -22
  83. data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +0 -67
  84. data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +0 -11
  85. data/vendor/js-test-core/lib/js_test_core/resources/runner.rb +0 -107
  86. data/vendor/js-test-core/lib/js_test_core/resources/session.rb +0 -44
  87. data/vendor/js-test-core/lib/js_test_core/resources/session_finish.rb +0 -17
  88. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +0 -46
  89. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +0 -17
  90. data/vendor/js-test-core/lib/js_test_core/selenium.rb +0 -2
  91. data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +0 -5
  92. data/vendor/js-test-core/lib/js_test_core/server.rb +0 -50
  93. data/vendor/js-test-core/lib/js_test_core/thin.rb +0 -3
  94. data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +0 -9
  95. data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +0 -8
  96. data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +0 -45
  97. data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +0 -52
  98. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +0 -16
  99. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/runner_spec.rb +0 -303
  100. data/vendor/js-test-core/spec/unit/js_test_core/resources/session_finish_spec.rb +0 -79
  101. data/vendor/js-test-core/spec/unit/js_test_core/resources/session_spec.rb +0 -82
  102. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +0 -105
  103. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +0 -42
  104. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +0 -117
  105. data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +0 -6
  106. data/vendor/js-test-core/vendor/thin-rest/CHANGES +0 -2
  107. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest.rb +0 -9
  108. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/connection.rb +0 -116
  109. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions.rb +0 -3
  110. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions/object.rb +0 -21
  111. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource.rb +0 -108
  112. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource_invalid.rb +0 -4
  113. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/routing_error.rb +0 -5
  114. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/connection_spec.rb +0 -207
  115. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resource_spec.rb +0 -127
  116. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest_spec_helper.rb +0 -124
@@ -0,0 +1,12 @@
1
+ module JsTestCore
2
+ class App < Sinatra::Base
3
+ set :logging, true
4
+ register(JsTestCore::Resources::WebRoot.route_handler)
5
+ register(JsTestCore::Resources::SeleniumSession.route_handler)
6
+ register(JsTestCore::Resources::CoreFile.route_handler)
7
+ register(JsTestCore::Resources::SpecFile.route_handler)
8
+ register(JsTestCore::Resources::File.route_handler)
9
+ register(JsTestCore::Resources::ImplementationsDeprecation.route_handler)
10
+ register(JsTestCore::Resources::NotFound.route_handler)
11
+ end
12
+ end
@@ -37,6 +37,10 @@ module JsTestCore
37
37
  params[:spec_url] = spec_url
38
38
  end
39
39
 
40
+ o.on('-t', '--timeout=TIMEOUT', "The timeout limit of the test run") do |timeout|
41
+ params[:timeout] = Integer(timeout)
42
+ end
43
+
40
44
  o.on_tail
41
45
  end
42
46
  parser.order!(argv)
@@ -51,11 +55,11 @@ module JsTestCore
51
55
  end
52
56
 
53
57
  def run
54
- Net::HTTP.start(DEFAULT_HOST, DEFAULT_PORT) do |@http|
55
- start_runner
56
- wait_for_session_to_finish
58
+ if parameters[:timeout]
59
+ Timeout.timeout(parameters[:timeout]) {do_run}
60
+ else
61
+ do_run
57
62
  end
58
- report_result
59
63
  end
60
64
 
61
65
  def parts_from_query(query)
@@ -67,8 +71,16 @@ module JsTestCore
67
71
  end
68
72
 
69
73
  protected
74
+ def do_run
75
+ Net::HTTP.start(DEFAULT_HOST, DEFAULT_PORT) do |@http|
76
+ start_runner
77
+ wait_for_session_to_finish
78
+ end
79
+ report_result
80
+ end
81
+
70
82
  def start_runner
71
- @session_start_response = http.post('/runners', query_string)
83
+ @session_start_response = http.post(Resources::SeleniumSession.path, query_string)
72
84
  end
73
85
 
74
86
  def wait_for_session_to_finish
@@ -80,10 +92,10 @@ module JsTestCore
80
92
 
81
93
  def report_result
82
94
  case last_poll_status
83
- when Resources::Session::SUCCESSFUL_COMPLETION
95
+ when Resources::SeleniumSession::SUCCESSFUL_COMPLETION
84
96
  STDOUT.puts "SUCCESS"
85
97
  true
86
- when Resources::Session::FAILURE_COMPLETION
98
+ when Resources::SeleniumSession::FAILURE_COMPLETION
87
99
  STDOUT.puts "FAILURE"
88
100
  STDOUT.puts last_poll_reason
89
101
  false
@@ -93,11 +105,11 @@ module JsTestCore
93
105
  end
94
106
 
95
107
  def session_not_completed?
96
- last_poll_status.nil? || last_poll_status == Resources::Session::RUNNING
108
+ last_poll_status.nil? || last_poll_status == Resources::SeleniumSession::RUNNING
97
109
  end
98
110
 
99
111
  def poll
100
- @last_poll = http.get("/sessions/#{session_id}")
112
+ @last_poll = http.get(Resources::SeleniumSession.path("/:session_id", :session_id => session_id))
101
113
  ensure_session_exists!
102
114
  parts = parts_from_query(last_poll.body)
103
115
  @last_poll_status = parts['status']
@@ -0,0 +1,35 @@
1
+ module JsTestCore
2
+ class Configuration
3
+ class << self
4
+ attr_accessor :instance
5
+
6
+ def method_missing(method_name, *args, &block)
7
+ if Configuration.instance.respond_to?(method_name)
8
+ Configuration.instance.send(method_name, *args, &block)
9
+ else
10
+ super
11
+ end
12
+ end
13
+ end
14
+
15
+ attr_accessor :host, :port, :spec_root_path, :public_path, :core_path
16
+
17
+ def initialize(params={})
18
+ params = {
19
+ :spec_root_path => File.expand_path("./specs/javascripts"),
20
+ :public_path => File.expand_path("./public"),
21
+ :host => DEFAULT_HOST,
22
+ :port => DEFAULT_PORT,
23
+ }.merge(params)
24
+ @spec_root_path = ::File.expand_path(params[:spec_root_path])
25
+ @public_path = ::File.expand_path(params[:public_path])
26
+ @host = params[:host]
27
+ @port = params[:port]
28
+ @core_path = params[:core_path]
29
+ end
30
+
31
+ def root_url
32
+ "http://#{host}:#{port}"
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
- Dir["#{File.dirname(__FILE__)}/extensions/*.rb"].each do |file|
1
+ Dir["#{File.dirname(__FILE__)}/extensions/**/*.rb"].each do |file|
2
2
  require file
3
3
  end
@@ -0,0 +1,7 @@
1
+ module Selenium
2
+ module Client
3
+ Driver.class_eval do
4
+ attr_reader :session_id
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ dir = File.dirname(__FILE__)
2
+
3
+ module JsTestCore
4
+ module Models
5
+ end
6
+ end
7
+
8
+ require "#{dir}/models/selenium_session"
@@ -0,0 +1,80 @@
1
+ module JsTestCore
2
+ module Models
3
+ class SeleniumSession
4
+ class << self
5
+ def find(id)
6
+ instances[id.to_s]
7
+ end
8
+
9
+ def register(selenium_session)
10
+ instances[selenium_session.session_id] = selenium_session
11
+ end
12
+
13
+ protected
14
+ def instances
15
+ @instances ||= {}
16
+ end
17
+ end
18
+
19
+ attr_reader :spec_url, :selenium_browser_start_command, :selenium_host, :selenium_port, :http_address, :driver, :run_result
20
+
21
+ def initialize(params={})
22
+ @spec_url = params[:spec_url]
23
+ @selenium_browser_start_command = params[:selenium_browser_start_command]
24
+ @selenium_host = params[:selenium_host]
25
+ @selenium_port = params[:selenium_port]
26
+
27
+ memoized_parsed_spec_url = parsed_spec_url
28
+ @http_address = "#{memoized_parsed_spec_url.scheme}://#{memoized_parsed_spec_url.host}:#{memoized_parsed_spec_url.port}"
29
+
30
+ @driver = Selenium::Client::Driver.new(
31
+ selenium_host,
32
+ selenium_port,
33
+ selenium_browser_start_command,
34
+ http_address
35
+ )
36
+ end
37
+
38
+ def start
39
+ begin
40
+ driver.start
41
+ rescue Errno::ECONNREFUSED => e
42
+ raise Errno::ECONNREFUSED, "Cannot connect to Selenium Server at #{http_address}. To start the selenium server, run `selenium`."
43
+ end
44
+ self.class.register(self)
45
+ Thread.start do
46
+ driver.open("/")
47
+ driver.create_cookie("session_id=#{session_id}")
48
+ driver.open(parsed_spec_url.path)
49
+ end
50
+ end
51
+
52
+ def session_id
53
+ driver.session_id
54
+ end
55
+
56
+ def finish(run_result)
57
+ driver.stop
58
+ @run_result = run_result.to_s
59
+ end
60
+
61
+ def running?
62
+ driver.session_started?
63
+ end
64
+
65
+ def successful?
66
+ !running? && run_result.empty?
67
+ end
68
+
69
+ def failed?
70
+ !running? && !successful?
71
+ end
72
+
73
+ protected
74
+
75
+ def parsed_spec_url
76
+ URI.parse(spec_url)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,11 @@
1
+ dir = File.dirname(__FILE__)
2
+
3
+ module JsTestCore
4
+ module Representations
5
+ end
6
+ end
7
+
8
+ require "#{dir}/representations/page.html"
9
+ require "#{dir}/representations/not_found.html"
10
+ require "#{dir}/representations/spec.html"
11
+ require "#{dir}/representations/dir.html"
@@ -0,0 +1,24 @@
1
+ module JsTestCore
2
+ module Representations
3
+ class Dir < Page
4
+ needs :relative_path, :absolute_path
5
+ protected
6
+ def body_content
7
+ ul do
8
+ ::Dir.glob("#{absolute_path}/*").inject("") do |html, file|
9
+ li do
10
+ a(
11
+ ::File.basename(file),
12
+ :href => "#{relative_path}/#{::File.basename(file)}".gsub("//", "/")
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ def title_text
20
+ "Contents of #{relative_path}"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ module JsTestCore
2
+ module Representations
3
+ class NotFound < Page
4
+ needs :message
5
+ protected
6
+ def body_content
7
+ h1 message
8
+ end
9
+
10
+ def title_text
11
+ message
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ module JsTestCore
2
+ module Representations
3
+ class Page < Erector::Widget
4
+ def content(&block)
5
+ rawtext %Q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">}
6
+ html :xmlns => "http://www.w3.org/1999/xhtml", :"xml:lang" => "en" do
7
+ head do
8
+ meta :"http-equiv" => "Content-Type", :content => "text/html;charset=UTF-8"
9
+ title title_text
10
+ head_content
11
+ end
12
+ body do
13
+ body_content(&block)
14
+ end
15
+ end
16
+ end
17
+
18
+ protected
19
+ def head_content
20
+ end
21
+
22
+ def title_text
23
+ "Thin Rest"
24
+ end
25
+
26
+ def body_content(&block)
27
+ yield(self)
28
+ end
29
+
30
+ def path
31
+ helpers.rack_request.path_info
32
+ end
33
+
34
+ def script_elements
35
+ end
36
+
37
+ def link_elements
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ module JsTestCore
2
+ module Representations
3
+ class Spec < Page
4
+ needs :spec_files
5
+ protected
6
+ def title_text
7
+ "Js Test Core Suite"
8
+ end
9
+
10
+ def head_content
11
+ spec_script_elements
12
+ end
13
+
14
+ def spec_script_elements
15
+ spec_files.each do |file|
16
+ script :type => "text/javascript", :src => file
17
+ end
18
+ end
19
+
20
+ def body_content
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,10 +1,16 @@
1
1
  dir = File.dirname(__FILE__)
2
- require "#{dir}/resources/runner"
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ end
6
+ end
7
+
8
+ require "#{dir}/resources/resource"
9
+ require "#{dir}/resources/selenium_session"
3
10
  require "#{dir}/resources/file"
4
- require "#{dir}/resources/dir"
5
- require "#{dir}/resources/file_not_found"
6
- require "#{dir}/resources/specs/spec_file"
7
- require "#{dir}/resources/specs/spec_dir"
11
+ require "#{dir}/resources/spec_file"
12
+ require "#{dir}/resources/core_file"
8
13
  require "#{dir}/resources/web_root"
9
- require "#{dir}/resources/session"
10
- require "#{dir}/resources/session_finish"
14
+ require "#{dir}/resources/not_found"
15
+
16
+ require "#{dir}/resources/implementations_deprecation"
@@ -0,0 +1,19 @@
1
+ module JsTestCore
2
+ module Resources
3
+ class CoreFile < File
4
+ map "/core"
5
+
6
+ get "/?" do
7
+ do_get
8
+ end
9
+
10
+ get "*" do
11
+ do_get
12
+ end
13
+
14
+ def absolute_path
15
+ @absolute_path ||= ::File.expand_path("#{core_path}#{relative_path.gsub(%r{^/core}, "")}")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,11 @@
1
1
  module JsTestCore
2
2
  module Resources
3
- class File < ThinRest::Resource
3
+ class File < Resource
4
+ map "*"
5
+
4
6
  MIME_TYPES = {
7
+ '.html' => 'text/html',
8
+ '.htm' => 'text/html',
5
9
  '.js' => 'text/javascript',
6
10
  '.css' => 'text/css',
7
11
  '.png' => 'image/png',
@@ -10,30 +14,48 @@ module JsTestCore
10
14
  '.gif' => 'image/gif',
11
15
  }
12
16
 
13
- property :absolute_path, :relative_path
17
+ get "*" do
18
+ do_get
19
+ end
20
+
21
+ def relative_path
22
+ @relative_path ||= request.path_info
23
+ end
14
24
 
15
- def get
16
- extension = ::File.extname(absolute_path)
17
- content_type = MIME_TYPES[extension] || 'text/html'
25
+ def absolute_path
26
+ @absolute_path ||= ::File.expand_path("#{public_path}#{relative_path}")
27
+ end
28
+
29
+ protected
18
30
 
19
- connection.terminate_after_sending do
20
- connection.send_head(
21
- 200,
22
- 'Content-Type' => content_type,
23
- 'Last-Modified' => ::File.mtime(absolute_path).rfc822,
24
- 'Content-Length' => ::File.size(absolute_path)
25
- )
26
- ::File.open(absolute_path) do |file|
27
- while !file.eof?
28
- connection.send_data(file.read(1024))
29
- end
31
+ def do_get
32
+ if ::File.exists?(absolute_path)
33
+ if ::File.directory?(absolute_path)
34
+ render_dir
35
+ else
36
+ render_file
30
37
  end
38
+ else
39
+ pass
31
40
  end
41
+ end
32
42
 
33
- def ==(other)
34
- return false unless other.class == self.class
35
- absolute_path == other.absolute_path && relative_path == other.relative_path
36
- end
43
+ def render_dir
44
+ Representations::Dir.new(:relative_path => relative_path, :absolute_path => absolute_path).to_s
45
+ end
46
+
47
+ def render_file
48
+ extension = ::File.extname(absolute_path)
49
+ content_type = MIME_TYPES[extension] || 'text/html'
50
+ [
51
+ 200,
52
+ {
53
+ 'Content-Type' => content_type,
54
+ 'Last-Modified' => ::File.mtime(absolute_path).rfc822,
55
+ 'Content-Length' => ::File.size(absolute_path)
56
+ },
57
+ ::File.read(absolute_path)
58
+ ]
37
59
  end
38
60
  end
39
61
  end