File: test_mab_builder.rb

package info (click to toggle)
ruby-mab 0.0.1%2Bgit20120515.30414e4-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 136 kB
  • sloc: ruby: 604; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 952 bytes parent folder | download
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
require 'helper'

class TestMabBuilder < MiniTest::Unit::TestCase
  def test_assigns
    b = Mab::Builder.new(:title => 'Mab') do
      title @title
    end

    assert_equal '<title>Mab</title>', b.to_s
  end

  def test_capture
    b = Mab::Builder.new do
      %w[name address].map do |key|
        mab do
          p key
        end
      end.join('<br>')
    end

    assert_equal "<p>name</p><br><p>address</p>", b.to_s
  end

  def test_helper
    obj = Class.new {
      def initialize
        @a = 1
        @b = 2
      end

      def c; @a + @b end
    }.new

    b = Mab::Builder.new({}, obj) do
      p @a
      p @b
      p c
    end

    assert_equal '<p>1</p><p>2</p><p>3</p>', b.to_s
  end

  def test_pretty
    b = Mab::PrettyBuilder.new do
      html do
        body do
          h1 "Nice"
        end
      end
    end

    assert_equal "<!DOCTYPE html>\n<html>\n  <body>\n    <h1>Nice</h1>\n  </body>\n</html>", b.to_s
  end
end