2
測試嵌套的控制器動作
我已經路線設置,看起來像:使用RSpec
match '/things/:thing_id' => "descriptions#index", :as => :thing
resources :things, :except => [:show] do
...
resources :descriptions, :only => [:create, :index]
end
我將如何測試嵌套描述的:create
方法?
到目前爲止,我已經得到了
context "with user signed in" do
before(:each) do
user = Factory.create(:user, :name => "Bob")
controller.stub!(:authenticate_user!).and_return(true)
controller.stub!(:current_user).and_return(user)
end
describe "PUT create" do
before(:each) do
@thing = Factory.create(:thing)
params = {"text" => "Happy Text"}
post thing_descriptions_path(@thing.id), params #Doesn't work
post :create, params #Doesn't work
end
end
end
你有這個代碼的規範的名稱是什麼?它是在things_spec還是descriptions_spec中?它應該在後者中。 –
Descriptions_Controller_Spec – Intentss