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?
Feature Spec
#spec/features/spree_variants_spec.rb
before(:each) do
user = FactoryGirl.create(:user, first_name: "First name")
helper.stub :spree_current_user => user # does not work
end
Controller
class Designers::SpreeVariantsController < ApplicationController
def create
...
@variant.attribute = spree_current_user.first_name #line 14
...
end
end
Error
Failure/Error: click_button 'Create'
NoMethodError:
undefined method `first_name' for nil:NilClass
# ./app/controllers/designers/spree_variants_controller.rb:14:in `create'
In stubbing the method, I have also tried:
#2
Designers::SpreeVariantsController.stub :spree_current_user => instance_double(Spree.user_class, :has_spree_role? => true, :last_incomplete_spree_order => nil, :spree_api_key => 'fake', first_name: "First name")
#3
self.stub :spree_current_user => user # same error
#4
helper.stub :spree_current_user => user # does not recognize 'helper'