Sha256: 480134a08276b08b115d222009d14ea072a20446e380fdd2d27c3f685d623d9f

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require 'fileutils'
require 'yaml'

module TestCodebase
  extend self
  AT = 'tmp/test_codebase'

  DEFAULTS = {
      'config/locales/en.yml' => {'en' => {}}.to_yaml,
      'config/locales/es.yml' => {'es' => {}}.to_yaml
  }

  def setup(files)
    FileUtils.mkdir_p AT
    in_test_app_dir do
      DEFAULTS.merge(files).each do |path, content|
        FileUtils.mkdir_p File.dirname(path)
        File.open(path, 'w') { |f| f.write(content) }
      end
    end
  end

  def teardown
    FileUtils.rm_rf AT
  end

  def rake_result(task)
    in_test_app_dir {
      rake_task = Rake::Task[task]
      rake_task.reenable
      capture_stdout { rake_task.invoke }
    }
  end

  def in_test_app_dir(&block)
    return block.call if @in_dir
    begin
      pwd = Dir.pwd
      Dir.chdir AT
      @in_dir = true
      block.call
    ensure
      Dir.chdir pwd
      @in_dir = false
    end
  end

  def capture_stderr
    err, $stderr = $stderr, StringIO.new
    yield
    $stderr.string
  ensure
    $stderr = err
  end

  def capture_stdout
    out, $stdout = $stdout, StringIO.new
    yield
    $stdout.string
  ensure
    $stdout = out
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
i18n-tasks-0.2.3 spec/support/test_codebase.rb
i18n-tasks-0.2.2 spec/support/test_codebase.rb
i18n-tasks-0.2.1 spec/support/test_codebase.rb
i18n-tasks-0.2.0 spec/support/test_codebase.rb