Forum: RSpec Speccing module which should be included in controller

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.
2101d75ccd71c5dfb984991a7ba53b9b?d=identicon&s=25 Harm (Guest)
on 2009-03-18 16:04
(Received via mailing list)
Dear all,

I have a module ApiAccessControl which is included in all controllers
which deal with the API. It sees if the users is valid, logs etc etc.

I want to see if this module does what it is supposed to but I dont
want to test that in every single controller dealing with the API. So
I created a file api_access_control_spec.rb with this content:

require File.dirname(__FILE__) + '/../spec_helper'

class ApiAccessControlTestController < ApplicationController
  include ApiAccessControl
end

describe ApiAccessControlTestController do
  describe "without valid credentials" do
    it "should respond with a 401 Unauthorized on the GET 'index'" do
      get "index"
      response.response_code.should == 401
    end
  end
end

This works by the grace that my routes file has a fallback map.connect
':controller/:action/:id'. I never use that fallback only for this
particular test. Is there anyway to get rid of this entry in my
routes.rb?

I tried something like this is a before block:
ActionController::Routing::RouteSet.new.add_route("index", :controller
=> "api_access_control_test", :action => "index")

But that doesn't seem to work. How do you guys test this sort of
stuff?

Harm
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2009-03-18 17:36
(Received via mailing list)
On 18 Mar 2009, at 12:03, Harm wrote:

>
>  end
>
> But that doesn't seem to work. How do you guys test this sort of
> stuff?
>
> Harm

See this thread:
http://www.nabble.com/How-to-Spec-a-Module-to-be-u...

It's slow though.

Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com
39100495c9937c39b2e0c704444e1b4a?d=identicon&s=25 Pat Maddox (Guest)
on 2009-03-18 17:59
(Received via mailing list)
On Mar 18, 2009, at 5:03 AM, Harm wrote:

> This works by the grace that my routes file has a fallback map.connect
> ':controller/:action/:id'. I never use that fallback only for this
> particular test. Is there anyway to get rid of this entry in my
> routes.rb?

map.connect ':controller/:action/:id' if RAILS_ENV == 'test'

yahtzee
This topic is locked and can not be replied to.