Reputation: 1506
I am trying to use assert Equals to check the Url that my User controller redirects to after an action. My test keeps failing with this error:
junit.framework.ComparisonFailure: expected:</todo[]> but was:</todo[/index]>
I just want to check that my function is redirecting to any URL within the /login/ path. Here is my integration test code:
import grails.test.mixin.*
import org.junit.*
/**
* See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions
*/
@TestFor(UserController)
class UserControllerTests extends GroovyTestCase {
User user
UserController uc
void setUp() {
//Save a User
user = new User(userName: "User1", firstName: "User1FN", lastName: "User1LN")
user.save()
//Set up UserController
uc = new UserController()
}
void tearDown() {
user.delete()
}
testHandleLogin(){
//Setup controller paramaters
uc.params.userName = user.userName
//Call the action
uc.handleLogin()
//if the action functioned correctly, it put a user object into the session
def sessUser = uc.session.user
assert sessUser
assertEquals("Expected ids to match", user.id, sessUser.id)
//And the user was redirected to the Todo Page
assertEquals "/login", uc.response.redirectedUrl
}
Is there anyway to use a regular expression, or a method that checks for "/login/(ANYTHING ELSE)"?
Thanks!
Upvotes: 0
Views: 67
Reputation: 75671
How about
assertTrue uc.response.redirectedUrl.startsWith("/login")
Upvotes: 2