Kenkuts
Kenkuts

Reputation: 69

Rspec not testing passing tests in regards to redirect

I am in a bootcamp and I cannot seem to pass this test. The project is creating your bootleg version of twitter and the test is:

it 'signup directs user to twitter index' do
  params = {
    :username => "skittles123",
    :email => "[email protected]",
    :password => "rainbows"
  }
  post '/signup', params
  expect(last_response.location).to include("/tweets")
end

My controller that handles this test is below:

 post '/users' do
    @user = User.create(params[:user])
    @error = @user.errors.full_messages

    unless @error == []
      redirect to '/signup'
    else
      session[:user_id] = @user.id
      redirect to '/tweets'
    end
  end

Basically what happens is that when I register a user and the data persists into the database my test should pass cause the expected last_response.location is to include '/tweets' and that is where it redirects to. I don't understand why it's not passing.

Upvotes: 1

Views: 52

Answers (1)

Kenkuts
Kenkuts

Reputation: 69

Because the test was asking for post /signup and instead of using /signup as the route method name after the user posted the information to create the account I used /users. This caused the error.

Upvotes: 1

Related Questions