class Zucchini::Feature
Attributes
device[RW]
js_exception[RW]
name[R]
path[RW]
stats[RW]
succeeded[R]
Public Class Methods
new(path)
click to toggle source
# File lib/zucchini/feature.rb, line 13 def initialize(path) @path = path @name = File.basename(path) @device = nil @succeeded = false @js_exception = false end
Public Instance Methods
approve(reference_type)
click to toggle source
# File lib/zucchini/feature.rb, line 98 def approve(reference_type) raise "Directory #{path} doesn't contain previous run data" unless File.exists?("#{run_data_path}/Run\ 1") screenshots(false).each do |s| reference_file_path = "#{File.dirname(s.file_path)}/../../#{reference_type}/#{device[:screen]}/#{s.file_name}" FileUtils.mkdir_p File.dirname(reference_file_path) @succeeded = FileUtils.copy_file(s.file_path, reference_file_path) end end
collect()
click to toggle source
# File lib/zucchini/feature.rb, line 60 def collect with_setup do `rm -rf #{run_data_path}/*` begin out = `instruments #{device_params(@device)} \ -t "#{Zucchini::Config.template}" "#{Zucchini::Config.app}" \ -e UIASCRIPT "#{compile_js(@device[:orientation])}" \ -e UIARESULTSPATH "#{run_data_path}" 2>&1` puts out # Hack. Instruments don't issue error return codes when JS exceptions occur @js_exception = true if (out.match /JavaScript error/) || (out.match /Instruments\ .{0,5}\ Error\ :/ ) ensure `rm -rf instrumentscli*.trace` Zucchini::Log.parse_automation_log(run_path) end end end
compare()
click to toggle source
# File lib/zucchini/feature.rb, line 79 def compare `rm -rf #{run_data_path}/Diff/*` @succeeded = !@js_exception && (stats[:failed].length == 0) end
run_data_path()
click to toggle source
# File lib/zucchini/feature.rb, line 21 def run_data_path "#{@path}/run_data" end
run_path()
click to toggle source
# File lib/zucchini/feature.rb, line 25 def run_path "#{run_data_path}/Run\ 1" end
screenshots(process = true)
click to toggle source
# File lib/zucchini/feature.rb, line 38 def screenshots(process = true) log = Zucchini::Log.new(run_path) if process && Zucchini::Log.exists?(run_path) @screenshots ||= Dir.glob("#{run_path}/*.png").sort.map do |file| next unless Zucchini::Screenshot.valid?(file) screenshot = Zucchini::Screenshot.new(file, @device, log) if process screenshot.mask screenshot.compare end screenshot end.compact + unmatched_pending_screenshots end
unmatched_pending_screenshots()
click to toggle source
# File lib/zucchini/feature.rb, line 29 def unmatched_pending_screenshots Dir.glob("#{@path}/pending/#{@device[:screen]}/[^0-9]*.png").sort.map do |file| screenshot = Zucchini::Screenshot.new(file, nil, nil, true) screenshot.test_path = File.expand_path(file) screenshot.diff = [:pending, "unmatched"] screenshot end end
with_setup() { || ... }
click to toggle source
# File lib/zucchini/feature.rb, line 84 def with_setup setup = "#{@path}/setup.rb" if File.exists?(setup) require setup begin Setup.before { yield } ensure Setup.after end else yield end end