diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/library/erb/result_spec.rb | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) |
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
[Misc #13792] [ruby-core:82287]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/erb/result_spec.rb')
-rw-r--r-- | spec/ruby/library/erb/result_spec.rb | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/spec/ruby/library/erb/result_spec.rb b/spec/ruby/library/erb/result_spec.rb new file mode 100644 index 0000000000..d79584b221 --- /dev/null +++ b/spec/ruby/library/erb/result_spec.rb @@ -0,0 +1,86 @@ +require 'erb' +require File.expand_path('../../../spec_helper', __FILE__) + +describe "ERB#result" do + + + it "return the result of compiled ruby code" do + input = <<'END' +<ul> +<% for item in list %> + <li><%= item %> +<% end %> +</ul> +END + expected = <<'END' +<ul> + + <li>AAA + + <li>BBB + + <li>CCC + +</ul> +END + erb = ERB.new(input) + list = %w[AAA BBB CCC] + actual = erb.result(binding) + actual.should == expected + end + + + it "share local variables" do + input = "<% var = 456 %>" + expected = 456 + var = 123 + ERB.new(input).result(binding) + var.should == expected + end + + + it "is not able to h() or u() unless including ERB::Util" do + input = "<%=h '<>' %>" + lambda { + ERB.new(input).result() + }.should raise_error(NameError) + end + + + it "is able to h() or u() if ERB::Util is included" do + myerb1 = Class.new do + include ERB::Util + def main + input = "<%=h '<>' %>" + return ERB.new(input).result(binding) + end + end + expected = '<>' + actual = myerb1.new.main() + actual.should == expected + end + + + it "use TOPLEVEL_BINDING if binding is not passed" do + myerb2 = Class.new do + include ERB::Util + def main1 + #input = "<%= binding.to_s %>" + input = "<%= _xxx_var_ %>" + return ERB.new(input).result() + end + def main2 + input = "<%=h '<>' %>" + return ERB.new(input).result() + end + end + + eval '_xxx_var_ = 123', TOPLEVEL_BINDING + expected = '123' + myerb2.new.main1().should == expected + + lambda { + myerb2.new.main2() + }.should raise_error(NameError) + end +end |