Rspec to skip devise action in controller - sign_in_and_redirect

rtd*_*tdp 1 ruby tdd rspec ruby-on-rails devise

I have integrated rails application with omniauth and devise integration. In one the controller I have -

def create
     # some 
     # stuff 
     # here
   sign_in_and_redirect(:person, @person)
     # some 
     # stuff 
     # here
 end 
Run Code Online (Sandbox Code Playgroud)

as this action is from devise, i shouldn't be testing this action but only presence of it(correct me here if i am wrong.). Also, as I am mocking this person object, it doesn't have methods to pass origin sign_in_and_redirect action.

So, how can test this controller ?

UPDATE

I tried this in my before do block -

controller.stub!(:sign_in_and_redirect).and_return(true)
Run Code Online (Sandbox Code Playgroud)

But this give me error as - Missing templace authentications/create I don't have any create.html.erb, as it redirects in normal workflow.


UPDATE

My AuthencationController#create method code can be seen here - http://www.pastie.org/2116067 My Test code can be seen here - http://www.pastie.org/2116081

rtd*_*tdp 5

最后我发现它与设计有关。

这解决了问题 - 设计维基 -如何:使用 Rails 3(和 rspec)进行控制器和视图测试

我必须包含 support/devise.rb 文件和以下几行 -

RSpec.configure do |config|
   config.include Devise::TestHelpers, :type => :controller
end
Run Code Online (Sandbox Code Playgroud)

之后,我只是通过存根将所需的方法添加到 person 类中,并且它起作用了。