0

I have the following test:

require 'rails_helper'

RSpec.describe User, type: :model do
  before {@user = User.new(name: "Example user", email: "mail@mail.com",
                        password: "foobar", password_confirmation: "foobar")}

  subject{@user}

  it { should respond_to(:name) }
  it { should respond_to(:email) }
  it { should respond_to(:password_digest) }
  it { should respond_to(:password) }
  it { should respond_to(:password_confirmation) }
  it { should respond_to (:authenticate) }

  it { should be_valid }
....................................................
describe "return value of authenticate method" do
    before { @user.save }
    let(:found_user) { User.find_by(email: @user.email) }

    describe "with valid password" do
      it { should eq found_user.authenticate(@user.password) }
    end

    describe "with invalid password" do
      let(:user_for_invalid_password) { found_user.authenticate("invalid") }

      it { should_not eq user_for_invalid_password }
      specify { expect(user_for_invalid_password).to be_false }
    end
end

When run bundle exec rspec spec/models/user_spec.rb, it generates the following error:

1) User return value of authenticate method with invalid password should be false
Failure/Error: specify { expect(user_for_invalid_password).to be_false }
expected false to respond to false?
# ./spec/models/user_spec.rb:88:in block (4 levels) in <top (required)>

How do I solve this problem?

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
Stefan Hansch
  • 1,550
  • 4
  • 22
  • 55

0 Answers0