0
votes

I followed all the instructions in chapter 7 Ruby on Rails tutorial, when I finally run $ Bundle exec rspec spec/ a series of errors are being displayed. I doubled checked if my codes had any spelling mistakes or any symbols left out. Everything seems to fine. Could you please kindly interpret the errors and tell me where I am going wrong??? Thanks

USER_PAGES_SPEC.RB

require 'spec_helper'

describe "User pages" do

  subject { page }

  describe "signup page" do
  before {visit signup_path}

    it { should have_selector('h1',    text: 'Sign ') }
    it { should have_selector('title', text: full_title('Sign up')) }
  end

 describe "profile page" do
    let(:user) { FactoryGirl.create(:user) }

    before { visit user_path(user) }

    it { should have_selector('h1',    text: user.name) }
    it { should have_selector('title', text: user.name) }
  end

   describe "signup" do

    before { visit signup_path }

    let(:submit) { "Create my account" }

    describe "with invalid information" do
      it "should not create a user" do
        expect { click_button submit }.not_to change(User, :count)
      end
    end

    describe "with valid information" do
      before do
        fill_in "Name",         with: "Example User"
        fill_in "Email",        with: "[email protected]"
        fill_in "Password",     with: "foobar"
        fill_in "Confirmation", with: "foobar"
      end

      it "should create a user" do
        expect { click_button submit }.to change(User, :count).by(1)
      end

      describe "after saving a user" do
        before {click_button submit}

        let (:user) {user.find_by_email("[email protected]")}

        it {should have_selector('title', text:user.name)}
    end
  end
end
end

USER_CONTROLLER.RB

class UsersController < ApplicationController

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

  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])

    if @user.save

    sign_in @user

    flash[:success] = "Welcome to the Sample App!"

    redirect_to @user

    else

     render 'new'
    end
  end
end

ERRORS DISPLAYED ON COMMAND LINE

    3) User pages signup page
 ←[31mFailure/Error:←[0m ←[31mit { should have_selector('title', text: full_

title('Sign up')) }←[0m ←[31mNoMethodError:←[0m ←[31mundefined method full_title' for #<RSpec::Core::ExampleGroup::Neste d_2::Nested_1:0x461b260>←[0m ←[36m # ./spec/requests/user_pages_spec.rb:11:inblock (3 levels) in '←[0m

4) User pages profile page ←[31mFailure/Error:←[0m ←[31mit { should have_selector('title', text: user. name) }←[0m ←[31mexpected css "title" with text "Michael Hartl" to return something←[ 0m ←[36m # ./spec/requests/user_pages_spec.rb:19:in `block (3 levels) in '←[0m

5) User pages signup with valid information should create a user ←[31mFailure/Error:←[0m ←[31mexpect { click_button submit }.to change(User, :count).by(1)←[0m ←[31mNoMethodError:←[0m ←[31mundefined method sign_in' for #<UsersController:0x45a8f00>←[0m ←[36m # ./app/controllers/users_controller.rb:14:increate'←[0m ←[36m # (eval):2:in click_button'←[0m ←[36m # ./spec/requests/user_pages_spec.rb:43:inblock (5 levels) in '←[0m ←[36m # ./spec/requests/user_pages_spec.rb:43:in `block (4 levels) in '←[0m

6) User pages signup with valid information after saving a user ←[31mFailure/Error:←[0m ←[31mbefore {click_button submit}←[0m ←[31mNoMethodError:←[0m ←[31mundefined method sign_in' for #<UsersController:0x46341c0>←[0m ←[36m # ./app/controllers/users_controller.rb:14:increate'←[0m ←[36m # (eval):2:in click_button'←[0m ←[36m # ./spec/requests/user_pages_spec.rb:47:inblock (5 levels) in '←[0m

1
Do you have a models/user.rb?mu is too short
@muistooshort Hi Thanks for the help. I thought my user.rb file was saved but apparently it wasnt! But I have new 4 errors :( , I have updated the query with the new errors , if you get a chance please kindly help me. Thanksuser1422120

1 Answers

0
votes

1) undefined method full_title

Are you defined it?

2) expected css "title" with text "Michael Hartl" to return something

You haven't <title>Michael Hartl</title> in output html.

3, 4) undefined method sign_in

Where are you defined it?

Correct your code and all tests will be passed.