Sha256: 6383a47c955dafc78760484cfde299118b995de9aa99aeaf3aefa410691cc68b

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

# coding: utf-8
require 'fileutils'
require 'yaml'
require_relative 'capture_std'
require 'i18n/tasks/commands'

module TestCodebase
  include CaptureStd
  extend self
  AT = 'tmp/test_codebase'

  def i18n_task(*args)
    TestCodebase.in_test_app_dir do
      ::I18n::Tasks::BaseTask.new(*args)
    end
  end

  def i18n_cmd(*args)
    TestCodebase.in_test_app_dir do
      ::I18n::Tasks::Commands.new(*args)
    end
  end

  def run_cmd(name, *args, &block)
    in_test_app_dir do
      silence_stderr {
        capture_stdout { i18n_cmd.run(name, *args, &block) }
      }
    end
  end

  def setup(files = {})
    FileUtils.mkdir_p AT
    in_test_app_dir do
      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, *args)
    in_test_app_dir {
      rake_task = Rake::Task[task]
      rake_task.reenable
      capture_stdout { rake_task.invoke(*args) }
    }
  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
end


Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
i18n-tasks-0.7.11 spec/support/test_codebase.rb
i18n-tasks-0.7.10 spec/support/test_codebase.rb
i18n-tasks-0.7.9 spec/support/test_codebase.rb
i18n-tasks-0.7.8 spec/support/test_codebase.rb
i18n-tasks-0.7.7 spec/support/test_codebase.rb
i18n-tasks-0.7.6 spec/support/test_codebase.rb
i18n-tasks-0.7.5 spec/support/test_codebase.rb
i18n-tasks-0.7.4 spec/support/test_codebase.rb
i18n-tasks-0.7.3 spec/support/test_codebase.rb
i18n-tasks-0.7.2 spec/support/test_codebase.rb