Forgus / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

Unable to test request attributes in a TagLibSpec #246

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When setting request attributes in my TagLib

request.setAttribute('blockIndex',blockIndex)
request.setAttribute('questionIndex',questionIndex)
request.setAttribute('answerIndex',answerIndex)

Of course the variables all have value at this point, but when testing those 
values in my TagLibSpec. They're all null (In fact there's no attributes in the 
mockRequest). It seems the attribute map has been cleaned before getting to the 
test (The request seems to have the same instance id while debugging the code 
in Eclipse).

mockRequest.getAttribute('blockIndex')
mockRequest.getAttribute('questionIndex')
mockRequest.getAttribute('answerIndex')

Using:

Grails 2.0.0
Spock Plugin :spock:0.6

Note:

I also have tested the code trying the different notation of setting/getting an 
attribute, always with the same result:

request['blockIndex'] = blockIndex

or

request."blockIndex" = blockIndex

Original issue reported on code.google.com by mario.g...@gmail.com on 4 Apr 2012 at 8:28

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
This sounds like a Grails related problem to me. Can you check if the same 
problem exists with JUnit 4? Also make sure not to use any of the Spock 
provided base classes anymore.

Original comment by pnied...@gmail.com on 4 Apr 2012 at 1:59

GoogleCodeExporter commented 8 years ago
This won't be fixed in TagLibSpec.

Please read 
http://grails.org/doc/latest/guide/testing.html#unitTestingTagLibraries

The approach for Grails 2 with regard to unit testing has changed dramatically. 
Spock supports the same @TestFor and @Mock annotations that you see in the 
examples there. These are now part of core Grails and will do a better job than 
the old TagLibSpec.

Original comment by lda...@gmail.com on 15 Apr 2012 at 11:37