module Filewatcher::SpecHelper
Helper for common spec features between plugins
Constants
- ENVIRONMENT_SPECS_COEFFICIENTS
Public Instance Methods
debug(string)
click to toggle source
# File lib/filewatcher/spec_helper.rb, line 60 def debug(string) logger.debug "Thread ##{Thread.current.object_id} #{string}" end
environment_specs_coefficients()
click to toggle source
# File lib/filewatcher/spec_helper.rb, line 27 def environment_specs_coefficients ENVIRONMENT_SPECS_COEFFICIENTS end
logger()
click to toggle source
# File lib/filewatcher/spec_helper.rb, line 23 def logger @logger ||= Logger.new($stdout, level: :debug) end
system_stat(filename)
click to toggle source
# File lib/filewatcher/spec_helper.rb, line 64 def system_stat(filename) case (host_os = RbConfig::CONFIG['host_os']) when /linux(-gnu)?/ `stat --printf 'Modification: %y, Change: %z\n' #{filename}` when /darwin\d*/ `stat #{filename}` when *Gem::WIN_PATTERNS system_stat_windows filename else "Unknown OS `#{host_os}` for system's `stat` command" end end
system_stat_windows(filename)
click to toggle source
# File lib/filewatcher/spec_helper.rb, line 77 def system_stat_windows(filename) filename = filename.gsub('/', '\\\\\\') properties = 'CreationDate,InstallDate,LastModified,LastAccessed' command = "wmic datafile where Name=\"#{filename}\" get #{properties}" # debug command `#{command}` end
wait(seconds: 1, interval: 1, &block)
click to toggle source
# File lib/filewatcher/spec_helper.rb, line 31 def wait(seconds: 1, interval: 1, &block) environment_specs_coefficients.each do |condition, coefficient| next unless instance_exec(&condition) interval *= coefficient seconds *= coefficient end if block wait_with_block seconds, interval, &block else wait_without_block seconds end end
wait_with_block(seconds, interval) { || ... }
click to toggle source
# File lib/filewatcher/spec_helper.rb, line 46 def wait_with_block(seconds, interval, &_block) (seconds / interval).ceil.times do break if yield debug "sleep interval #{interval}" sleep interval end end
wait_without_block(seconds)
click to toggle source
# File lib/filewatcher/spec_helper.rb, line 55 def wait_without_block(seconds) debug "sleep without intervals #{seconds}" sleep seconds end