4

I recently installed a plugin called Gretel to take care of breadcrumbs for me. It seems to be working great, except that it appears to be breaking some of my specs with the following error:

 Failure/Error: response.should redirect_to @course
 Expected response to be a redirect to </courses/904> but was a redirect to
 <http://test.host/courses/904>

What can I do to get rid of this error? The path seems totally correct, with the exception of that pesky test.host thing.

sapphiremirage
  • 475
  • 2
  • 17

2 Answers2

5

You are probably testing against my_model_url instead of my_model_path

The former does a full URI - including the host. The latter is a relative path without the host.

Go have a check in your controller and see if it uses _path or _url - and use the same one in your test-cases.

Taryn East
  • 27,486
  • 9
  • 86
  • 108
  • 1
    Thanks! As a note to others, it wasn't explicitly obvious that I was checking against a URL in my test. In my controller I had "redirect_to @course" and in my tests I also had "response.should redirect_to @course". Apparently something is different between the two (which I don't quite understand yet), and I needed to more explicitly define the path in the tests as "response.should redirect_to course_path(@course)" in my tests to make it work. – sapphiremirage Jun 21 '11 at 17:05
  • Cool - good to know. I guess the redirect_to(@course) just defaults to the full path. – Taryn East Jun 21 '11 at 18:47
1

You need to expliclty define your request body..Here i have Application that uses rails 3.0...i am using Devise for authentication..and i get a customised domain that user specifies.

#get user from fixtures OR create them

  @user = users(:user1)

  #used devise "sign_in for testing"

    sign_in :user, @user  
  #defined my request

   request.host = 'myblog.free-blog.com'

  #get 'show_blog"

  get 'show'
Taryn
  • 242,637
  • 56
  • 362
  • 405
Milind
  • 4,535
  • 2
  • 26
  • 58