Module: Nanoc::Spec::Helper

Defined in:
lib/nanoc/spec.rb

Instance Method Summary collapse

Instance Method Details

#chdir(dir) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/nanoc/spec.rb', line 13

def chdir(dir)
  here = Dir.getwd
  Dir.chdir(dir)
  yield
ensure
  Dir.chdir(here)
end

#command?(cmd) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/nanoc/spec.rb', line 21

def command?(cmd)
  TTY::Which.exist?(cmd)
end

#skip_unless_gem_available(gem) ⇒ Object



29
30
31
32
33
# 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) ⇒ Object



25
26
27
# 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) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# 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