简体   繁体   中英

rspec test doesn't seem to connect

I was taking a look at the ol hartl tutorial and even though he goes a little crazy with the testing, I've been able to follow so far until I hit this one test that is a bit confusing to me. I was wondering if one of you more experienced devs can share his logic for this test :

  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

To me, it looks like he is creating a variable defined with a return value of a user with invalid authentication.

He then takes said variable and says it should not equal itself.

Then he also says that same variable should be false.

For transparency, here is the complete test :

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

Can someone explain where I misunderstood? Thanks!!

I'm pretty sure there's some context missing here. The it is being used implicitly, which means RSpec already has a subject in mind. It determines the subject a number of ways, some implicitly (based on class and describe block names, among other things), and some explicitly, via the subject keyword. It's likely that there's a subject defined outside the describe block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM