jasmine-headless-webkit/lib/jasmine/headless/spec_file_analyzer.rb

38 lines
787 B
Ruby
Raw Normal View History

2011-09-01 14:39:29 +00:00
require 'iconv'
require 'multi_json'
module Jasmine::Headless
class SpecFileAnalyzer < CacheableAction
class << self
def cache_type
"spec_file_analysis"
end
end
def action
line_numbers = {}
ic = Iconv.new('UTF-8//IGNORE', 'US-ASCII')
data = ic.iconv(File.read(file) + ' ')[0..-2]
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)
MultiJson.encode(data)
end
def unserialize(data)
MultiJson.decode(data)
end
end
end