assert_params
When the test fails, upgrade the source to pass in those data:
def decode(ypath) ypath =~ /^node(:.*)/ return $1.gsub(':', '//') end ... href = { :id => 'link_'+ypath, :url => { :action => 'display_iframe', :page_name => page_name, :ypath => decode(ypath) } } @x << @page.link_to_remote($1, href)
That triggers an error message, which tells us how to upgrade the test:
assert_xpath 'Statement[1]//ArgumentList[1]' do |node|
assert_equal
'/wiki/display_iframe?ypath=%2F%2Ftest_uncle_wiggily&page_name=WikiTestPage',
assert_argument(1)
end
The front-slashes were predictably escaped as %2F
, and the arguments arrived in a different
order.
Patching that test case isn't good enough. For every feature in our code, including the systems that generate a URI's path and query segments, we need a matching feature on the test side:
def assert_params(path_query) path, query = path_query.split('?') params = {} if query query.split('&').each do |item| key, value = item.split('=') params[key.to_sym] = CGI::unescape(value) end end return [path, params] end def test_test_nodes_link_to_display_iframe render_wiki(get_omap) assert_xpath '//strong/a[ . = "test" ]' do |a| assert_equal '#', a.href assert_js 'ajax = ' + a.onclick do assert_xpath 'Statement[1]//ArgumentList[1]' do command, params = assert_params(assert_argument(1)) assert_equal '/wiki/display_iframe', command assert_equal '//test_uncle_wiggily', params[:ypath] assert_equal 'WikiTestPage', params[:page_name] end end end end
And that ...
Get Test Driven Ajax (on Rails) now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.