lib/teaspoon/suite.rb in teaspoon-0.8.0 vs lib/teaspoon/suite.rb in teaspoon-0.9.0

- old
+ new

@@ -1,33 +1,32 @@ module Teaspoon class Suite - def self.all @all ||= Teaspoon.configuration.suite_configs.keys.map { |suite| Teaspoon::Suite.new(suite: suite) } end def self.resolve_spec_for(file) all.each do |suite| spec = suite.include_spec_for?(file) - return {suite: suite.name, path: spec} if spec + return { suite: suite.name, path: spec } if spec end false end attr_accessor :config, :name - delegate :helper, :stylesheets, :javascripts, :boot_partial, :body_partial, :no_coverage, :hooks, - to: :config + delegate :helper, :stylesheets, :javascripts, :boot_partial, :body_partial, :no_coverage, :hooks, + to: :config def initialize(options = {}) @options = options @name = (@options[:suite] || :default).to_s @config = suite_configuration @env = Rails.application.assets end def spec_files - glob.map { |file| {path: file, name: asset_from_file(file)} } + glob.map { |file| { path: file, name: asset_from_file(file) } } end def spec_assets(include_helper = true) assets = specs assets.unshift(helper) if include_helper && helper @@ -36,13 +35,24 @@ def include_spec?(file) glob.include?(file) end + def ignored_file?(file) + for ignored in no_coverage + if ignored.is_a?(String) + return true if File.basename(file) == ignored + elsif ignored.is_a?(Regexp) + return true if file =~ ignored + end + end + false + end + def include_spec_for?(file) return file if glob.include?(file) - paths = glob.select { |path| path.include?(file) } + paths = glob.select { |path| path.include?(file) } return paths unless paths.empty? false end protected @@ -52,13 +62,13 @@ return files unless files.empty? glob.map { |file| asset_from_file(file) } end def asset_tree(sources) - sources.collect do |source| + sources.map do |source| asset = @env.find_asset(source) - if asset && asset.respond_to?(:logical_path) + if asset && asset.respond_to?(:logical_path) && config.expand_assets asset.to_a.map { |a| asset_url(a) } else source unless source.blank? end end.flatten.compact.uniq @@ -70,18 +80,11 @@ "#{asset.logical_path}#{params}" end def instrument_file?(file) return false unless @options[:coverage] || Teaspoon.configuration.use_coverage - return false if include_spec?(file) - for ignored in no_coverage - if ignored.is_a?(String) - return false if File.basename(file) == ignored - elsif ignored.is_a?(Regexp) - return false if file =~ ignored - end - end + return false if include_spec?(file) || ignored_file?(file) true end def asset_from_file(original) filename = original @@ -92,10 +95,10 @@ raise Teaspoon::AssetNotServable, "#{filename} is not within an asset path" if filename == original normalize_js_extension(filename) end def normalize_js_extension(filename) - filename.gsub('.erb', '').gsub(/(\.js\.coffee|\.coffee)$/, ".js") + filename.gsub(".erb", "").gsub(/(\.js\.coffee|\.coffee)$/, ".js") end def glob @glob ||= Dir[config.matcher.present? ? Teaspoon.configuration.root.join(config.matcher) : ""] end