Sha256: fabced5651217064e86002f0fa5a6260d8d50ba1727b4b31afd0fbc88dc0f50b
Contents?: true
Size: 1.6 KB
Versions: 5
Compression:
Stored size: 1.6 KB
Contents
module RespondsToParent module SelectorAssertion # :call-seq: # assert_select_parent() # assert_select_parent() { |script| ... } # # Selects JavaScript that is generated for the `parent' window. # # Without a block, #assert_select_parent asserts that the response # is generated by responds_to_parent. # # With a block, #assert_select_parent selects script that is supposed # to be evaluated in the parent window and passes it to the block. # Typically #assert_select_rjs is used in the block. def assert_select_parent(*args, &block) wrapper_re_str = Regexp.escape("with(window.parent) { setTimeout(function() { window.eval('") + "(.*)" + Regexp.escape("'); window.loc && loc.replace('about:blank'); }, 1) }") match = @response.body.match(Regexp.new(wrapper_re_str)) if match escaped_js = match[1] unescaped_js = escaped_js. gsub(%r!</scr"\+"ipt>!, '</script>'). gsub(/\\(\'|\")/, '\1'). gsub(/((?:^|[^\\])(?:\\\\)*)\\n/, "\\1\n"). # replace `n' with odd number of backslash. gsub(/\\\\/, '\\') @response.body = unescaped_js # assert_select_rjs refers @response.body. if block_given? begin in_scope, @selected = @selected, unescaped_js yield unescaped_js ensure @selected = in_scope end end unescaped_js else # doesn't seem a responds_to_parent content. flunk args.shift || "No content for the parent window." end end end end
Version data entries
5 entries across 5 versions & 3 rubygems