Sha256: 13e283cf8c35d170c5a748f2dcd1f43aab77cecab8a55cc17685aca4826b7c63

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

module JsTestCore
  module Resources
    class SpecFile < ::JsTestCore::Resources::File
      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)
        headers = {
          'Content-Type' => "text/html",
          'Last-Modified' => ::File.mtime(real_path).rfc822
        }
        [200, headers, html]
      end

      def render_spec(spec_files)
        JsTestCore.suite_representation_class.new(:spec_files => spec_files).to_s
      end

      def absolute_path
        @absolute_path ||= ::File.expand_path("#{spec_path}#{relative_path.gsub(%r{^/specs}, "")}")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
honkster-screw-unit-server-0.6.3 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
honkster-screw-unit-server-0.6.2 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
honkster-screw-unit-server-0.6.1 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
btakita-screw-unit-server-0.6.0 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb