我有一個組控制器與方法def inbox.
如何創建驗證JSON響應的rspec測試?
如果用戶是一個組成員,然後收件箱返回一個JSON對象。
如果用戶不是會員,那麼收件箱應重定向感謝CanCan權限。
如何編寫rspec來測試這兩個用例?
電流規格:
require 'spec_helper'
describe GroupsController do
include Devise::TestHelpers
before (:each) do
@user1 = Factory.create(:user)
@user1.confirm!
sign_in @user1
@group = Factory(:group)
@permission_user_1 = Factory.create(:permission, :user => @user1, :creator_id => @user1.id, :group => @group)
end
describe "GET inbox" do
it "should be successful" do
get inbox_group_path(@group.id), :format => :json
response.should be_success
end
end
end
路線:
inbox_group GET /groups/:id/inbox(.:format) {:controller=>"groups", :action=>"inbox"}
routes文件:
resources :groups do
member do
get 'vcard', 'inbox'
end
....
end
謝謝試過,但我得到一個錯誤:「失敗/錯誤:得到:收件箱,:格式=>:json ActionController :: RoutingError: 沒有路由匹配{:controller =>」groups「,:format => :json,:action =>「inbox」} #./controllers/groups_controller_spec.rb:19 「考慮到rake路由會產生一個奇怪的結果:inbox_group GET /groups/:id/inbox(.:format){:controller = >「groups」,:action =>「inbox」} – AnApprentice 2011-05-13 23:28:36
嘗試提供使用url_for獲取的路徑 - http://apidock.com/rails/ActionDispatch/Integration/RequestHelpers/get – Roman 2011-05-13 23:36:38
這會是什麼樣子? – AnApprentice 2011-05-13 23:44:04