keeganwitt / gmock

Automatically exported from code.google.com/p/gmock
6 stars 2 forks source link

Empty static expectations should not appear in error messages #31

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following test should pass:

    void testEmptyStaticExpectationsShouldNotAppearInErrorMessages() {
        def mockLoader = mock(Loader)
        mockLoader.static.one()
        mockLoader.static
        def expected = "Unexpected static method call 'Loader.two()'\n" +
                       "  'Loader.one()': expected 1, actual 1"
        play {
            Loader.one()
            def message = shouldFail(AssertionFailedError) {
                Loader.two()
            }
            assertEquals expected, message
        }
    }

Original issue reported on code.google.com by JohnnyJianHY on 29 Nov 2008 at 3:21

GoogleCodeExporter commented 9 years ago

Original comment by julien.g...@gmail.com on 29 Nov 2008 at 7:11

GoogleCodeExporter commented 9 years ago
Started. But it might wait for tomorrow.

Original comment by julien.g...@gmail.com on 29 Nov 2008 at 7:17

GoogleCodeExporter commented 9 years ago
I think we should catch some kind of missing expectation. We shouldn't let 
people write:

mockLoader.static

It doesn't mean much. We should validate it at the beginning of the play 
closure. 

I am changing the test to something like:

def mockLoader = mock(Loader)
mockLoader.static.one()
mockLoader.static

def expected = "Missing static expectation for Loader" 
def message = shouldFail(AssertionFailedError) {
  play {}
}
assertEquals expected, message

Original comment by julien.g...@gmail.com on 30 Nov 2008 at 10:15

GoogleCodeExporter commented 9 years ago
The best solution is to throw an exception on the line of "mockLoader.static", 
then 
the user can easily locate it. But I know it is hard (maybe impossible) to 
implement, so let's just validate at the beginning of the play closure.

And please also do that to the missing property expectations.

Original comment by JohnnyJianHY on 30 Nov 2008 at 10:43

GoogleCodeExporter commented 9 years ago
Yep I agree, ideally we would like to throw an exception on the correct line 
and I
agree it seems impossible to implement.

Original comment by julien.g...@gmail.com on 30 Nov 2008 at 10:47

GoogleCodeExporter commented 9 years ago

Original comment by julien.g...@gmail.com on 30 Nov 2008 at 12:07