2011-09-01 14:39:29 +00:00
|
|
|
require 'multi_json'
|
|
|
|
|
|
|
|
module Jasmine::Headless
|
|
|
|
class SpecFileAnalyzer < CacheableAction
|
|
|
|
class << self
|
|
|
|
def cache_type
|
|
|
|
"spec_file_analysis"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def action
|
|
|
|
line_numbers = {}
|
|
|
|
|
2011-10-10 13:32:27 +00:00
|
|
|
data = File.read(file)
|
|
|
|
|
|
|
|
if data.respond_to?(:encode)
|
2011-11-18 11:29:36 +00:00
|
|
|
data.encode!('US-ASCII', 'UTF-8', :invalid => :replace, :undef => :replace)
|
2011-10-10 13:32:27 +00:00
|
|
|
else
|
|
|
|
require 'iconv'
|
|
|
|
ic = Iconv.new('UTF-8//IGNORE', 'US-ASCII')
|
|
|
|
data = ic.iconv(File.read(file) + ' ')[0..-2]
|
|
|
|
end
|
|
|
|
|
2011-09-01 14:39:29 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
def serialize(data)
|
2012-04-23 13:30:56 +00:00
|
|
|
MultiJson.dump(data)
|
2011-09-01 14:39:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def unserialize(data)
|
2012-04-23 13:30:56 +00:00
|
|
|
MultiJson.load(data)
|
2011-09-01 14:39:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|