public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
stub the instance method, there is no class method
jeremy (author)
Fri Apr 11 16:44:42 -0700 2008
commit  9a7ab8b05b748932d25d3e05a3d09600afa99f7b
tree    e04a2fee1fa8196dcf3c5d6cdcc202cef3781813
parent  13e784978571b341a2783f95c1a26f4d2d4fd68e
...
41
42
43
44
 
45
46
47
...
41
42
43
 
44
45
46
47
0
@@ -41,7 +41,7 @@
0
     CGI.expects(:new).raises('some multipart parsing failure')
0
 
0
     ActionController::Routing::Routes.stubs(:reload)
0
- Dispatcher..stubs(:log_failsafe_exception)
1
+ Dispatcher.any_instance.stubs(:log_failsafe_exception)
0
 
0
     assert_nothing_raised { dispatch }
0
 

Comments

  • mislav Sat Apr 12 05:30:45 -0700 2008 at actionpack/test/controller/dispatcher_test.rb L45

    Thought I knew all of Mocha :-/

  • tomafro Sat Apr 12 09:54:27 -0700 2008

    If you mean #any_instance, you were better off not knowing. It’s a nasty code smell.

  • joevandyk Sat Apr 12 11:00:58 -0700 2008

    You’re a nasty code smell.

  • josh Tue Apr 15 13:29:28 -0700 2008

    git-bisect says was not a good idea. What handy a little tool.
    9a7ab8b05b748932d25d3e05a3d09600afa99f7b is first bad commit
    commit 9a7ab8b05b748932d25d3e05a3d09600afa99f7b
    Author: Jeremy Kemper
    Date: Fri Apr 11 16:44:42 2008 -0700
    Investigating.

  • lazyatom Tue Apr 15 13:47:15 -0700 2008

    any_instance is useful where you can’t turn the instance (of Dispatcher in this case) into a collaborator (i.e. something that’s passed to a method).

    Another way of getting around using #any_instance is stubbing whatever creates the Dispatcher instance (and probably extracting the creation of the Dispatcher into a method while you do that) to return a known instance (or a stub object).
    However, often that’s more work than one might hope…

  • lazyatom Tue Apr 15 13:47:51 -0700 2008

    (apologies for the weird formatting there, i didn’t realise it was going to use Markdown…)

  • robbyrussell Tue Apr 15 14:28:26 -0700 2008

    @lazyatom:
    NO WORRIES!