test: add template, view, session, and flash tests
This commit is contained in:
1 parent
7cf239f4e3
commit
bb0ac4afc3
4 files changed
+186
No files matched your search
@@ -0,0 +1,29 @@
|
||||
require 'minitest/autorun'
|
||||
require 'prism'
|
||||
|
||||
class TemplateTest < Minitest::Test
|
||||
def test_interpolation
|
||||
assert_equal 'Hello, Ruby!', Prism::Template.render('Hello, <%= name %>!', name: 'Ruby')
|
||||
end
|
||||
|
||||
def test_html_escape
|
||||
result = Prism::Template.render('<%= value %>', value: '<script>alert(1)</script>')
|
||||
assert_equal '<script>alert(1)</script>', result
|
||||
end
|
||||
|
||||
def test_raw_output
|
||||
result = Prism::Template.render('<%== value %>', value: '<b>bold</b>')
|
||||
assert_equal '<b>bold</b>', result
|
||||
end
|
||||
|
||||
def test_logic
|
||||
template = '<% items.each do |n| %><%= n %>;<% end %>'
|
||||
assert_equal '1;2;3;', Prism::Template.render(template, items: [1, 2, 3])
|
||||
end
|
||||
|
||||
def test_conditional
|
||||
template = '<% if admin %>yes<% else %>no<% end %>'
|
||||
assert_equal 'yes', Prism::Template.render(template, admin: true)
|
||||
assert_equal 'no', Prism::Template.render(template, admin: false)
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user