2012-09-25 66 views
0

我想傳遞一個命名變量在我的RSpec調用匹配如何通過通過要求規格

這是路線得到變量:

match '/api/get-pairings/:global_id' => 'api#get_pairings', :as => :get_pairings 

這是我沒有按,但是」 t工作:

it "should get pairings for a specific id" do 
    {:get => get_pairings_path, :global_id => 1000 }.should route_to(:controller => "api", :action => "get_pairings") 
    {:get => get_pairings_path, :params => { :global_id => 1000 } }.should route_to(:controller => "api", :action => "get_pairings") 
end 

任何想法?

THX提前

+0

怎麼樣':GET => get_pairings_path(:global_id => 1000)'? –

回答

1

您需要的變量傳遞給_path方法的規範工作:

it "should get pairings for a specific id" do 
    {:get => get_pairings_path(:global_id => 1000) }. 
    should route_to(:controller => "api", 
        :action => "get_pairings", 
        :global_id => "1000") 
end 
+0

thx - 以爲我曾試過這個,但這個工程。 – timpone

+0

太棒了!這是否意味着它被接受? ;) –