2011-07-14 3 views
3

だから私はこのようになりますルートがあります。RoutingError

scope "4" do 
    scope "public" do 
    scope ":apikey" do 
     resources :shops 
    end 
    end 
end 

そして、このようになります。その一例が、コントローラの仕様の束、:

describe ShopsController do 

    describe "when responding to a GET" do 

    context "#new" do 
     it "should create a new instance of the shop class" do 
     get :new 
     @shop.should_not_be_nil 
     end 
    end 

    end 

end 

をレーキルートでは、ウェブブラウザを介して、このコントローラ/アクションは正常に動作します。しかし、RSpec throw:

1) ShopsController when responding to a GET#new should create a new instance of the shop class 
Failure/Error: get :new 
ActionController::RoutingError: 
    No route matches {:controller=>"shops", :action=>"new"} 
# ./spec/controllers/shops_controller_spec.rb:9:in `block (4 levels) in <top (required)>' 

私はルートからscopeステートメントを削除すると、テストは正常に動作します。ルートスコープのRSpecに「通知」する方法はありますか?

ありがとうございます!あなたのルートによると

答えて

6

:apikeyはあなたの得るためにそれを追加する必要があるので、必要なパラメータです:

get :new, :apikey => "something" 

また、あなたはこれにあなたの次の行に期待を変更する必要があります。

assigns[:shop].should_not be_nil 

assignsを使用してコントローラのインスタンス変数を確認し、アンダースコアではなくスペースでマッチャからshould_notを区切ります。その最後のビットは慣れていくものです。

+0

はチャンピオンのように働いた。ありがとうございました! – ianm

関連する問題