lib/teaspoon/suite.rb in teaspoon-0.9.1 vs lib/teaspoon/suite.rb in teaspoon-1.0.0
- old
+ new
@@ -11,11 +11,11 @@
end
false
end
attr_accessor :config, :name
- delegate :helper, :stylesheets, :javascripts, :boot_partial, :body_partial, :no_coverage, :hooks,
+ delegate :helper, :stylesheets, :javascripts, :boot_partial, :body_partial, :hooks,
to: :config
def initialize(options = {})
@options = options
@name = (@options[:suite] || :default).to_s
@@ -31,25 +31,10 @@
assets = specs
assets.unshift(helper) if include_helper && helper
asset_tree(assets)
end
- 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) }
return paths unless paths.empty?
false
@@ -62,53 +47,66 @@
return files unless files.empty?
glob.map { |file| asset_from_file(file) }
end
def asset_tree(sources)
- sources.map do |source|
+ sources.flat_map do |source|
asset = @env.find_asset(source)
- if asset && asset.respond_to?(:logical_path) && config.expand_assets
- asset.to_a.map { |a| asset_url(a) }
+
+ if asset && asset.respond_to?(:logical_path)
+ assets = config.expand_assets ? asset.to_a : [asset]
+ assets.map { |a| asset_url(a) }
else
- source unless source.blank?
+ source.blank? ? [] : [source]
end
- end.flatten.compact.uniq
+ end.compact.uniq
end
def asset_url(asset)
- params = "?body=1"
- params << "&instrument=1" if instrument_file?(asset.pathname.to_s)
- "#{asset.logical_path}#{params}"
+ params = []
+ params << "body=1" if config.expand_assets
+ params << "instrument=1" if instrument_file?(asset.pathname.to_s)
+ url = asset.logical_path
+ url += "?#{params.join("&")}" if params.any?
+ url
end
def instrument_file?(file)
- return false unless @options[:coverage] || Teaspoon.configuration.use_coverage
- return false if include_spec?(file) || ignored_file?(file)
+ return false unless coverage_requested?
+ return false if matched_spec_file?(file)
true
end
+ def coverage_requested?
+ @options[:coverage] || Teaspoon.configuration.use_coverage
+ end
+
+ def matched_spec_file?(file)
+ glob.include?(file)
+ end
+
def asset_from_file(original)
filename = original
Rails.application.config.assets.paths.each do |path|
filename = filename.gsub(%r(^#{Regexp.escape(path.to_s)}[\/|\\]), "")
end
- raise Teaspoon::AssetNotServable, "#{filename} is not within an asset path" if filename == original
+ raise Teaspoon::AssetNotServableError.new(filename: filename) 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|\.es6|\.js\.es6)$/, ".js")
end
def glob
@glob ||= Dir[config.matcher.present? ? Teaspoon.configuration.root.join(config.matcher) : ""].sort!
end
def suite_configuration
config = Teaspoon.configuration.suite_configs[name]
- raise Teaspoon::UnknownSuite, "Unknown suite \"#{name}\"" unless config.present?
- config[:instance] ||= Teaspoon::Configuration::Suite.new(&config[:block])
+ raise Teaspoon::UnknownSuite.new(name: name) unless config.present?
+ config[:instance] ||= Teaspoon::Configuration::Suite.new(name, &config[:block])
end
def specs_from_file
Array(@options[:file]).map do |filename|
asset_from_file(File.expand_path(Teaspoon.configuration.root.join(filename)))