File: wlang_test.rb

package info (click to toggle)
ruby-sinatra 1.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,524 kB
  • ctags: 483
  • sloc: ruby: 9,521; makefile: 5
file content (87 lines) | stat: -rw-r--r-- 1,977 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require File.expand_path('../helper', __FILE__)

begin
require 'wlang'

class WLangTest < Test::Unit::TestCase
  def engine
    Tilt::WLangTemplate
  end

  def wlang_app(&block)
    mock_app {
      set :views, File.dirname(__FILE__) + '/views'
      get '/', &block
    }
    get '/'
  end

  it 'uses the correct engine' do
    assert_equal engine, Tilt[:wlang]
  end

  it 'renders .wlang files in views path' do
    wlang_app { wlang :hello }
    assert ok?
    assert_equal "Hello from wlang!\n", body
  end

  it 'renders in the app instance scope' do
    mock_app do
      helpers do
        def who; "world"; end
      end
      get('/') { wlang 'Hello +{who}!' }
    end
    get '/'
    assert ok?
    assert_equal 'Hello world!', body
  end

  it 'takes a :locals option' do
    wlang_app do
      locals = {:foo => 'Bar'}
      wlang 'Hello ${foo}!', :locals => locals
    end
    assert ok?
    assert_equal 'Hello Bar!', body
  end

  it "renders with inline layouts" do
    mock_app do
      layout { 'THIS. IS. +{yield.upcase}!' }
      get('/') { wlang 'Sparta' }
    end
    get '/'
    assert ok?
    assert_equal 'THIS. IS. SPARTA!', body
  end

  it "renders with file layouts" do
    wlang_app { wlang 'Hello World', :layout => :layout2 }
    assert ok?
    assert_body "WLang Layout!\nHello World"
  end

  it "can rendered truly nested layouts by accepting a layout and a block with the contents" do
    mock_app do
      template(:main_outer_layout) { "<h1>Title</h1>\n>{ yield }" }
      template(:an_inner_layout) { "<h2>Subtitle</h2>\n>{ yield }" }
      template(:a_page) { "<p>Contents.</p>\n" }
      get('/') do
        wlang :main_outer_layout, :layout => false do
          wlang :an_inner_layout do
            wlang :a_page
          end
        end
      end
    end
    get '/'
    assert ok?
    assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
  end
end

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