title: how do you stub a local variable in an rspec controller test
body: <p>I've just implemented OmniAuth (using Ryan Bates' Screencast <a href="http://asciicasts.com/episodes/235-omniauth-part-1" rel="nofollow">http://asciicasts.com/episodes/235-omniauth-part-1</a>) and am writing Rspec tests for the functionality and have ran into trouble testing the authentifications#create action. I'm at quite a loss as to how to test this one -- in particular how to stub the local variable omniauth. No matter what I try I keep can't get any tests to work. </p>
  
  <p>Taking a cut down version of the action, how would you test that a new is called on User for example</p>
  
  <pre><code>
  #cut down version of the authentifications controller code I am attempting to test
  
    def create
      omniauth = request.env["omniauth.auth"]
      authentification = Authentification.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])     
      ....
      user = User.new
      ....
    end  
  
  #example test
  
      it "should create a new user" do          
          subject.stub_chain(:request,:env) {{"omniauth.auth" => {'provider' =>1, 'uid' => 2}}}
          User.should_receive(:new)
          post :create
        end
  </pre>
  
  <p></code></p>