Sha256: f005621b1c74b07155969ca845014905be4cda272ba631248265282b6414d644

Contents?: true

Size: 1.87 KB

Versions: 47

Compression:

Stored size: 1.87 KB

Contents

require File.expand_path('../teststrap',__FILE__)
require 'rabl/template'

class Scope
end

context "RablTemplate" do
  asserts "that it registers for .rabl files" do
    Tilt['test.rabl']
  end.equals RablTemplate

  context "#render" do
    setup do
      RablTemplate.new { |t| "code(:lol) { 'wut' }" }
    end

    asserts "preparing and evaluating templates on #render" do
      topic.render
    end.matches %r{"lol":"wut"}

    3.times do |n|
      asserts "can be rendered #{n} time(s)" do
        topic.render
      end.matches %r{"lol":"wut"}
    end

    # asserts "that it can be passed locals" do
    #   template = RablTemplate.new { "code(:name) { @name }" }
    #   template.render(Object.new, :object => 'Bob')
    # end.matches %r{"name":"Bob"}

    asserts "that it evaluates in object scope" do
      template = RablTemplate.new { "code(:lol) { @name }" }
      scope = Object.new
      scope.instance_variable_set :@name, 'Joe'
      template.render(scope)
    end.matches %r{"lol":"Joe"}

    asserts "that it can pass a block for yield" do
      template = RablTemplate.new { "code(:lol) { 'Hey ' + yield + '!' }" }
      template.render { 'Joe' }
    end.matches %r{"lol":"Hey Joe!"}
  end

  context "#render compiled" do
    # asserts "that it can be passed locals" do
    #   template = RablTemplate.new { "code(:name) { @name }" }
    #   template.render(Scope.new, :object => 'Bob')
    # end.matches %r{"name":"Bob"}

    asserts "that it evaluates in an object scope" do
      template = RablTemplate.new { "code(:lol) { @name }" }
      scope = Scope.new
      scope.instance_variable_set :@name, 'Joe'
      template.render(scope)
    end.matches %r{"lol":"Joe"}

    asserts "that it can pass a block for yield" do
      template = RablTemplate.new { "code(:lol) { 'Hey ' + yield + '!' }" }
      template.render(Scope.new) { 'Joe' }
    end.matches %r{"lol":"Hey Joe!"}
  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
rabl-0.14.3 test/template_test.rb
rabl-0.14.2 test/template_test.rb
rabl-0.14.1 test/template_test.rb
rabl-0.14.0 test/template_test.rb
rabl-0.13.1 test/template_test.rb
rabl-0.13.0 test/template_test.rb
rabl-0.12.0 test/template_test.rb
rabl-0.11.8 test/template_test.rb
rabl-0.11.7 test/template_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/rabl-0.11.6/test/template_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/rabl-0.11.6/test/template_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/rabl-0.11.6/test/template_test.rb
rabl-0.11.6 test/template_test.rb
rabl-0.11.5 test/template_test.rb
rabl-0.11.4 test/template_test.rb
rabl-0.11.3 test/template_test.rb
rabl-0.11.2 test/template_test.rb
rabl-0.11.1 test/template_test.rb
rabl-0.11.0 test/template_test.rb
rabl-0.10.1 test/template_test.rb