Sha256: 7b8a9e3a023d8f748744f28a48626bfe855e49bab39aa14b5a323e87f29798ac

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

module Teabag
  class Suite

    attr_accessor :config
    delegate :stylesheets, :helper, to: :config

    def initialize(name = :default)
      @name = name
      @config = suite_configuration(name)
    end

    def javascripts
      [config.javascripts, helper, specs].flatten
    end

    def specs
      Dir[config.matcher.present? ? Teabag.configuration.root.join(config.matcher) : ""].map do |filename|
        asset_path_from_filename(File.expand_path(filename))
      end
    end

    def suites
      {all: Teabag.configuration.suites.keys, active: @name.to_s}
    end

    protected

    def suite_configuration(name)
      name ||= :default
      config = Teabag.configuration.suites[name.to_s]
      raise Teabag::UnknownSuite unless config.present?
      Teabag::Configuration::Suite.new(&config)
    end

    def asset_path_from_filename(original)
      filename = original
      Rails.application.config.assets.paths.each do |path|
        filename = filename.gsub(%r(^#{path}[\/|\\]), "")
      end
      raise Teabag::AssetNotServable, "#{filename} is not within an asset path" if filename == original
      filename.gsub(/(\.js\.coffee|\.coffee)$/, ".js")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
teabag-0.4.2 lib/teabag/suite.rb
teabag-0.4.1 lib/teabag/suite.rb