title: Rails RSpec Test Does not Pass Correctly
body: <p>I'm writing model tests with RSpec for a <code>Cookbook</code> model. Each user <code>has_many</code> cookbooks, and each cookbook <code>belongs_to</code> a user. To make sure that a <code>Cookbook</code> could not be created without a user, I wrote the following test:</p>
  
  <pre><code>it "is invalid without a user" do
    expect(FactoryGirl.build(:cookbook, user: nil)).to be_invalid
  end
  </code></pre>
  
  <p>However, when running <code>rspec</code>, I get the following output:</p>
  
  <pre><code>1) Cookbook is invalid without a user
     Failure/Error: expect(FactoryGirl.build(:cookbook, user: nil)).to be_invalid
     NoMethodError:
       undefined method `cookbooks' for nil:NilClass
  </code></pre>
  
  <p>So, then, to test for an error being raised, I made the test like this:</p>
  
  <pre><code>it "is invalid without a user" do
    expect{FactoryGirl.build(:cookbook, user: nil)}.to raise_error(NoMethodError)
  end
  </code></pre>
  
  <p>However, that test also fails with the following output:</p>
  
  <pre><code>1) Cookbook is invalid without a user
     Failure/Error: expect{FactoryGirl.build(:cookbook, user: nil)}.to raise_error(NoMethodError)
       expected NoMethodError but nothing was raised
  </code></pre>
  
  <p>If it means anything, here is the factory for the cookbook:</p>
  
  <pre><code>require 'faker'
  
  FactoryGirl.define do
    factory :cookbook do |f|
      f.title "#{Faker::Name.first_name}'s recipes"
      f.description "#{Faker::Name.last_name}'s favorite recipes."
      f.user 1
    end
  end
  </code></pre>
  
  <p>How should I go about writing the model test so that it makes sure a user is required when creating a <code>Cookbook</code>?</p>