Cucumber は :delete %> をハンドリング出来る

Cucumber は 内部で Webrat を使い、生成されたHTMLをチェックしたり、ボタン・リンクの動作をシミュレーションしています。 したがって、Javascriptを使ったページはテスト出来ません。

http://cukes.info/images/cuke_logo.png


Railsで削除等には <%= link_to 'Destroy', todo, :confirm => 'Are you sure?', :method => :delete %> というタグが使われますが、これは以下のようなHTMLに展開されます。

<a href="/todos/3" onclick="if (confirm('Are you sure?')) 
{  var f = document.createElement('form');
   f.style.display = 'none'; this.parentNode.appendChild(f);
   f.method = 'POST';
   f.action = this.href;
   var m = document.createElement('input');
   m.setAttribute('type', 'hidden');
   m.setAttribute('name', '_method');
   m.setAttribute('value', 'delete');
   f.appendChild(m);
   var s = document.createElement('input');
   s.setAttribute('type', 'hidden');
   s.setAttribute('name', 'authenticity_token');
   s.setAttribute('value', 'Bl9qumlN+C5TCFQIeSdEkIov/8XQkFXS4JcjtkCA5tE=');
   f.appendChild(s);
   f.submit();
};
  return false;">Destroy</a>

このHTMLにはJavascriptが含まれているので、Webrat(Cucumber)ではテスト出来ないと思っていたのですが・・・・
先ほど、Webratのコードを読んでいたら、なんとmethod や authenticity_token をハンドリングするコードがあるではないですか!


早速、Cucumberの 削除(<%= link_to ... :method => :delete %>)のシナリオを書いてみたのですが、動作しました !!
もちろん、ダイアログによる確認はありません (::) (::)