title: Passing subjects in Rspec
body: <p>I'm doing my best to wrap my head around Rspec's flow, but the simplest things seem to escape me.</p>
  
  <p>I want to reuse some testing for attribute formatting validity on two different models. So, I thought I would move those Rspec tests to another method and just call the method with the subject being tested. I.e. go from:</p>
  
  <pre><code>  describe "when email format is invalid" do
      it "should be invalid" do
        addresses = %w[user@foo,com user_at_foo.org example.user@foo.
                   foo@bar_baz.com foo@bar+baz.com]
        addresses.each do |invalid_address|
          @user.email = invalid_address
          @user.should_not be_valid
        end
      end
    end
  </code></pre>
  
  <p>To something like this:</p>
  
  <pre><code>  describe "email format checking" do
      valid_email_check(@user)
    end
  </code></pre>
  
  <p>..and in utilities.rb</p>
  
  <pre><code>def valid_email_check(subject)
    describe "when email format is invalid" do
      it "should be invalid" do
        addresses = %w[user@foo,com user_at_foo.org example.user@foo.
                       foo@bar_baz.com foo@bar+baz.com]
        addresses.each do |invalid_address|
          subject.email = invalid_address
          subject.should_not be_valid
        end
      end
    end
  end
  </code></pre>
  
  <p>"subect" is always nil when passed to this function. Any help appreciated.</p>