Sha256: 7bff2b70523fefe07b5c3a9de0bf15d77d77b03eecfaa4a85c38ae08e5b2972e

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

require 'setup'

spec :engine do
  it 'inherits engine from superclass' do
    a = mock_controller {
      engine :Slim
    }
    b = mock_controller(a) {
    }
    assert(b.initialize_controller.engine) == [:SlimTemplate, []]
  end

  it 'overrides engine inherited from superclass' do
    a = mock_controller {
      engine :Slim
    }
    b = mock_controller(a) {
      engine :Turbo
    }
    assert(b.initialize_controller.engine) == [:TurboTemplate, []]
  end

  it 'can use include to override engine inherited from superclass' do
    a = mock_controller {
      engine :Slim
    }
    b = mock_controller(a) {
      engine :Turbo
    }
    c = mock_controller(a) {
      import :engine, from: b
    }
    assert(c.initialize_controller.engine) == [:TurboTemplate, []]
  end

  it 'uses a block (that runs at instance level) to define engine' do
    app mock_controller {
      engine {@x = 'x'; :Slim}
      def get; engine[0].to_s + @x end
    }
    get
    assert(last_response.body) == 'SlimTemplatex'
  end

  it 'can accept engine options when a block used' do
    c = mock_controller {
      engine {[:Slim, {pretty_print: true}]}
    }
    e,o = c.allocate.engine
    assert(e) == :SlimTemplate
    assert(o) == [{pretty_print: true}]
  end

  it 'uses inherited engine if given block returns no engine' do
    a = mock_controller {
      engine :Slim
    }
    b = mock_controller(a) {
      engine {
        :ERB if env['IAMABOT']
      }
      def get; engine[0].to_s end
    }
    app b
    get
    assert(last_response.body) == 'SlimTemplate'
    env['IAMABOT'] = true
    get
    assert(last_response.body) == 'ERBTemplate'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rocketio-0.1.0 test/render/engine_test.rb