Class: Teabag::Suite

Inherits:
Object
  • Object
show all
Defined in:
lib/teabag/suite.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Suite

Returns a new instance of Suite.



19
20
21
22
23
# File 'lib/teabag/suite.rb', line 19

def initialize(options = {})
  @options = options
  @name = (@options[:suite] || :default).to_s
  @config = suite_configuration
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/teabag/suite.rb', line 4

def config
  @config
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/teabag/suite.rb', line 4

def name
  @name
end

Class Method Details

.allObject



6
7
8
# File 'lib/teabag/suite.rb', line 6

def self.all
  Teabag.configuration.suites.keys.map { |suite| Teabag::Suite.new(suite: suite) }
end

.resolve_spec_for(file) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/teabag/suite.rb', line 10

def self.resolve_spec_for(file)
  suites = all
  suites.each do |suite|
    spec = suite.include_spec_for?(file)
    return {suite: suite.name, path: spec} if spec
  end
  false
end

Instance Method Details

#core_javascriptsObject



37
38
39
# File 'lib/teabag/suite.rb', line 37

def core_javascripts
  config.javascripts
end

#helperObject



29
30
31
# File 'lib/teabag/suite.rb', line 29

def helper
  config.helper
end

#include_spec?(file) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/teabag/suite.rb', line 70

def include_spec?(file)
  glob.include?(file)
end

#include_spec_for?(file) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
# File 'lib/teabag/suite.rb', line 74

def include_spec_for?(file)
  return file if glob.include?(file)
  glob.each do |spec|
    return spec if spec.include?(file)
  end
  false
end

#instrument_file?(file) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
# File 'lib/teabag/suite.rb', line 58

def instrument_file?(file)
  return false if include_spec?(file)
  for ignored in @config.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
  true
end

#javascriptsObject



33
34
35
# File 'lib/teabag/suite.rb', line 33

def javascripts
  [core_javascripts, spec_javascripts].flatten
end


53
54
55
56
# File 'lib/teabag/suite.rb', line 53

def link(params = {})
  query = "?#{params.to_query}" if params.present?
  [Teabag.configuration.mount_at, name, query].compact.join("/")
end

#spec_filesObject



49
50
51
# File 'lib/teabag/suite.rb', line 49

def spec_files
  glob.map { |file| {path: file, name: asset_from_file(file)} }
end

#spec_javascriptsObject



41
42
43
# File 'lib/teabag/suite.rb', line 41

def spec_javascripts
  [helper, specs].flatten
end

#stylesheetsObject



25
26
27
# File 'lib/teabag/suite.rb', line 25

def stylesheets
  config.stylesheets
end

#suitesObject



45
46
47
# File 'lib/teabag/suite.rb', line 45

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