module Zucchini::Compiler
Public Instance Methods
compile_js(orientation)
click to toggle source
Compile the feature Javascript file for UIAutomation
@param orientation [String] initial device orientation, `portrait` or `landscape` @return [String] path to a compiled js file
# File lib/zucchini/compiler.rb, line 10 def compile_js(orientation) js_path = "#{run_data_path}/feature.js" lib_path = File.expand_path(File.dirname(__FILE__)) coffee_src_paths = [ "#{lib_path}/uia", "#{path}/../support/screens", "#{path}/../support/lib", feature_coffee("#{path}/feature.zucchini", orientation) ].select { |p| File.exists? p }.join ' ' "coffee -o #{run_data_path} -j #{js_path} -c #{coffee_src_paths}".tap do |cmd| raise "Error compiling a feature file: #{cmd}" unless system(cmd) end concat("#{lib_path}/uia/lib", js_path) js_path end
Private Instance Methods
concat(lib_path, js_path)
click to toggle source
# File lib/zucchini/compiler.rb, line 46 def concat(lib_path, js_path) tmp_file = "/tmp/feature.js" js_src = Dir.glob("#{lib_path}/*.js").inject([]) do |libs, f| libs << File.read(f) end.join(";\n") File.open(tmp_file, 'w') do |f| f.puts(js_src) f.puts(File.read(js_path)) end FileUtils.mv(tmp_file, js_path) end
feature_coffee(file, orientation)
click to toggle source
Wrap feature text into a call to Zucchini
client side runner
@param file [String] path to a feature file @param orientation [String] initial device orientation @return [String] path to the resulting CoffeeScript file
# File lib/zucchini/compiler.rb, line 36 def feature_coffee(file, orientation) cs_path = "#{run_data_path}/feature.coffee" File.open(cs_path, "w+") do |f| feature_text = File.read(file).gsub(/\#.+[\z\n]?/,"").gsub(/\n/, "\\n") f.write "Zucchini('#{feature_text}', '#{orientation}')" end cs_path end