djcrankypants / spock

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

Spock test fail with NoSuchBeanDefinitionException “No bean named 'grailsLinkGenerator' is defined” where redirect is called #244

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem? If possible, provide source code and
stack trace.
1. Create a controller with 2 method, A, B, and have A redirect to B
2. Create a ControllerSpec that test method A
3. Test will fail with NoSuchBeanDefinitionException

4*. Change parent class from ControllerSpec to UnitSpec will fix the problem.

What version of Spock and Groovy are you using?
Spock 0.6, Grails 2.0.1, Groovy 1.8.6

Attached sample app that illustrate this.

Original issue reported on code.google.com by zsxking on 29 Mar 2012 at 7:12

Attachments:

GoogleCodeExporter commented 8 years ago
Simply changing the inheritance of the test from ControllerSpec to UnitSpec 
does no fix the problem (point 4), as references to controller.redirectArgs, 
mockParams etc. are now broken.  Is there a known alternative?

Original comment by alexande...@gmail.com on 10 Apr 2012 at 1:24

GoogleCodeExporter commented 8 years ago
The old Spock unit testing support is effectively deprecated and *should not* 
be used with Grails 2.

Grails 2 introduced an entirely new testing mechanism that is owned/maintained 
by Grails core. You should use this wherever possible.

Please see: 
http://grails.org/doc/latest/guide/testing.html#unitTestingControllers

The approach is exactly the same (e.g. the use of the annotations). So you just 
need to adapt them to Spock, which means extending spock.lang.Specification and 
not ControllerUnitTestSpec.

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

GoogleCodeExporter commented 8 years ago
Ok, thanks for the heads up.  This is one of a number of issues I've had with 
using the old style tests in Grails 2.  Is there a standard place to post such 
error messages?  They're mostly very opaque, so a big sign pointing from them 
to the fact that old grails testing is deprecated could be very helpful for 
anyone else getting bogged down in this.

Original comment by alexande...@gmail.com on 20 Apr 2012 at 1:43

GoogleCodeExporter commented 8 years ago
e.g.
| Error Error running script test-app functional: FolderList: cannot find 
shared instance field (Use --stacktrace to see the full trace)

Original comment by alexande...@gmail.com on 20 Apr 2012 at 1:44

GoogleCodeExporter commented 8 years ago
Given that the old unit testing support is only deprecated for Grails 2.0, and 
the plugin also supports 1.3, we probably cannot print any deprecation warnings 
at this time.

Original comment by pnied...@gmail.com on 12 May 2012 at 12:56

GoogleCodeExporter commented 8 years ago
Closing as WontFix as the ControllerSpec class is not compatible with Grails 2.

Original comment by lda...@gmail.com on 14 May 2012 at 7:36