Class: Jasmine::Headless::FilesList

Inherits:
Object
  • Object
show all
Includes:
FileChecker
Defined in:
lib/jasmine/headless/files_list.rb

Constant Summary collapse

PLEASE_WAIT_IM_WORKING_TIME =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FileChecker

#alert_bad_format, #alert_if_bad_format?, #bad_format?

Constructor Details

#initialize(options = {}) ⇒ FilesList

Returns a new instance of FilesList.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/jasmine/headless/files_list.rb', line 78

def initialize(options = {})
  @options = options

  Kernel.srand(@options[:seed]) if @options[:seed]

  @required_files = UniqueAssetList.new
  @potential_files_to_filter = []

  self.class.default_files.each do |file|
    begin
      @required_files << sprockets_environment.find_asset(file, :bundle => false)
    rescue InvalidUniqueAsset => e
      raise StandardError.new("Not an asset: #{file}")
    end
  end

  use_config! if config?
end

Instance Attribute Details

#potential_files_to_filterObject (readonly)

Returns the value of attribute potential_files_to_filter.



76
77
78
# File 'lib/jasmine/headless/files_list.rb', line 76

def potential_files_to_filter
  @potential_files_to_filter
end

#required_filesObject (readonly)

Returns the value of attribute required_files.



76
77
78
# File 'lib/jasmine/headless/files_list.rb', line 76

def required_files
  @required_files
end

Class Method Details

.asset_pathsObject

Raises:

  • (StandardError)


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jasmine/headless/files_list.rb', line 13

def asset_paths
  return @asset_paths if @asset_paths

  require 'rubygems'

  raise StandardError.new("A newer version of Rubygems is required to use vendored assets. Please upgrade.") if !Gem::Specification.respond_to?(:each)

  @asset_paths = []

  Gem::Specification.each { |gemspec| @asset_paths += get_paths_from_gemspec(gemspec) }

  @asset_paths
end

.default_filesObject



63
64
65
# File 'lib/jasmine/headless/files_list.rb', line 63

def default_files
  %w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessConsoleReporter jsDump beautify-html}
end

.extension_filterObject



67
68
69
70
71
# File 'lib/jasmine/headless/files_list.rb', line 67

def extension_filter
  extensions = (%w{.js .css} + Sprockets.engine_extensions)

  %r{(#{extensions.join('|')})$}
end

.get_paths_from_gemspec(gemspec) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jasmine/headless/files_list.rb', line 27

def get_paths_from_gemspec(gemspec)
  %w{vendor lib app}.collect do |dir|
    path = File.join(gemspec.gem_dir, dir, "assets/javascripts")

    if File.directory?(path) && !@asset_paths.include?(path)
      path
    else
      nil
    end
  end.compact
end

.reset!Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jasmine/headless/files_list.rb', line 39

def reset!
  @asset_paths = nil

  # register haml-sprockets if it's available...
  %w{haml-sprockets}.each do |library|
    begin
      require library
    rescue LoadError
    end
  end

  # ...and unregister ones we don't want/need
  Sprockets.instance_eval do
    EXCLUDED_FORMATS.each do |extension|
      register_engine ".#{extension}", Jasmine::Headless::NilTemplate
    end

    register_engine '.coffee', Jasmine::Headless::CoffeeTemplate
    register_engine '.js', Jasmine::Headless::JSTemplate
    register_engine '.css', Jasmine::Headless::CSSTemplate
    register_engine '.jst', Jasmine::Headless::JSTTemplate
  end
end

Instance Method Details

#filesObject



97
98
99
# File 'lib/jasmine/headless/files_list.rb', line 97

def files
  required_files.flatten.collect { |asset| asset.pathname.to_s }.uniq
end

#files_to_htmlObject



152
153
154
# File 'lib/jasmine/headless/files_list.rb', line 152

def files_to_html
  to_html(files)
end

#filtered?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/jasmine/headless/files_list.rb', line 148

def filtered?
  files != filtered_files
end

#filtered_filesObject



107
108
109
# File 'lib/jasmine/headless/files_list.rb', line 107

def filtered_files
  filter_for_requested_specs(files)
end

#filtered_files_to_htmlObject



156
157
158
# File 'lib/jasmine/headless/files_list.rb', line 156

def filtered_files_to_html
  to_html(filtered_files)
end

#has_spec_outside_scope?Boolean

Returns:

  • (Boolean)


133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/jasmine/headless/files_list.rb', line 133

def has_spec_outside_scope?
  if is_outside_scope = !spec_filter.empty?
    is_outside_scope = spec_dir.any? do |dir|
      spec_file_searches.any? do |search|
        !spec_files.any? do |file|
          target = File.join(dir, search)
          File.fnmatch?(target, file) || File.fnmatch?(target.gsub(%{^**/}, ''), file)
        end
      end
    end
  end

  is_outside_scope
end

#search_pathsObject



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/jasmine/headless/files_list.rb', line 111

def search_paths
  return @search_paths if @search_paths

  @search_paths = [ Jasmine::Core.path, Jasmine::Headless.root.join('vendor/assets/javascripts').to_s ]
  @search_paths += self.class.asset_paths
  @search_paths += src_dir.collect { |dir| File.expand_path(dir) }
  @search_paths += asset_paths.collect { |dir| File.expand_path(dir) }
  @search_paths += spec_dir.collect { |dir| File.expand_path(dir) }

  @search_paths
end

#spec_file_line_numbersObject



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/jasmine/headless/files_list.rb', line 160

def spec_file_line_numbers
  @spec_file_line_numbers ||= Hash[spec_files.collect { |file|
    if File.exist?(file)
      if !(lines = Jasmine::Headless::SpecFileAnalyzer.for(file)).empty?
        [ file, lines ]
      end
    else
      nil
    end
  }.compact]
end

#spec_filesObject



101
102
103
104
105
# File 'lib/jasmine/headless/files_list.rb', line 101

def spec_files
  filter_for_requested_specs(
    files.find_all { |file| spec_dir.any? { |dir| file[dir] } }
  )
end

#sprockets_environmentObject



123
124
125
126
127
128
129
130
131
# File 'lib/jasmine/headless/files_list.rb', line 123

def sprockets_environment
  return @sprockets_environment if @sprockets_environment

  @sprockets_environment = Sprockets::Environment.new
  search_paths.each { |path| @sprockets_environment.append_path(path) }

  @sprockets_environment.unregister_postprocessor('application/javascript', Sprockets::SafetyColons)
  @sprockets_environment
end