开发者

rspec not calling my custom action on a namespace'd rails 3 controller?

开发者 https://www.devze.com 2023-02-04 18:07 出处:网络
i\'m having an issue testing a rails 3 admin controller. it appears that the controller action is not even being called.i\'ve tested this by having the action explicitly throw an exception, and the te

i'm having an issue testing a rails 3 admin controller. it appears that the controller action is not even being called. i've tested this by having the action explicitly throw an exception, and the test does not show this fact.

with the following code, my test passes. the exception should cause the test to fail if my_custom_action was actually called.

controllers/admin/things_controller.rb

class Admin::ThingsController < Admin::AdminController
  def my_custom_action
    raise 'thi开发者_开发问答s should be bad'
  end
end

spec/controllers/admin/things_controller_spec.rb

describe Admin::ThingsController do
  it "shouldn't work!" do
    post :my_custom_action
  end
end 

config/routes.rb

namespace :admin do
  resources :things do
    post :my_custom_action, :on => :collection
  end
end

whenever i remove the route the test fails with a "no matching route" error, so i'm quite confused about why it seems that when the route is defined the action is not getting called

what am i missing in order to test namespace'd routes via rspec?


Exception thrown and not caught in the Controller process (server) are not re-thrown at the rspec side by default, usually you should check response (that is not 200 ok in that case):

post :something_wrong
response.should be_ok
0

精彩评论

暂无评论...
验证码 换一张
取 消