Problem running test controller in Rails 4

Asked

Viewed 68 times

1

Good afternoon,

I generated a scaffold of a class of mine, User example. While running the tests I came across the following failure:

Minitest::Assertion: "User.count" didn't change by 1.
 Expected: 3
  Actual: 2
test/controllers/users_controller_test.rb:20:in `block in <class:UsersControllerTest>' 

the code for this error is:

test "should create user" do
  assert_difference('User.count') do
    post :create, user: { name: 'teste', password: 'secret', password_confirmation: 'secret' }
  end
  assert_redirected_to user_path(assigns(:user))
end

This is the code generated by scaffold, I just changed the name reference.

As far as I can tell, the create is not being executed. I already put a brakpoint in the controller create but not there.

Am I doing something wrong?

Thanks for your help

  • "I just changed the name reference" What do you mean? I didn’t understand what you changed. Maybe this caused the problem. Post also the model code and User controller.

1 answer

1


I managed to solve the problem,

I had forgotten to put the user in the session

  • I’ve already made this mistake too =) Just mark your answer as the correct one to help anyone searching for the question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.