I’m new to TDD in rails, I’m getting this weird error with
assert_redirected_to.
Here’s my test:
def test_friendship_request_accept
@request.session[:user] = users(:nathan).id
get :accept, { :id => 1 }
assert_redirected_to :controller => “/users/profile”, :action =>
“index”, :id => users(:nathan).id
end
When I run this I get:
RuntimeError: The number of parameters does not match the number of
substitutions. on the assert_redirect_to line.
Any ideas?
blinking bear wrote:
assert_redirected_to :controller => “/users/profile”, :action =>
“index”, :id => users(:nathan).id
RuntimeError: The number of parameters does not match the number of
substitutions. on the assert_redirect_to line.
The point of TDD is to go beyond matching each line of code with an
identical line of test. You should instead accept the redirection,
render
the target page, and then use assert_select to reach in for some
artifact
that shows your data is getting thru to the user.
Look up “integration tests”, then add one for this scenario. And don’t
let
the names fool you - Rails may claim to support functional, integration,
and
unit tests, but they are all just TDD tests. (Those things have strict
QA
definitions that we don’t care about.)
The difference between the test categories is the avaliable “fixtures”,
or
reusable support code. So integration tests will be able to follow you
into
the redirected page.
Any ideas?
Reduce :controller => “/users/profile” to just the name of your
controller;
either :users or :profile. Let the assertion figure out the rest.
–
Phlip
Redirecting... ← NOT a blog!!!