How do you create an rspec testing for a self.method?

rspec, ruby-on-rails

Solution

describe User do
  let(:user) { User.create(:email => "foo@bar.com", :password => "foo") }

  it "authenticates existing user" do
    User.authenticate(user.email, user.password).should eq(user)
  end

  it "does not authenticate user with wrong password" do
    User.authenticate(user.email, "bar").should be_nil
  end
end

Problem

I currently have this method in my `User` class: ``` def self.authenticate(email, password) user = User.find_by_email(email) (user && user.has_password?(password)) ? user : nil end ``` How do I run rspec testing on this? I tried to run `it { responds_to(:authenticate) }`, but I assume the self thing is different from the authenticate. I am still a beginner at rails and any tips on how to test and explanation on the `self` keyword will be much appreciated!

Original source