title: How to stub Spree's spree_current_user method in an RSpec feature spec?
body: <p>I am trying to stub Spree's current_user method in Rspec 3.0, Capybara 2.3, to no avail. My goal is to test the page for content that should only appear when the user is logged in. How can I stub the spree_current_user helper in a feature spec?</p>
  
  <p><strong>Feature Spec</strong></p>
  
  <pre><code>#spec/features/spree_variants_spec.rb
  before(:each) do
    user = FactoryGirl.create(:user, first_name: "First name")
    helper.stub :spree_current_user =&gt; user # does not work
  end
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>class Designers::SpreeVariantsController &lt; ApplicationController
    def create
      ...
      @variant.attribute  = spree_current_user.first_name  #line 14
      ...
    end
  end
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>Failure/Error: click_button 'Create'
   NoMethodError:
     undefined method `first_name' for nil:NilClass
   # ./app/controllers/designers/spree_variants_controller.rb:14:in `create'
  </code></pre>
  
  <p>In stubbing the method, I have also tried:</p>
  
  <pre><code>#2
  Designers::SpreeVariantsController.stub :spree_current_user =&gt; instance_double(Spree.user_class, :has_spree_role? =&gt; true, :last_incomplete_spree_order =&gt; nil, :spree_api_key =&gt; 'fake', first_name: "First name")
  
  #3
  self.stub :spree_current_user =&gt; user # same error
  
  #4
  helper.stub :spree_current_user =&gt; user # does not recognize 'helper'
  </code></pre>