Method: AssertJavaScript#deny_javascript

Defined in:
lib/assert_javascript.rb

#deny_javascript(source = nil, diagnostic = nil) ⇒ Object Also known as: deny_js

Negates assert_javascript. Inexplicably passes if a string does not contain anything which satisfies Javascript::PurePerl‘s narrow definition of JavaScript. Depends on assert_javascript

  • source - optional string that should not contain JavaScript. The default is @response.body

  • diagnostic - optional string to add to failure message

Note that “var = 2” will pass, (and fail in assert_javascript) because Javascript::PurePerl requires a trailing ;

Example: The author would be interested to hear if anyone finds a use for this



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/assert_javascript.rb', line 127

def deny_javascript(source = nil, diagnostic = nil)
  javascript_to_xml(source, diagnostic) do
    stash_xdoc do 
      deny_xpath( '/AST/Program/SourceElements',
                  build_message(
                    diagnostic,
                    "string <#{_esc source}> should not be well-formed JavaScript"
                 )
              )
    end
  end
end