Вопрос

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