如何通过请求规范传递get变量

时间:2012-09-25 00:31:29

标签: ruby-on-rails rspec

我想在我的rspec调用中传递一个命名变量来匹配

这是路线:

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

这是我所拥有但不起作用的:

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

有什么想法吗?

事先提前

1 个答案:

答案 0 :(得分: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