自動生成したrspecのコードが失敗するときのメモ

rspecの低い(<= 1.2.2)バージョンを前提にgenerateされるコードが多いみたいなので、下記の修正が必要だったりします。


(1)route_forのパラメータは数字(integer)じゃなくて文字列(string)にする

○ route_for(:controller => "comments", :action => "index", :entry_id => "1").should == "/entries/1/comments"
× route_for(:controller => "comments", :action => "index", :entry_id => 1).should == "/entries/1/comments"


(2)route_forの右辺には:methodも含める

○ route_for(:controller => "acts", :action => "update", :id => "1", :manual_id => "1").should
== {:path => "/manuals/1/acts/1", :method => "PUT"}
× route_for(:controller => "acts", :action => "update", :id => "1", :manual_id => "1").should == "/manuals/1/acts/1"

※ GETの場合は文字列のみで良い


(3)formatted_XXX_pathは単にXXX_pathで良い
○ user_path(:id => '1', :format => 'xml').should == "/users/1.xml"
× formatted_user_path(:id => '1', :format => 'xml').should == "/users/1.xml"


参考:
rspec-rails 1.2.2やCucumber 0.2.0にあげるときの作業メモ
Rspec Rails、なんか仕様が変わった?