James Mead
2007-Apr-11 14:37 UTC
[mocha-developer] Fwd: [ mocha-Feature Requests-5856 ] Stubbing of private methods should be allowed
---------- Forwarded message ---------- From: noreply at rubyforge.org <noreply at rubyforge.org> Date: 11-Apr-2007 15:31 Subject: [ mocha-Feature Requests-5856 ] Stubbing of private methods should be allowed To: noreply at rubyforge.org Feature Requests item #5856, was opened at 2006-09-22 17:03 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=7480&aid=5856&group_id=1917 Category: None Group: None Status: Open Priority: 3 Submitted By: Christian Romney (xmlblog) Assigned to: Nobody (None) Summary: Stubbing of private methods should be allowed Initial Comment: I have a private method in my Rails controller that does some processing. Based on the return value of this method, a particular action decides what to do. I do not want to make this method public, because public methods in a controller are callable from a URL. Below is a patch to enable stubbing of private methods. Index: lib/stubba/instance_method.rb ================================================================== --- lib/stubba/instance_method.rb (revision 57) +++ lib/stubba/instance_method.rb (working copy) @@ -13,8 +13,9 @@ # intentionally empty end - def exists? - stubbee.respond_to?(method) + def exists? + #stubbee.respond_to?(method) + (stubbee.methods | stubbee.private_methods).include?(method.to_s) end end ---------------------------------------------------------------------->Comment By: James Mead (jamesmead)Date: 2007-04-11 14:31 Message: I don''t know whether you have noticed, but this has accidentally become possible in more recent versions of Mocha! However, I intend to reintroduce the restriction soon. Stubbing private methods is not in general a good idea, because it couples your test to the internal implementation of the class under test. Have you considered moving the method into another class e.g. an appropriate model class. See Jamis Buck''s blog posts like this one - http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model. ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=7480&aid=5856&group_id=1917 -- James. http://blog.floehopper.org
Reasonably Related Threads
- Fwd: [ mocha-Bugs-5892 ] Using a setup method in test_case_class destroys subsequent test cases
- Mocking Time, delegating to original object
- Mocha 0.4 released
- Problem with RSpec and Mocha/Stubba
- Fwd: [ mocha-Feature Requests-13763 ] add with_any_arguments method