Sha256: 59e965a2075b3d9321a4df59934b52a001577e21ec88a91f47b24515f5b69929

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

require "tilt"
require "konacha/engine"
require "konacha/runner"
require "konacha/server"
require "konacha/reporter"
require "konacha/formatter"

module Konacha
  class << self
    attr_accessor :mode

    def serve
      puts "Your tests are here:"
      puts "  http://#{host}:#{port}/"
      self.mode = :server
      Konacha::Server.start
    end

    def run
      self.mode = :runner
      Konacha::Runner.start
    end

    def config
      Konacha::Engine.config.konacha
    end

    def configure
      yield config
    end

    delegate :host, :port, :spec_dir, :spec_matcher, :application, :driver, :runner_port, :formatters, :to => :config

    def spec_root
      [config.spec_dir].flatten.map {|d| File.join(Rails.root, d)}
    end

    def spec_paths
      spec_root.flat_map do |root|
        # Support Sprockets 2.x
        if Rails.application.assets.respond_to?(:each_entry)
          paths = Rails.application.assets.each_entry(root).find_all { |pathname|
            config.spec_matcher === pathname.basename.to_s &&
            (pathname.extname == '.js' || Tilt[pathname]) &&
            Rails.application.assets.content_type_of(pathname) == 'application/javascript'
          }
        # Sprockets 3
        elsif Rails.application.assets.respond_to?(:each_file)
          paths = Rails.application.assets.each_file.find_all { |path|
            pathname = Pathname.new(path)
            pathname.dirname.to_s.start_with?(root) &&
              config.spec_matcher === pathname.basename.to_s &&
              (pathname.extname == '.js' || Tilt[pathname])
          }
        else
          raise NotImplementedError.new("Konacha is not compatible with the version of Sprockets used by your application.")
        end
        paths.map { |pathname|
          pathname.to_s.gsub(File.join(root, ''), '')
        }.sort
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
konacha-3.7.0 lib/konacha.rb
konacha-3.6.0 lib/konacha.rb