Question

I have a :fakeUser factory defined in factories/user.rb, which I use in user_spec.rb correctly.

I want to be able to do the same, create(:fakeUser), in another rspec file potato_spec.rb.

How can I do this?

Was it helpful?

Solution

require 'spec_helper'

feature "your potato test" do    
    let!(:fakeUser ) { FactoryGirl.create(:fakeUser ) }

    context "your test context" do

        #...the actions you want to test
    end
end

Within the context you may have different scenarios, for example "when user is logged in" or "when user is guest".
Provided that you have a factory users.rb like this:

FactoryGirl.define do
    factory :fakeUser do
      name 'John'
      #... other attributes you might have for the user
    end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top