Sha256: 51b01abb3fc99f13ffe233d2988a586fe30f1e88b41728ff9d211a28f7ba2f90

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

$:.unshift(File.expand_path("../lib", File.dirname(__FILE__)))
require 'zsteg'

SAMPLES_DIR = File.expand_path("../samples", File.dirname(__FILE__))

def each_sample glob="*.png"
  Dir[File.join(SAMPLES_DIR, glob)].each do |fname|
    yield fname.sub(Dir.pwd+'/','')
  end
end

def sample fname
  fname = File.join(SAMPLES_DIR, fname)
  if block_given?
    yield fname.sub(Dir.pwd+'/','')
  end

  fname
end

def cli *args
  @@cli_cache ||= {}
  args.map! do |arg|
    if arg.is_a?(String) && arg[' ']
      # split strings with spaces into arrays
      arg.split(' ')
    else
      arg
    end
  end
  args.flatten!
  @@cli_cache[args.inspect] ||=
    begin
      klass =
        if args.first.is_a?(Symbol)
          cli_name = args.shift.to_s
          require "zsteg/cli/#{cli_name}"
          ZSteg::CLI.const_get(cli_name.capitalize)
        else
          ZSteg::CLI
        end
      args << "--no-color" unless args.any?{|x| x['color']}
      orig_stdout, out = $stdout, ""
      begin
        $stdout = StringIO.new(out)
        klass.new(args).run
      ensure
        $stdout = orig_stdout
      end
      out.strip
    end
end

RSpec.configure do |config|
  config.before :suite do
    Dir[File.join(SAMPLES_DIR, "**", "*.7z")].each do |fname|
      next if File.exist?(fname.sub(/\.7z$/,''))
      system "7z", "x", fname, "-o#{File.dirname(fname)}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zsteg-0.1.2 spec/spec_helper.rb
zsteg-0.1.1 spec/spec_helper.rb
zsteg-0.1.0 spec/spec_helper.rb