Sha256: 41c2b0b0e061cad47f1f52a9be047a4c2c68a5e599005a735365ad9e753818db

Contents?: true

Size: 1.75 KB

Versions: 49

Compression:

Stored size: 1.75 KB

Contents

require File.dirname(__FILE__) + '/test_helper'

class SinatraMarkabyTest < Test::Unit::TestCase
  def markaby_app(&block)
    mock_app {
      use_in_file_templates!
      helpers Sinatra::Markaby
      set :views, File.dirname(__FILE__) + '/views'
      get '/', &block
    }
    get '/'
  end

  def test_renders_inline_strings
    markaby_app { markaby 'mab.p "Hello shrimp!"' }
    assert last_response.ok?
    assert_equal '<p>Hello shrimp!</p>', last_response.body
  end

  def test_renders_inline_blocks
    markaby_app {
      @name = 'Frank & Mary'
      markaby do |mab|
        mab.p "Hello #{@name}!"
      end
    }
    assert last_response.ok?
    assert_equal '<p>Hello Frank &amp; Mary!</p>', last_response.body
  end

  def test_renders_markaby_files_in_views_path
    markaby_app {
      @name = 'World'
      markaby :hello
    }
    assert last_response.ok?
    assert_equal '<p>Hello, World!</p>', last_response.body
  end

  def test_renders_in_file_template
    markaby_app {
      @name = 'Joe'
      markaby :in_file
    }
    assert last_response.ok?
    assert_equal '<p>Hey Joe</p>', last_response.body
  end

  def test_renders_with_layout
    markaby_app {
      @name = 'with Layout'
      markaby :hello, :layout => :html
    }
    assert last_response.ok?
    assert_equal '<html><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"/><title>Hello</title></head><body><p>Hello, with Layout!</p></body></html>', last_response.body
  end

  def test_raises_error_if_template_not_found
    mock_app {
      helpers Sinatra::Markaby
      set :environment, :test
      set :raise_errors, true
      get('/') { markaby :no_such_template }
    }
    assert_raises(Errno::ENOENT) { get('/') }
  end
end

__END__

@@ in_file
mab.p "Hey #{@name}"

Version data entries

49 entries across 49 versions & 3 rubygems

Version Path
sbfaulkner-sinatra-markaby-0.9.2.2 test/sinatra_markaby_test.rb
tdreyno-middleman-0.2.4 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.2.5 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.2.6 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.2.7 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.2.8 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.2.9 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.3.0 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.3.1 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.3.10 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.3.2 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.3.3 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.3.4 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.3.7 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.3.8 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.4.1 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.5.0 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.5.2 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.5.3 vendor/sinatra-markaby/test/sinatra_markaby_test.rb
tdreyno-middleman-0.5.4 vendor/sinatra-markaby/test/sinatra_markaby_test.rb