class WatirSpec::Server::App
Public Instance Methods
response(path, data = nil)
click to toggle source
# File lib/watirspec/server/app.rb, line 4 def response(path, data = nil) case path when '/' respond(self.class.name) when '/post_to_me' respond("You posted the following content:\n#{data}") when '/plain_text' respond('This is text/plain', 'Content-Type' => 'text/plain') when %r{/set_cookie} body = "<html>C is for cookie, it's good enough for me</html>" respond(body, 'Content-Type' => 'text/html', 'Set-Cookie' => 'monster=1') when static_file? respond_to_file(path) else respond('') end end
Private Instance Methods
css_file?()
click to toggle source
# File lib/watirspec/server/app.rb, line 43 def css_file? proc { |path| static_file(path) && path.end_with?('.css') } end
file_binread(path)
click to toggle source
# File lib/watirspec/server/app.rb, line 79 def file_binread(path) File.binread(static_file(path)) end
file_read(path)
click to toggle source
# File lib/watirspec/server/app.rb, line 75 def file_read(path) File.read(static_file(path)) end
gif_file?()
click to toggle source
# File lib/watirspec/server/app.rb, line 55 def gif_file? proc { |path| static_file(path) && path.end_with?('.gif') } end
js_file?()
click to toggle source
# File lib/watirspec/server/app.rb, line 47 def js_file? proc { |path| static_file(path) && path.end_with?('.js') } end
png_file?()
click to toggle source
# File lib/watirspec/server/app.rb, line 51 def png_file? proc { |path| static_file(path) && path.end_with?('.png') } end
respond(body, headers = {}, status = '200 OK')
click to toggle source
# File lib/watirspec/server/app.rb, line 39 def respond(body, headers = {}, status = '200 OK') [status, headers, body] end
respond_to_file(path)
click to toggle source
# File lib/watirspec/server/app.rb, line 24 def respond_to_file(path) case path when css_file? respond(file_read(path), 'Content-Type' => 'text/css') when js_file? respond(file_read(path), 'Content-Type' => 'application/javascript') when png_file? respond(file_binread(path), 'Content-Type' => 'image/png') when gif_file? respond(file_read(path), 'Content-Type' => 'image/gif') else respond(file_read(path)) end end
static_file(path)
click to toggle source
# File lib/watirspec/server/app.rb, line 69 def static_file(path) static_files.find do |file| file.end_with?(path) end end
static_file?()
click to toggle source
# File lib/watirspec/server/app.rb, line 59 def static_file? proc { |path| static_file(path) } end
static_files()
click to toggle source
# File lib/watirspec/server/app.rb, line 63 def static_files WatirSpec.htmls.flat_map do |html| Dir["#{html}/**/*"] end end