2017-05-02 1 views
0

ハッシュのシーケンスのために実際のものと予想されるもののどちらかに問題があります。私はこれを前に見て回想していない...とにかく私はハッシュが順序付けられていないと思った?RSpecルーティング仕様:ハッシュ内のフィールドのシーケンス

どうすればこのテストに合格することができますか?

RSpec.describe ArticleSectionsController, type: :routing do 
    describe "routing" do 

    it "routes to #index" do 
     expect(:get => "/articles/5/article_sections").to route_to("article_sections#index", article_id: 5) 
    end 
    end 
end 
1) ArticleSectionsController routing routes to #index 
    Failure/Error: expect(:get => "/articles/5/article_sections").to route_to("article_sections#index", article_id: 5) 

     The recognized options <{"controller"=>"article_sections", "action"=>"index", "article_id"=>"5"}> did not match <{"article_id"=>5, "controller"=>"article_sections", "action"=>"index"}>, difference:. 
     --- expected 
     +++ actual 
     @@ -1 +1 @@ 
     -{"article_id"=>5, "controller"=>"article_sections", "action"=>"index"} 
     +{"controller"=>"article_sections", "action"=>"index", "article_id"=>"5"} 

答えて

3

問題は、ハッシュの順序ではない、問題は内容です。

"article_id"=>"5" 

はあなたのroute_toパラメータの

"article_id"=> 5 

お問い合わせ文字列バージョンと同じではありません、それは問題を修正します。

+0

長い日...少なくとも私は怒っていない!ありがとう@SteveTurczyn。 – ardochhigh

関連する問題