summaryrefslogtreecommitdiff
path: root/spec/ruby/library/erb/new_spec.rb
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-22 13:28:25 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-22 13:28:25 +0000
commitcc777d09f44fa909a336ba14f3aa802ffe16e010 (patch)
treef360ca1bfed187f981397f6c7370360287606ffb /spec/ruby/library/erb/new_spec.rb
parent1727c8358498054428a376b52869983549f62399 (diff)
erb.rb: deprecate safe_level of ERB.new
Also, as it's in the middle of the list of 4 arguments, 3rd and 4th arguments (trim_mode, eoutvar) are changed to keyword arguments. Old ways to specify arguments are deprecated and warned now. bin/erb: deprecate -S option. We'll remove all of deprecated ones at Ruby 2.7+. enc/make_encmake.rb: stopped using deprecated interface ext/etc/mkconstants.rb: ditto ext/socket/mkconstants.rb: ditto sample/ripper/ruby2html.rb: ditto spec/ruby/library/erb/defmethod/def_erb_method_spec.rb: ditto spec/ruby/library/erb/new_spec.rb: ditto test/erb/test_erb.rb: ditto test/erb/test_erb_command.rb: ditto tool/generic_erb.rb: ditto tool/ruby_vm/helpers/dumper.rb: ditto tool/transcode-tblgen.rb: ditto lib/rdoc/erbio.rb: ditto lib/rdoc/generator/darkfish.rb: ditto [Feature #14256] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62529 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/erb/new_spec.rb')
-rw-r--r--spec/ruby/library/erb/new_spec.rb69
1 files changed, 57 insertions, 12 deletions
diff --git a/spec/ruby/library/erb/new_spec.rb b/spec/ruby/library/erb/new_spec.rb
index f141f1c..156873a 100644
--- a/spec/ruby/library/erb/new_spec.rb
+++ b/spec/ruby/library/erb/new_spec.rb
@@ -31,21 +31,33 @@ END
it "compiles eRuby script into ruby code when trim mode is 0 or not specified" do
expected = "<ul>\n\n\n\n<li>1</li>\n\n\n\n<li>2</li>\n\n\n\n<li>3</li>\n\n\n</ul>\n"
[0, '', nil].each do |trim_mode|
- ERB.new(@eruby_str, nil, trim_mode).result.should == expected
+ if RUBY_VERSION >= '2.6'
+ ERB.new(@eruby_str, trim_mode: trim_mode).result.should == expected
+ else
+ ERB.new(@eruby_str, nil, trim_mode).result.should == expected
+ end
end
end
it "removes '\n' when trim_mode is 1 or '>'" do
expected = "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>\n"
[1, '>'].each do |trim_mode|
- ERB.new(@eruby_str, nil, trim_mode).result.should == expected
+ if RUBY_VERSION >= '2.6'
+ ERB.new(@eruby_str, trim_mode: trim_mode).result.should == expected
+ else
+ ERB.new(@eruby_str, nil, trim_mode).result.should == expected
+ end
end
end
it "removes spaces at beginning of line and '\n' when trim_mode is 2 or '<>'" do
expected = "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>\n"
[2, '<>'].each do |trim_mode|
- ERB.new(@eruby_str, nil, trim_mode).result.should == expected
+ if RUBY_VERSION >= '2.6'
+ ERB.new(@eruby_str, trim_mode: trim_mode).result.should == expected
+ else
+ ERB.new(@eruby_str, nil, trim_mode).result.should == expected
+ end
end
end
@@ -61,7 +73,11 @@ END
</ul>
END
- ERB.new(input, nil, '-').result.should == expected
+ if RUBY_VERSION >= '2.6'
+ ERB.new(input, trim_mode: '-').result.should == expected
+ else
+ ERB.new(input, nil, '-').result.should == expected
+ end
end
@@ -75,23 +91,39 @@ END
END
lambda {
- ERB.new(input, nil, '-').result
+ if RUBY_VERSION >= '2.6'
+ ERB.new(input, trim_mode: '-').result
+ else
+ ERB.new(input, nil, '-').result
+ end
}.should raise_error(SyntaxError)
end
it "regards lines starting with '%' as '<% ... %>' when trim_mode is '%'" do
expected = "<ul>\n <li>1\n \n <li>2\n \n <li>3\n \n\n</ul>\n%%\n"
- ERB.new(@eruby_str2, nil, "%").result.should == expected
+ if RUBY_VERSION >= '2.6'
+ ERB.new(@eruby_str2, trim_mode: "%").result.should == expected
+ else
+ ERB.new(@eruby_str2, nil, "%").result.should == expected
+ end
end
it "regards lines starting with '%' as '<% ... %>' and remove \"\\n\" when trim_mode is '%>'" do
expected = "<ul>\n <li>1 <li>2 <li>3 </ul>\n%%\n"
- ERB.new(@eruby_str2, nil, '%>').result.should == expected
+ if RUBY_VERSION >= '2.6'
+ ERB.new(@eruby_str2, trim_mode: '%>').result.should == expected
+ else
+ ERB.new(@eruby_str2, nil, '%>').result.should == expected
+ end
end
it "regard lines starting with '%' as '<% ... %>' and remove \"\\n\" when trim_mode is '%<>'" do
expected = "<ul>\n <li>1\n \n <li>2\n \n <li>3\n \n</ul>\n%%\n"
- ERB.new(@eruby_str2, nil, '%<>').result.should == expected
+ if RUBY_VERSION >= '2.6'
+ ERB.new(@eruby_str2, trim_mode: '%<>').result.should == expected
+ else
+ ERB.new(@eruby_str2, nil, '%<>').result.should == expected
+ end
end
@@ -106,13 +138,22 @@ END
%%%
END
- ERB.new(input, nil, '%-').result.should == expected
+ if RUBY_VERSION >= '2.6'
+ ERB.new(input, trim_mode: '%-').result.should == expected
+ else
+ ERB.new(input, nil, '%-').result.should == expected
+ end
end
it "changes '_erbout' variable name in the produced source" do
input = @eruby_str
- match_erbout = ERB.new(input, nil, nil).src
- match_buf = ERB.new(input, nil, nil, 'buf').src
+ if RUBY_VERSION >= '2.6'
+ match_erbout = ERB.new(input, trim_mode: nil).src
+ match_buf = ERB.new(input, trim_mode: nil, eoutvar: 'buf').src
+ else
+ match_erbout = ERB.new(input, nil, nil).src
+ match_buf = ERB.new(input, nil, nil, 'buf').src
+ end
match_erbout.gsub("_erbout", "buf").should == match_buf
end
@@ -124,7 +165,11 @@ END
<%# end %>
END
ERB.new(input).result.should == "\n<b></b>\n\n"
- ERB.new(input, nil, '<>').result.should == "<b></b>\n"
+ if RUBY_VERSION >= '2.6'
+ ERB.new(input, trim_mode: '<>').result.should == "<b></b>\n"
+ else
+ ERB.new(input, nil, '<>').result.should == "<b></b>\n"
+ end
end
it "forget local variables defined previous one" do