Sha256: 0b1e3731ccb3df04d816bde061a4f63bc271541e2a6baaebf47c61b6956d932d

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

# -*- coding: utf-8 -*-
require "test_helper"

class EnvironmentTest < Sablon::TestCase
  def test_transforms_internal_hash
    context = Sablon::Context.transform_hash(a: 1, b: { c: 2, "d" => 3 })
    env = Sablon::Environment.new(nil, a: 1, b: { c: 2, "d" => 3 })
    #
    assert_nil env.template
    assert_equal context, env.context
  end

  def test_alter_context
    # set initial context
    env = Sablon::Environment.new(nil, a: 1, b: { c: 2, "d" => 3 })
    # alter context to change a single key and set a new one
    env2 = env.alter_context(a: "a", e: "new-key")
    assert_equal({ "a" => "a", "b" => { "c" => 2, "d" => 3 }, "e" => "new-key" }, env2.context)
    # check that the old context was not modified
    assert_equal({"a" => 1, "b" => { "c" => 2, "d" => 3 }}, env.context)
    # check that numbering and template are the same references
    assert env.template.equal?(env2.template), "#{env.template} != #{env2.template}"
    assert env.numbering.equal?(env2.numbering), "#{env.numbering} != #{env2.numbering}"
    # check that a new context reference was created
    assert !env.context.equal?(env2.context), "#{env.context} == #{env2.context}"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sablon-0.1.1 test/environment_test.rb
sablon-0.1.0 test/environment_test.rb
sablon-0.0.22 test/environment_test.rb