On Mon, Apr 21, 2008 at 8:27 AM, Andy Croll <[EMAIL PROTECTED]> wrote: > How would I go about writing specs for methods in the Application > Controller: > > I'm thinking of simple methods that do authentication, through before > filters or for example how might I spec this method in an > application_spec.rb? > > def store_location > session[:return_to] = request.request_uri > end > > The trouble is I'm not generating a request object as the methods are to > be used by all controllers... I've tried stubbing... > > request = mock_model(URI::HTTP, :request_uri => "something") > > ...or setting the variable in the spec itself... > > request.response_uri = "something" > > ...but I can't seem to get the approach right!
Hey Andy, You can define a controller method on the fly in order to test this out. I just did a quick experiment to demonstrate it...obviously modify to suit your needs. application_controller_spec.rb: require File.dirname(__FILE__) + '/../spec_helper' describe "a before_filter" do class FooController < ApplicationController def index; render :text => "foos"; end end controller_name :foo it "should work" do get :index assigns[:assigned].should_not be_blank end end application.rb: class ApplicationController < ActionController::Base before_filter :set_assigned def set_assigned @assigned = "yay" end end _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users