Sha256: 76db8594c93438e93ac2e89f170909f7a3341ee2501fa8e467024d178d7fe2d2

Contents?: true

Size: 1.54 KB

Versions: 13

Compression:

Stored size: 1.54 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,
            'Content-Length' => html.length
          },
          html
        ]
      end

      def render_spec(spec_files)
        self.class.spec_representation_class.new(:spec_files => spec_files).to_s
      end

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

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
pivotal-screw-unit-0.5.0 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
pivotal-screw-unit-0.5.1 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
pivotal-screw-unit-0.5.2 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
pivotal-screw-unit-0.5.3 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
pivotal-screw-unit-server-0.5.3 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
pivotal-screw-unit-server-0.5.4 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
pivotal-screw-unit-server-0.5.5 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
pivotal-screw-unit-server-0.5.6 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
pivotal-screw-unit-server-0.5.7 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
pivotal-screw-unit-server-0.5.8 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
screw-unit-0.5.1 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
screw-unit-server-0.5.3 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb
screw-unit-0.5.2 vendor/js-test-core/lib/js_test_core/resources/spec_file.rb