Akos, that is exactly the kind of problem I'm talking about! Right down to the detail about stopping work and returning to the project later, and seeing all the tests pass!
-- Jonathon McKitrick On Tue, Jan 6, 2015 at 3:22 AM, Akos Gyimesi <a...@gyim.hu> wrote: > > On Sat, Jan 3, 2015, at 02:46 AM, Brian Marick wrote: > > > > > I use TDD and mocking/stubbing (conjure) to test each layer of my code. > > > The problem is when I change the function signature and the tests do > not > > > break, because the mocks/stubs do not know when their argument lists no > > > longer agree with the underlying function they are mocking. Is there a > > > way to catch this? Short of a test suite that eschews stubbing in > favor > > > of full setup/teardown of DB data for each test? > > > > Could you give an example? I use mocks fairly heavily, and I don't seem > > to have this problem. Perhaps it's because I change the tests before the > > code? > > Although the subject changed a little bit, I would be still interested > in your approach to refactoring if there is heavy use of mocking. Let me > give you an example: > > Let's say I am writing a login form, trying to use the top-down approach > you described. My approach could be the following: > > (unfinished check-pw) > > (fact "login-form succeeds if user enters the correct password" > (login-form-success? {:username "admin" :password "secret"}) => true > (provided > (db/get-user "admin") => (contains (:password "my-secret-hash")) > (check-pw "my-secret-hash" "secret") => true)) > > (defn login-form-success? [user-input] > (let [user (db/get-user (:username user-input))] > (check-pw (:password user) (:password user-input)))) > > Then I finish the check-pw function and everything works. > > Now, later that day I decide that I pass the whole user object to the > check-pw function. Maybe I want to use the user ID as a salt, or maybe I > just want to leave the possibility for checking password expiration, > etc. So I modify the test and the implementation of check-pw so that the > first parameter is the user object, not the password hash. > > Suddenly my co-worker comes to me saying "hey, I need you on a meeting > right now!" I close my laptop, and an hour later I think "where were > we?..." I run all the tests, and they all pass, so I commit. > > Except... I forgot to modify all the invocations of check-pw in both the > test and the implementation. Every test pass, so I have no way of > finding out the problem without careful code review or by examining the > stack traces from the live code. > > While this bug is easy to catch, what if my function is mocked in > several places, and I fail to rewrite all of them properly? > > Do you have any advice on what you would have done differently here to > avoid this bug? > > Regards, > Akos > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to a topic in the > Google Groups "Clojure" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/clojure/T8fIW27kDYE/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.