title: Rails rspec and omniauth (integration testing)
body: <p>My Rails 3.2 app uses OmniAuth and Devise to sign in with Twitter. The authentication system works fine. I would like to write an integration test in rspec to make sure everything works. Using the information in the wiki, I've written the following, but I know I'm missing things. </p>
  
  <p>Under test.rb in config/environments, I have the following lines</p>
  
  <pre><code>OmniAuth.config.test_mode = true
  OmniAuth.config.mock_auth[:twitter] = {:provider =&gt; 'twitter', :uid =&gt; '123545'}
  </code></pre>
  
  <p>My rspec test looks like this:</p>
  
  <pre><code>describe "Authentications" do
    context "without signing into app" do
  
      it "twitter sign in button should lead to twitter authentication page" do
        visit root_path
        click_link "Sign in with Twitter"
        Authentication.last.uid.should == '123545'
      end
  
    end
  end
  </code></pre>
  
  <p>Authentication is the name of my model and calling .uid in rails console returns the string fine. </p>
  
  <p>I'm getting the following error when I run this test:</p>
  
  <pre><code>Failure/Error: Authentication.last.uid.should == '123545'
  NoMethodError:
  undefined method `uid' for nil:NilClass
  </code></pre>
  
  <p>Can anyone help me figure out how to use the OmniAuth mocks that are provided? An explanation for <em>why</em> and <em>how</em> it works would be appreciated as well. </p>