質問

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