[rspec-users] controller filters running twice in 1.1.4?

Matt McNeil nabble at mattmcneil.org
Wed Jun 4 03:37:50 EDT 2008

Pat Maddox wrote:
> On Tue, Jun 3, 2008 at 5:31 PM, Matt McNeil <nabble at mattmcneil.org> wrote:
>> since upgrading to 1.1.4 (I had been running without issue on a git
>> snapshot), I'm noticing that my filter actions initiated from
>> application.rb
>> seem to be running twice.  I created a test rails project with the rspec
>> scaffold and am also seeing the same behavior here too.
>> Adding this code to application.rb:
>>  before_filter :foo
>>  def foo
>>    "foo"
>>  end
>> and an example in users_controller_spec.rb:
>>    it "should call foo via a before filter" do
>>      controller.should_receive(:foo)
>>      do_get
>>    end
>> results in this:
>> 1)
>> Spec::Mocks::MockExpectationError in 'UsersController handling GET
>> /users.xml should call foo'
>> Mock 'UsersController' expected :foo with (any args) once, but received
>> it
>> twice
>> script/spec:4:
>> Is any one else seeing this?
> Can you put a print statement inside application.rb to see if the file
> itself is being loaded multiple times?
> Pat
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
Application.rb (and the method called by the before filter) only seem to be
loaded twice when they're being run with autotest/spec.  To reproduce what
I'm showing here:

$ rails -v
Rails 2.1.0

rails test
cd test
script/plugin install git://github.com/dchelimsky/rspec.git
script/plugin install git://github.com/dchelimsky/rspec-rails.git
script/generate rspec
rsg rspec_scaffold User name:string

then add the before_filter :foo to application.rb, the foo method to
users_controller.rb, and the example to users_controller_spec.rb.  


$ /opt/local/bin/ruby -S script/spec -O spec/spec.opts 

Spec::Mocks::MockExpectationError in 'UsersController handling GET /users
should call foo via a before filter'
Mock 'UsersController' expected :foo with (any args) once, but received it

Finished in 0.252162 seconds

35 examples, 1 failure

View this message in context: http://www.nabble.com/controller-filters-running-twice-in-1.1.4--tp17629653p17640917.html
Sent from the rspec-users mailing list archive at Nabble.com.

More information about the rspec-users mailing list