mardi 5 mai 2015

undefined method 'body' for nil:Nilclass

I am writing integration test for my application. For the following test, I am getting

undefined method 'body' for nil:Nilclass

My RSpec code:

        it "should not make a new user" do
            visit signup_path
            fill_in "Name", :with => ""
            fill_in "Email", :with => ""
            fill_in "Password", :with => ""
            fill_in "Confirmation", :with => ""
            click_button "Sign up"
            response.should render_template('users/new')
            response.should have_selector("div#error_explanation")
        end

Controller:

class UsersController < ApplicationController
  def new
    @user = User.new
    @title = "Sign Up"
  end

  def show
    @user = User.find(params[:id])
    @title = @user.name
  end

  def create
    @user = User.new(user_params)
    if @user.save
    # Handle a successful save.
        flash[:success] = "Welcome to the Sample App!"
        redirect_to @user
    else
        @title = "Sign Up"
        render 'new'
    end
  end
  def user_params
    params.require(:user).permit(:name, :email, :password, :password_confirmation)
  end
end

What is missing/wrong in this code?

Aucun commentaire:

Enregistrer un commentaire