Sha256: cf38781388f3b1e36f5c1c8204d54ac3e5c0e391add8cef9a6610a4eb27ac455

Contents?: true

Size: 595 Bytes

Versions: 5

Compression:

Stored size: 595 Bytes

Contents

require 'erb'

describe "ERB#def_method" do

  it "define module's instance method to render eRuby file" do
    input = <<'END'
arg1=<%= arg1.inspect %>
arg2=<%= arg2.inspect %>
END
    expected = <<'END'
arg1="foo"
arg2=123
END
    #
    filename = 'example.rhtml'   # 'arg1' and 'arg2' are used in example.rhtml
    #erb = ERB.new(File.read(filename))
    erb = ERB.new(input)
    class MyClass0ForErb
    end
    erb.def_method(MyClass0ForErb, 'render(arg1, arg2)', filename)
    MyClass0ForErb.method_defined?(:render)
    MyClass0ForErb.new.render('foo', 123).should == expected
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubysl-erb-2.0.2 spec/def_method_spec.rb
rubysl-erb-1.0.1 spec/def_method_spec.rb
rubysl-erb-1.0.0 spec/def_method_spec.rb
rubysl-erb-2.0.1 spec/def_method_spec.rb
rubysl-erb-2.0.0 spec/def_method_spec.rb