summaryrefslogtreecommitdiff
path: root/test/erb/test_erb.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/erb/test_erb.rb')
-rw-r--r--test/erb/test_erb.rb84
1 files changed, 57 insertions, 27 deletions
diff --git a/test/erb/test_erb.rb b/test/erb/test_erb.rb
index 045ce51..ffa1fef 100644
--- a/test/erb/test_erb.rb
+++ b/test/erb/test_erb.rb
@@ -24,16 +24,22 @@ class TestERB < Test::Unit::TestCase
assert_match(/\Atest filename:1\b/, e.backtrace[0])
end
+ # [deprecated] This will be removed at Ruby 2.7
def test_without_filename_with_safe_level
- erb = ERB.new("<% raise ::TestERB::MyError %>", 1)
+ erb = EnvUtil.suppress_warning do
+ ERB.new("<% raise ::TestERB::MyError %>", 1)
+ end
e = assert_raise(MyError) {
erb.result
}
assert_match(/\A\(erb\):1\b/, e.backtrace[0])
end
+ # [deprecated] This will be removed at Ruby 2.7
def test_with_filename_and_safe_level
- erb = ERB.new("<% raise ::TestERB::MyError %>", 1)
+ erb = EnvUtil.suppress_warning do
+ ERB.new("<% raise ::TestERB::MyError %>", 1)
+ end
erb.filename = "test filename"
e = assert_raise(MyError) {
erb.result
@@ -92,9 +98,12 @@ class TestERBCore < Test::Unit::TestCase
end
def test_core
- _test_core(nil)
- _test_core(0)
- _test_core(1)
+ # [deprecated] Fix initializer at Ruby 2.7
+ EnvUtil.suppress_warning do
+ _test_core(nil)
+ _test_core(0)
+ _test_core(1)
+ end
end
def _test_core(safe)
@@ -203,26 +212,26 @@ EOS
end
def test_trim_line1_with_carriage_return
- erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", nil, '>')
+ erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", trim_mode: '>')
assert_equal("line\r\n" * 3, erb.result)
- erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", nil, '%>')
+ erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", trim_mode: '%>')
assert_equal("line\r\n" * 3, erb.result)
end
def test_trim_line2_with_carriage_return
- erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", nil, '<>')
+ erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", trim_mode: '<>')
assert_equal("line\r\n" * 3, erb.result)
- erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", nil, '%<>')
+ erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", trim_mode: '%<>')
assert_equal("line\r\n" * 3, erb.result)
end
def test_explicit_trim_line_with_carriage_return
- erb = @erb.new("<%- 3.times do -%>\r\nline\r\n<%- end -%>\r\n", nil, '-')
+ erb = @erb.new("<%- 3.times do -%>\r\nline\r\n<%- end -%>\r\n", trim_mode: '-')
assert_equal("line\r\n" * 3, erb.result)
- erb = @erb.new("<%- 3.times do -%>\r\nline\r\n<%- end -%>\r\n", nil, '%-')
+ erb = @erb.new("<%- 3.times do -%>\r\nline\r\n<%- end -%>\r\n", trim_mode: '%-')
assert_equal("line\r\n" * 3, erb.result)
end
@@ -259,26 +268,26 @@ EOS
%n = 1
<%= n%>
EOS
- assert_equal("1\n", ERB.new(src, nil, '%').result(binding))
+ assert_equal("1\n", ERB.new(src, trim_mode: '%').result(binding))
src = <<EOS
<%
%>
EOS
ans = "\n"
- assert_equal(ans, ERB.new(src, nil, '%').result(binding))
+ assert_equal(ans, ERB.new(src, trim_mode: '%').result(binding))
src = "<%\n%>"
# ans = "\n"
ans = ""
- assert_equal(ans, ERB.new(src, nil, '%').result(binding))
+ assert_equal(ans, ERB.new(src, trim_mode: '%').result(binding))
src = <<EOS
<%
n = 1
%><%= n%>
EOS
- assert_equal("1\n", ERB.new(src, nil, '%').result(binding))
+ assert_equal("1\n", ERB.new(src, trim_mode: '%').result(binding))
src = <<EOS
%n = 1
@@ -294,7 +303,7 @@ EOS
% %%><%1
%%
EOS
- assert_equal(ans, ERB.new(src, nil, '%').result(binding))
+ assert_equal(ans, ERB.new(src, trim_mode: '%').result(binding))
end
def test_def_erb_method
@@ -378,7 +387,7 @@ foo
%% print 'foo'
EOS
- assert_equal(ans, ERB.new(src, nil, '%').result)
+ assert_equal(ans, ERB.new(src, trim_mode: '%').result)
end
def test_keep_lineno
@@ -389,7 +398,7 @@ Hello,\s
% raise("lineno")
EOS
- erb = ERB.new(src, nil, '%')
+ erb = ERB.new(src, trim_mode: '%')
e = assert_raise(RuntimeError) {
erb.result
}
@@ -407,7 +416,7 @@ EOS
%>Hello,\s
World%>
EOS
- assert_equal(ans, ERB.new(src, nil, '>').result)
+ assert_equal(ans, ERB.new(src, trim_mode: '>').result)
ans = <<EOS
%>
@@ -415,7 +424,7 @@ Hello,\s
World%>
EOS
- assert_equal(ans, ERB.new(src, nil, '<>').result)
+ assert_equal(ans, ERB.new(src, trim_mode: '<>').result)
ans = <<EOS
%>
@@ -440,13 +449,13 @@ EOS
}
assert_match(/\A\(erb\):5\b/, e.backtrace[0].to_s)
- erb = ERB.new(src, nil, '>')
+ erb = ERB.new(src, trim_mode: '>')
e = assert_raise(RuntimeError) {
erb.result
}
assert_match(/\A\(erb\):5\b/, e.backtrace[0].to_s)
- erb = ERB.new(src, nil, '<>')
+ erb = ERB.new(src, trim_mode: '<>')
e = assert_raise(RuntimeError) {
erb.result
}
@@ -460,13 +469,13 @@ EOS
<% raise("lineno") %>
EOS
- erb = ERB.new(src, nil, '-')
+ erb = ERB.new(src, trim_mode: '-')
e = assert_raise(RuntimeError) {
erb.result
}
assert_match(/\A\(erb\):5\b/, e.backtrace[0].to_s)
- erb = ERB.new(src, nil, '%-')
+ erb = ERB.new(src, trim_mode: '%-')
e = assert_raise(RuntimeError) {
erb.result
}
@@ -502,8 +511,8 @@ NotSkip NotSkip
* WORLD
KeepNewLine \s
EOS
- assert_equal(ans, ERB.new(src, nil, '-').result)
- assert_equal(ans, ERB.new(src, nil, '-%').result)
+ assert_equal(ans, ERB.new(src, trim_mode: '-').result)
+ assert_equal(ans, ERB.new(src, trim_mode: '-%').result)
end
def test_url_encode
@@ -519,7 +528,7 @@ EOS
end
def test_percent_after_etag
- assert_equal("1%", @erb.new("<%= 1 %>%", nil, "%").result)
+ assert_equal("1%", @erb.new("<%= 1 %>%", trim_mode: "%").result)
end
def test_token_extension
@@ -629,6 +638,27 @@ EOS
@erb.new("<% # comment %>\n").result
end
end
+
+ # These interfaces will be removed at Ruby 2.7.
+ def test_deprecated_interface_warnings
+ [nil, 0, 1, 2].each do |safe|
+ assert_warning(/2nd argument of ERB.new is deprecated/) do
+ ERB.new('', safe)
+ end
+ end
+
+ [nil, '', '%', '%<>'].each do |trim|
+ assert_warning(/3rd argument of ERB.new is deprecated/) do
+ ERB.new('', nil, trim)
+ end
+ end
+
+ [nil, '_erbout', '_hamlout'].each do |eoutvar|
+ assert_warning(/4th argument of ERB.new is deprecated/) do
+ ERB.new('', nil, nil, eoutvar)
+ end
+ end
+ end
end
class TestERBCoreWOStrScan < TestERBCore