Sha256: 45920cb03728490aa53bcc72217eca0b12492efddc5a2e5b3ffeba0757c05902

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require 'jasmine-core'

module Lanes
    module API

        class TestSpecs
            cattr_accessor :current

            def initialize(root)
                @root = root
            end

            def css_files
                urlpath Jasmine::Core.css_files
            end

            def js_files
                urlpath(Jasmine::Core.js_files)   +
                urlpath(Jasmine::Core.boot_files) +
                urlpath(spec_files("helpers"))    +
                urlpath(spec_files("client"))
            end

          private

            def spec_files(path)
                dir = @root.join("spec")
                regex = /^#{dir}\//
                Dir.glob( dir.join(path,"**/*.{coffee,js}") ).map do |file|
                    file.sub(regex,'').sub(/coffee$/,'js')
                end
            end

            def urlpath(files)
                files.map{ |file| "/spec/"+file }
            end
        end


        Lanes.config.get(:specs_root) do | root |
            TestSpecs.current = TestSpecs.new(root)
            Root.sprockets.append_path(root.join("spec"))
        end


        Root.sprockets.append_path(Jasmine::Core.path)

        routes.draw do

            get '/spec' do
                content_type 'text/html'
                erb :specs, locals: { specs: TestSpecs.current }
            end

            get "/spec/*" do |path|
                env_sprockets = request.env.dup
                env_sprockets['PATH_INFO'] = path
                settings.sprockets.call env_sprockets
            end

        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lanes-0.0.5 lib/lanes/api/test_specs.rb