[rspec-users] Controller specs and default_url_options

Titinux jeremie.horhant at titinux.net
Mon Jan 16 18:17:54 EST 2012


I'm using Rails 3.1.3 with rspec-rails 2.8.1. I have a scope ':locale'
in routes.rb and I want to run controller and routing
specs. I'm aware of the problem with setting default_url_options in
application.rb controller so I apply the solution found in the last
comment on rspec issue #255 ( https://github.com/rspec/rspec-rails/issues/255

class ActionView::TestCase::TestController
  def default_url_options(options={})
    { :locale => I18n.default_locale }

class ActionDispatch::Routing::RouteSet
  def default_url_options(options={})
    { :locale => I18n.default_locale }

require "spec_helper"

describe CategoriesController do

  describe "GET index" do
    it "assigns all categories as @categories" do
      category = Factory :category

      get :index
      assigns(:categories).to_a.should eq([category])

This test fails with routing error but if I use "get :index,
locale: :fr" instead of just "get :index" the test pass.
This test is a example of controller spec but I have failing tests for
routing and request. (I have no view specs but
I'm pretty sure they would also fail)

I can't figure out where the problem come from and why the patch
doesn't solve it. Is there another thing to do ? (I just put the code
in ./spec/support/default_locale.rb and verify that it loads

Thanks in advance.

More information about the rspec-users mailing list