Sha256: 024e03b9f0a78ae282f00442009267809832e97ac6ccda5bd22c54fccb69da17
Contents?: true
Size: 1.61 KB
Versions: 4
Compression:
Stored size: 1.61 KB
Contents
module JsTestCore module Resources class SpecFile < ::JsTestCore::Resources::File class << self def spec_representation_class @spec_representation_class ||= JsTestCore::Representations::Spec end attr_writer :spec_representation_class end map "/specs" get "/?" do do_get end get "*" do do_get end protected def do_get if ::File.exists?(absolute_path) if ::File.directory?(absolute_path) spec_files = ::Dir["#{absolute_path}/**/*_spec.js"].map do |file| ["#{relative_path}#{file.gsub(absolute_path, "")}"] end get_generated_spec(absolute_path, spec_files) else super end elsif ::File.exists?("#{absolute_path}.js") get_generated_spec("#{absolute_path}.js", ["#{relative_path}.js"]) else pass end end def get_generated_spec(real_path, spec_files) html = render_spec(spec_files) [ 200, { 'Content-Type' => "text/html", 'Last-Modified' => ::File.mtime(real_path).rfc822 }, html ] end def render_spec(spec_files) self.class.spec_representation_class.new(:spec_files => spec_files, :session_id => session_id).to_s end def session_id params[:session_id] || request.cookies["session_id"] end def absolute_path @absolute_path ||= ::File.expand_path("#{spec_root_path}#{relative_path.gsub(%r{^/specs}, "")}") end end end end
Version data entries
4 entries across 4 versions & 1 rubygems