Sha256: df223e82410c138187def43c11f2d3cf32e812926e04fac702d8126bf903fecb

Contents?: true

Size: 1.97 KB

Versions: 72

Compression:

Stored size: 1.97 KB

Contents

require File.expand_path('../helper', __FILE__)

begin
require 'markaby'

class MarkabyTest < Test::Unit::TestCase
  def markaby_app(&block)
    mock_app do
      set :views, File.dirname(__FILE__) + '/views'
      get '/', &block
    end
    get '/'
  end

  it 'renders inline markaby strings' do
    markaby_app { markaby 'h1 "Hiya"' }
    assert ok?
    assert_equal "<h1>Hiya</h1>", body
  end

  it 'renders .markaby files in views path' do
    markaby_app { markaby :hello }
    assert ok?
    assert_equal "<h1>Hello From Markaby</h1>", body
  end

  it "renders with inline layouts" do
    mock_app do
      layout { 'h1 { text "THIS. IS. "; yield }' }
      get('/') { markaby 'em "SPARTA"' }
    end
    get '/'
    assert ok?
    assert_equal "<h1>THIS. IS. <em>SPARTA</em></h1>", body
  end

  it "renders with file layouts" do
    markaby_app { markaby 'text "Hello World"', :layout => :layout2 }
    assert ok?
    assert_equal "<h1>Markaby Layout!</h1><p>Hello World</p>", body
  end

  it 'renders inline markaby blocks' do
    markaby_app { markaby { h1 'Hiya' } }
    assert ok?
    assert_equal "<h1>Hiya</h1>", body
  end

  it 'renders inline markaby blocks with inline layouts' do
    markaby_app do
      settings.layout { 'h1 { text "THIS. IS. "; yield }' }
      markaby { em 'SPARTA' }
    end
    assert ok?
    assert_equal "<h1>THIS. IS. <em>SPARTA</em></h1>", body
  end

  it 'renders inline markaby blocks with file layouts' do    
    markaby_app { markaby(:layout => :layout2) { text "Hello World" } }
    assert ok?
    assert_equal "<h1>Markaby Layout!</h1><p>Hello World</p>", body
  end

  it "raises error if template not found" do
    mock_app { get('/') { markaby :no_such_template } }
    assert_raise(Errno::ENOENT) { get('/') }
  end
  
  it "allows passing locals" do
    markaby_app do
      markaby 'text value', :locals => { :value => 'foo' }
    end
    assert ok?
    assert_equal 'foo', body
  end
end

rescue LoadError
  warn "#{$!.to_s}: skipping markaby tests"
end

Version data entries

72 entries across 70 versions & 8 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/sinatra-1.3.2/test/markaby_test.rb
classiccms-0.7.4 vendor/bundle/gems/sinatra-1.3.2/test/markaby_test.rb
classiccms-0.7.3 vendor/bundle/gems/sinatra-1.3.2/test/markaby_test.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/sinatra-1.3.5/test/markaby_test.rb
classiccms-0.7.2 vendor/bundle/gems/sinatra-1.3.2/test/markaby_test.rb
classiccms-0.7.1 vendor/bundle/gems/sinatra-1.3.2/test/markaby_test.rb
classiccms-0.7.0 vendor/bundle/gems/sinatra-1.3.2/test/markaby_test.rb
torquebox-console-0.2.5 vendor/bundle/ruby/1.8/gems/sinatra-1.3.5/test/markaby_test.rb
torquebox-console-0.2.5 vendor/bundle/jruby/1.9/gems/sinatra-1.3.5/test/markaby_test.rb
sinatra-1.3.6 test/markaby_test.rb
torquebox-console-0.2.4 vendor/bundle/jruby/1.9/gems/sinatra-1.3.5/test/markaby_test.rb
torquebox-console-0.2.4 vendor/bundle/ruby/1.8/gems/sinatra-1.3.5/test/markaby_test.rb
torquebox-console-0.2.3 vendor/bundle/jruby/1.9/gems/sinatra-1.3.5/test/markaby_test.rb
sinatra-1.3.5 test/markaby_test.rb
sinatra-1.3.4 test/markaby_test.rb
classiccms-0.6.9 vendor/bundle/gems/sinatra-1.3.2/test/markaby_test.rb
classiccms-0.6.8 vendor/bundle/gems/sinatra-1.3.2/test/markaby_test.rb
classiccms-0.6.7 vendor/bundle/gems/sinatra-1.3.2/test/markaby_test.rb
classiccms-0.6.6 vendor/bundle/gems/sinatra-1.3.2/test/markaby_test.rb
jellyfish-0.5.0 sinatra/markaby_test.rb