Skip to content

modify error message when redirected but expecting to render a template #1440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 2, 2015

Conversation

AEgan
Copy link

@AEgan AEgan commented Aug 2, 2015

This change modifies the error message when using expect(response).to have_rendered(:template) when the response is a redirect.

The current error message is

expecting <"template_name"> but rendering with <[]>

This change would modify it to be

expecting <'template_name'> but was a redirect to <(redirect location)>

This will make the problem a bit more clear.

Because the matcher calls assert_template for this, the actual exception is being passed from assert_template to have_rendered, so when the assert_template fails it was just passing the error message along. This change checks to see if the response is a redirect after the assertion fails, and if so replaces the second half of the error message with a message that gives the actual reason for the failure.

@cupakromer
Copy link
Member

Thanks for improving this! 💙 This will definitely help debugging controller specs.

Because the matcher calls assert_template for this, the actual exception is being passed from assert_template to have_rendered, so when the assert_template fails it was just passing the error message along.

😲 Yeah, at some point we really should update our matchers to no rely on those assert_xyz methods.

match_check
end

def check_redirect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a YARD doc comment.

@AEgan
Copy link
Author

AEgan commented Aug 2, 2015

I added a YARD doc and comments, and changed the param name in the spec. Let me know if you want anything modified or if you want me to squash the commits!

@cupakromer
Copy link
Member

Looks good. I think we just need a change log entry. And then merge when this is green.

Also I've opened #1441 so we can make this process easier in the future.

@cupakromer
Copy link
Member

Thanks

cupakromer added a commit that referenced this pull request Aug 2, 2015
modify error message when redirected but expecting to render a template
@cupakromer cupakromer merged commit 85fe74b into rspec:master Aug 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants