Sha256: f895cf8218a3d8d6910b8f4e2a847445d2607c675b69d3ffc041562c5756a6d6

Contents?: true

Size: 1.96 KB

Versions: 131

Compression:

Stored size: 1.96 KB

Contents

require 'contest'
require 'tilt'

begin
  require 'coffee_script'

  class CoffeeScriptTemplateTest < Test::Unit::TestCase
    test "is registered for '.coffee' files" do
      assert_equal Tilt::CoffeeScriptTemplate, Tilt['test.coffee']
    end

    test "compiles and evaluates the template on #render" do
      template = Tilt::CoffeeScriptTemplate.new { |t| "puts 'Hello, World!'\n" }
      assert_match "puts('Hello, World!');", template.render
    end

    test "can be rendered more than once" do
      template = Tilt::CoffeeScriptTemplate.new { |t| "puts 'Hello, World!'\n" }
      3.times { assert_match "puts('Hello, World!');", template.render }
    end

    test "disabling coffee-script wrapper" do
      str = "puts 'Hello, World!'\n"

      template = Tilt::CoffeeScriptTemplate.new(:bare => true) { str }
      assert_equal "puts('Hello, World!');", template.render

      template2 = Tilt::CoffeeScriptTemplate.new(:no_wrap => true) { str}
      assert_equal "puts('Hello, World!');", template.render
    end

    context "disabling coffee-script wrapper globally" do
      setup do
        @bare = Tilt::CoffeeScriptTemplate.default_bare
      end

      teardown do
        Tilt::CoffeeScriptTemplate.default_bare = @bare
      end

      test "no options" do
        template = Tilt::CoffeeScriptTemplate.new { |t| "puts 'Hello, World!'\n" }
        assert_match "puts('Hello, World!');", template.render
        assert_match "(function() {", template.render
      end

      test "overridden by :bare" do
        template = Tilt::CoffeeScriptTemplate.new(:bare => false) { "puts 'Hello, World!'\n" }
        assert_not_equal "puts('Hello, World!');", template.render
      end

      test "overridden by :no_wrap" do
        template = Tilt::CoffeeScriptTemplate.new(:no_wrap => false) { "puts 'Hello, World!'\n" }
        assert_not_equal "puts('Hello, World!');", template.render
      end
    end
  end

rescue LoadError => boom
  warn "Tilt::CoffeeScriptTemplate (disabled)\n"
end

Version data entries

131 entries across 114 versions & 18 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
classiccms-0.7.4 vendor/bundle/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
classiccms-0.7.3 vendor/bundle/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
classiccms-0.7.2 vendor/bundle/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
classiccms-0.7.1 vendor/bundle/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
classiccms-0.7.0 vendor/bundle/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
challah-1.0.0.beta vendor/bundle/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
active_mailer-0.0.5 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
active_mailer-0.0.4 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
active_mailer-0.0.3 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
graphael-on-rails-0.5.1 vendor/bundle/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
graphael-on-rails-0.0.1 vendor/bundle/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
challah-0.9.1.beta.3 vendor/bundle/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb
devise_sociable-0.1.0 vendor/bundle/gems/tilt-1.3.3/test/tilt_coffeescripttemplate_test.rb