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?

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top