Class: Jasmine::Headless::SpecFileAnalyzer

Inherits:
CacheableAction show all
Defined in:
lib/jasmine/headless/spec_file_analyzer.rb

Instance Attribute Summary

Attributes inherited from CacheableAction

#file

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CacheableAction

cache_dir, cache_dir=, #cache_file, cache_type=, #cached?, enabled=, enabled?, for, #fresh?, #handle, #initialize

Constructor Details

This class inherits a constructor from Jasmine::Headless::CacheableAction

Class Method Details

.cache_typeObject



6
7
8
# File 'lib/jasmine/headless/spec_file_analyzer.rb', line 6

def cache_type
  "spec_file_analysis"
end

Instance Method Details

#actionObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jasmine/headless/spec_file_analyzer.rb', line 11

def action
  line_numbers = {}

  data = File.read(file)

  if data.respond_to?(:encode)
    data.encode!('US-ASCII', 'UTF-8', :invalid => :replace, :undef => :replace)
  else
    require 'iconv'
    ic = Iconv.new('UTF-8//IGNORE', 'US-ASCII')
    data = ic.iconv(File.read(file) + ' ')[0..-2]
  end

  data.force_encoding('US-ASCII') if data.respond_to?(:force_encoding)

  data.lines.each_with_index.each { |line, index|
    if description = line[%r{(describe|context|it)[( ]*(["'])(.*)\2}, 3]
      (line_numbers[description] ||= []) << (index + 1)
    end
  }

  line_numbers
end

#serialize(data) ⇒ Object



35
36
37
# File 'lib/jasmine/headless/spec_file_analyzer.rb', line 35

def serialize(data)
  MultiJson.encode(data)
end

#unserialize(data) ⇒ Object



39
40
41
# File 'lib/jasmine/headless/spec_file_analyzer.rb', line 39

def unserialize(data)
  MultiJson.decode(data)
end