title: Testing model finder methods in rspec
body: <p>Ruby newbie here trying to get to grips with rspec, rails, cucumber.</p>
  
  <p>I'm not sure why this is returning the following error:</p>
  
  <pre><code>1) User can be found by username
  Failure/Error: user.should_not be_valid
  NoMethodError:
      undefined method `valid?' for nil:NilClass
      # ./spec/models/user_spec.rb:26:in `block (2 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>From the following model spec file:</p>
  
  <pre><code>require 'spec_helper'
  
  describe User do
    let(:user) { User.new(
        :username =&gt; 'username',
        :password =&gt; 'password'
      )
    }
  
    it "should be createable" do
      user.should be_valid
    end
  
    it "cannot have an empty username" do
      user.username = nil
      user.should_not be_valid
    end
  
    it "cannot have an empty password" do
      user.password = nil
      user.should_not be_valid
    end
  
    it "can be found by username" do
      user = User.find_by_username('username')
      user.should be_valid  
    end
    it "can be deleted"
  end
  </code></pre>
  
  <p>I'm sure it's something simple but I can't figure it out?</p>