Forum: RSpec Problem with testing Rails action that uses return keyword

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Szymon N. (Guest)
on 2009-05-20 01:49
(Received via mailing list)
Hi,

I'm trying to test Rails action that looks like this:

def create
  unless facebook_session
    authentication_failed and return
  end
  ...
  @facebook_user = facebook_session.user
  ...
end

authentication_failed method redirects to '/'.

The test looks like this:

it 'should call authentication_failed' do
  controller.should_receive(:authentication_failed)
  get :create
end

The problem is that in the test, despite the fact that
facebook_session is nil and the authentication_failed method is
called, the action does not return and I got error in
facebook_session.user line, because facebook_session is nil.

If I move the return keyword to the next line, the test complains then
about missing create.erb template.

Any ideas how to solve it?
David C. (Guest)
on 2009-05-27 12:30
(Received via mailing list)
On Tue, May 19, 2009 at 5:13 PM, szimek <removed_email_address@domain.invalid> 
wrote:
>  ...
> end
>
> authentication_failed method redirects to '/'.
>
> The test looks like this:
>
> it 'should call authentication_failed' do
>  controller.should_receive(:authentication_failed)
>  get :create

If you're using facebooker, you should use facebook_get instead of get:

  facebook_get :create

Also - shouldn't this be a post?
This topic is locked and can not be replied to.