# Run from your Rails main directory require 'test/test_helper' class TestERB < Test::Unit::TestCase def assert_renders_erb(expected, input, shield=true) erb_class = shield ? XSSProtectedERB : ERB actual = eval(erb_class.new(input).src) assert_equal expected, actual end def test_erb_with_shield assert_renders_erb < <%= h("Foo & Bar") %> <%= "Foo & Bar".mark_as_xss_protected %> <%= h("Foo & Bar") %> <%= "Foo & Bar" %> IN end def test_erb_without_shield assert_renders_erb < <%= "Foo & Bar" %> <%= "Foo & Bar".mark_as_xss_protected %> <%= h("Foo & Bar") %> <%= "Foo & Bar" %> IN end end