summaryrefslogtreecommitdiff
path: root/test/erb/test_erb_command.rb
blob: 0baa59ddd59ed90747d5b2b357dcecc92b688ec5 (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
# -*- coding: us-ascii -*-
# frozen_string_literal: false
require 'test/unit'

class TestErbCommand < Test::Unit::TestCase
  def test_var
    assert_in_out_err(["-I#{File.expand_path('../../lib', __dir__)}", "-w",
                       File.expand_path("../../libexec/erb", __dir__),
                       "var=hoge"],
                      "<%=var%>", ["hoge"])
  end

  def test_template_file_encoding
    assert_in_out_err(["-I#{File.expand_path('../../lib', __dir__)}", "-w",
                       File.expand_path("../../libexec/erb", __dir__)],
                      "<%=''.encoding.to_s%>", ["UTF-8"])
  end

  # These interfaces will be removed at Ruby 2.7.
  def test_deprecated_option
    warnings = [
      "warning: -S option of erb command is deprecated. Please do not use this.",
      /\n.+\/libexec\/erb:\d+: warning: Passing safe_level with the 2nd argument of ERB\.new is deprecated\. Do not use it, and specify other arguments as keyword arguments\.\n/,
    ]
    assert_in_out_err(["-I#{File.expand_path('../../lib', __dir__)}", "-w",
                       File.expand_path("../../libexec/erb", __dir__),
                       "-S", "0"],
                      "hoge", ["hoge"], warnings)
  end
end