module Nanoc::Spec::Helper

Public Instance Methods

chdir(dir) { || ... } click to toggle source
# File lib/nanoc/spec.rb, line 13
def chdir(dir)
  here = Dir.getwd
  Dir.chdir(dir)
  yield
ensure
  Dir.chdir(here)
end
command?(cmd) click to toggle source
# File lib/nanoc/spec.rb, line 21
def command?(cmd)
  TTY::Which.exist?(cmd)
end
skip_unless_gem_available(gem) click to toggle source
# File lib/nanoc/spec.rb, line 29
def skip_unless_gem_available(gem)
  require gem
rescue LoadError
  skip "Could not load gem \"#{gem}\""
end
skip_unless_have_command(cmd) click to toggle source
# File lib/nanoc/spec.rb, line 25
def skip_unless_have_command(cmd)
  skip "Could not find external command \"#{cmd}\"" unless command?(cmd)
end
sleep_until(max: 3.0) { || ... } click to toggle source
# File lib/nanoc/spec.rb, line 35
def sleep_until(max: 3.0)
  start = Time.now
  loop do
    diff = (Time.now - start).to_f
    if diff > max
      raise "Waited for #{diff}s for condition to become true, but it never did"
    end

    break if yield

    sleep 0.1
  end
end