Thursday, March 13, 2008

Source Code for that Testing Library


Ring the bells that still can ring
Forget your perfect offering 
There is a crack in everything
That’s how the light gets in.
  —Leonard Cohen



Yesterday, I posted on a trivial little testing library I hacked together.I’ve put the source online. Get the source through Rob’s git repository (see below).


In the meantime, I discovered a problem with the idea of intercepting comparison operators, the technique used by the expect method. Ruby doesn’t really have != and !~ methods. Instead, the parser maps(a != b) into !(a == b). This means that the ComparisonProxy cannot intercept calls to either of these. This is a problem because


   expect(1) != 1

actually passes, because it becomes !(expect(1) == 1), and the expect method is happy with that.


I’m betting there’s a way around this…


Update: 14:26 CDT.


  • Rob Sanheim has set up a Git repository for the code. He says

    I’ve put this up on github to watch what forks or releases develop around it.


    git clone git://github.com/rsanheim/prag_dave_testing.git




  • Michael Neumann suggested a way around the negated == and =~ tests using source inspection:


    class ComparatorProxy
    def ==(obj)
    # try to get the source code position of the call
    # and see if it's a != or a ==
    end
    end


No comments:

Post a Comment