keeganwitt / gmock

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

Mocking Closure #54

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Suppport for mocking closure like:

mockSomeone.count(invoke(1, 2) {
  it.put(3)

}.returns(3)) 

Original issue reported on code.google.com by julien.g...@gmail.com on 3 Feb 2009 at 6:34

GoogleCodeExporter commented 8 years ago

Original comment by julien.g...@gmail.com on 3 Feb 2009 at 6:35

GoogleCodeExporter commented 8 years ago
I still worry about that the users may be confused by the different means of 
"returns".

Original comment by JohnnyJianHY on 4 Feb 2009 at 3:09

GoogleCodeExporter commented 8 years ago
Even if they are slightly different context both returns have the same meaning. 
I
think users would instinctively understand this returns when used to the rest 
of the api.

Original comment by julien.g...@gmail.com on 4 Feb 2009 at 7:48

GoogleCodeExporter commented 8 years ago
IMO, they have different meanings:

1. If this method is called, THEN return this value
2. While this closure is returned, the result SHOULD be this value

Original comment by JohnnyJianHY on 4 Feb 2009 at 7:56

GoogleCodeExporter commented 8 years ago
I understand they've got slight different meaning but a normal user would use 
the
returns keyword he keep using everywhere.
1. Method called -> returns value
2. Closure called -> returns value

Original comment by julien.g...@gmail.com on 4 Feb 2009 at 8:03

GoogleCodeExporter commented 8 years ago
OK then.

Original comment by JohnnyJianHY on 4 Feb 2009 at 9:33

GoogleCodeExporter commented 8 years ago

Original comment by JohnnyJianHY on 6 Mar 2009 at 12:08

GoogleCodeExporter commented 8 years ago

Original comment by julien.g...@gmail.com on 26 Apr 2009 at 9:28

GoogleCodeExporter commented 8 years ago
Issue 107 has been merged into this issue.

Original comment by JohnnyJianHY on 19 Feb 2011 at 11:04

GoogleCodeExporter commented 8 years ago
A more complex example:

def m = mock()
m.unless(
  invoke(3) { // a closure should be passed to unless() as parameter
              // and invoke the closure with parameter "3"
    current().returns(3) // expect current() to be called in the closure
  }.returns(true) // expect the closure to return true
).returns(false)

play {
  assert !m.unless { it == current() }
}

Original comment by JohnnyJianHY on 19 Feb 2011 at 11:07