gqli
gqli

Reputation: 1055

Rspec testing authentication pages couldn't pass

I'm flowing ROR tutorials on chapter 8. I got stuck with testing authentication_pages. I checked with the book three times already, Couldn't found any problem out there. Anyone please take a look , your help will be greatly appreciated!

Failures:

  1) AuthenticationPages signin with valid information 
     Failure/Error: fill_in "Password", with: user.Password
     NoMethodError:
       undefined method `Password' for #<User:0x007fee4d55ed60>
     # ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'

  2) AuthenticationPages signin with valid information 
     Failure/Error: fill_in "Password", with: user.Password
     NoMethodError:
       undefined method `Password' for #<User:0x007fee4d668d50>
     # ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'

  3) AuthenticationPages signin with valid information 
     Failure/Error: fill_in "Password", with: user.Password
     NoMethodError:
       undefined method `Password' for #<User:0x007fee4ba5ed08>
     # ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'

  4) AuthenticationPages signin with valid information 
     Failure/Error: fill_in "Password", with: user.Password
     NoMethodError:
       undefined method `Password' for #<User:0x007fee4d68b008>
     # ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'

Finished in 0.72208 seconds
44 examples, 4 failures

Failed examples:

rspec ./spec/requests/authentication_pages_spec.rb:30 # AuthenticationPages signin with valid information 
rspec ./spec/requests/authentication_pages_spec.rb:31 # AuthenticationPages signin with valid information 
rspec ./spec/requests/authentication_pages_spec.rb:32 # AuthenticationPages signin with valid information 
rspec ./spec/requests/authentication_pages_spec.rb:33 # AuthenticationPages signin with valid information 

authentication_pages_spec.rb file:

require 'spec_helper'

describe "AuthenticationPages" do
    subject { page }
    describe "signin page" do
    before { visit signin_path }
it { should have_content('Sign in') }
it { should have_title('Sign in') }
end
describe "signin" do
    before { visit signin_path }
    describe "with invalid information" do
        before { click_button "Sign in"}

        it { should have_title('Sign in') }
        it { should have_selector('div.alert.alert-error', text: 'Invalid') }

        describe "after visiting another page" do
            before { click_link "Home" }
            it { should_not have_selector('div.alert.alter-error') }
        end
    end
    describe "with valid information" do
        let(:user) { FactoryGirl.create(:user) }
        before do
            fill_in "Email", with: user.email.upcase
            fill_in "Password", with: user.Password
            click_button "Sign in"
        end
        it { should have_title(user.name) }
        it { should have_link('Profile', href: user_path(user)) }
        it { should have_link('Sign out', href: signout_path) }
        it { should_not have_link('Sign in', href: signin_path) }
    end
end
end

sessions_controller.rb file:

  class SessionsController < ApplicationController
    def new
    end
def create
    user = User.find_by(email: params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password])
    else
        flash.now[:error]= 'Invalid email/password combination' # Not quite right!
        render 'new'
    end
end
    def destroy
    end
end

routes.rb file

SampleApp::Application.routes.draw do
  resources :users
  resources :sessions, only: [:new, :create, :destroy]
  root to: 'static_pages#home'
  match '/signup',  to: 'users#new',            via: 'get'
  match '/signin',  to: 'sessions#new',         via: 'get'
  match '/signout', to: 'sessions#destroy',     via: 'delete'
  match '/help',    to: 'static_pages#help',    via: 'get'
  match '/about',   to: 'static_pages#about',   via: 'get'
  match '/contact', to: 'static_pages#contact', via: 'get'
end

Upvotes: 0

Views: 69

Answers (1)

jyrkim
jyrkim

Reputation: 2869

I think apneadiving is right, it looks like it should be lower case. I also had a look at GitHub code for the tutorial

describe "with valid information" do
      let(:user) { FactoryGirl.create(:user) }
      before do
        fill_in "Email",    with: user.email.upcase
        fill_in "Password", with: user.password
        click_button "Sign in"
      end

it's lower case there too. And just make it sure I just also checked Ruby is a case sensitive language, according to the Ruby Programming language book by David Flanagan, Yukihiro Matsumoto.

Upvotes: 1

Related Questions