Sha256: 601a79d93161240e22c56815c6d6e264899605d02281415c134f42af4e1cc820

Contents?: true

Size: 1.96 KB

Versions: 17

Compression:

Stored size: 1.96 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 {
      markaby 'text value', :locals => { :value => 'foo' }
    }
    assert ok?
    assert_equal 'foo', body
  end
end

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

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
sinatra-acd-1.4.5 test/markaby_test.rb
sinatra-1.4.5 test/markaby_test.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/sinatra-1.4.4/test/markaby_test.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/sinatra-1.4.4/test/markaby_test.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/sinatra-1.4.4/test/markaby_test.rb
sinatra-1.4.4 test/markaby_test.rb
sinatra-1.4.3 test/markaby_test.rb
sinatra-1.4.2 test/markaby_test.rb
sinatra-1.4.1 test/markaby_test.rb
sinatra-1.4.0 test/markaby_test.rb
sinatra-1.4.0.d test/markaby_test.rb
sinatra-1.4.0.c test/markaby_test.rb
sinatra-1.4.0.b test/markaby_test.rb
sinatra-1.4.0.a test/markaby_test.rb
devcenter-0.0.3 vendor/sinatra/test/markaby_test.rb
devcenter-0.0.2 vendor/sinatra/test/markaby_test.rb
devcenter-0.0.1 vendor/sinatra/test/markaby_test.rb