Welcome to mirror list, hosted at ThFree Co, Russian Federation.

twine_test.rb « test - github.com/mapsme/twine.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: efeb045ee5bb31e7eb27b47d4f89b2e8f53289dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'erb'
require 'minitest/autorun'
require "mocha/mini_test"
require 'securerandom'
require 'stringio'
require 'twine'
require 'twine_file_dsl'

class TwineTest < Minitest::Test
  include TwineFileDSL

  KNOWN_LANGUAGES = %w(en fr de es)
  
  def setup
    super
    Twine::stdout = StringIO.new
    Twine::stderr = StringIO.new

    @formatters = Twine::Formatters.formatters.dup

    @output_dir = Dir.mktmpdir
    @output_path = File.join @output_dir, SecureRandom.uuid
  end

  def teardown
    FileUtils.remove_entry_secure @output_dir if File.exists? @output_dir
    Twine::Formatters.formatters.clear
    Twine::Formatters.formatters.concat @formatters
    super
  end

  def execute(command)
    command += "  -o #{@output_path}"
    Twine::Runner.run(command.split(" "))
  end

  def fixture_path(filename)
    File.join File.dirname(__FILE__), 'fixtures', filename
  end

  def content(filename)
    ERB.new(File.read fixture_path(filename)).result
  end

  def content_io(filename)
    StringIO.new ERB.new(File.read fixture_path(filename)).result
  end
end