# encoding: UTF-8
# Original Rumble tests (c) 2011 Magnus Holm (https://github.com/judofyr).
require 'helper'
if defined?(Minitest::Test)
klass = Minitest::Test
else
klass = MiniTest::Unit::TestCase
end
class TestRumble < klass
include Keynote::Rumble
def assert_rumble(str, &blk)
exp = str.gsub(/(\s+(<)|>\s+)/) { $2 || '>' }
res = nil
build_html {
res = yield.to_s
}
assert_equal exp, res
assert_instance_of ActiveSupport::SafeBuffer, res
end
def setup
@rumble_context = nil
super
assert_nil @rumble_context
end
def teardown
super
assert_nil @rumble_context
end
def test_simple
str = <<-HTML
HTML
assert_rumble str do
form do
div.wrapper! do
h1 "My Site"
end
div.input do
input type: 'text', name: 'value'
end
end
end
end
def test_string_data
assert_rumble '' do
div data: "whatever"
end
end
def test_hash_data
str = <<-HTML
HTML
assert_rumble str do
div data: { modal: true, safe: '"""'.html_safe, unsafe: '"""' }
end
end
def test_array_attrs
str = <<-HTML
HTML
assert_rumble str do
div class: ["hello", '"uns&fe"', '"w&rld"'.html_safe]
end
end
def test_several
str = <<-HTML
Hello
World
HTML
assert_rumble str do
p "Hello"
p "World"
end
end
def test_several_capture
str = <<-HTML
Hello
Hello
|
World
World
HTML
assert_rumble str do
div do
(%w[Hello World].map { |x| build_html { p x; p x } } * '|').html_safe
end
end
end
def test_capture_raise
assert_raises RuntimeError do
build_html {
div do
build_html { raise }
end
}
end
end
def test_escape
str = <<-HTML
Hello & World
HTML
assert_rumble str do
p "Hello & World", :class => '"test"'
end
end
def test_multiple_css_classes
str = <<-HTML
HTML
assert_rumble str do
p.one.two.three
end
end
def test_selfclosing
assert_rumble "
" do
br
end
end
def test_text
assert_rumble "hello" do
text "hello"
end
end
def test_escaping_unsafe_input
str = "
"
assert_rumble "<br>
" do
div { str }
end
assert_rumble "<br>
" do
div str
end
assert_rumble "<br>
" do
div { text { str } }
end
assert_rumble "<br>
" do
div { text str }
end
end
def test_not_escaping_safe_input
str = "
".html_safe
assert_rumble "
" do
div { str }
end
assert_rumble "
" do
div str
end
assert_rumble "
" do
div { text { str } }
end
assert_rumble "
" do
div { text str }
end
end
def test_error_tags_outside_rumble_context
assert_raises Keynote::Rumble::Error do
div "content"
end
end
def test_error_selfclosing_content
assert_raises Keynote::Rumble::Error do
build_html {
br "content"
}
end
end
def test_error_css_proxy_continue
assert_raises Keynote::Rumble::Error do
build_html {
p.one("test").two
}
end
end
# The real test here is if @rumble_context is nil in the teardown.
def test_error_general
assert_raises RuntimeError do
build_html {
div do
raise
end
}
end
end
end