I was wondering if anyone knows whether it's possible to use FactoryGirl without any of the aforementioned prerequisites.
I would like to use it to generate on-the-fly test data when driving UI automation tests for both mobile and web, and even possibly API.
I know I could create some custom helper classes/methods and use getters and setters, etc., but I thought it would be good to use this awesome little gem.
I have searched quite extensively and also tried to set up a basic RSpec project (I also tried Cucumber), but to no avail. It still appears that I need classes to be instantiated with the relevant login in order to consume it.
FactoryGirl.define do
factory :user do
firstname { Faker::Name.first_name }
lastname { Faker::Name.last_name }
age { 1 + rand(100) }
end
end
Then if I try to call it in a RSpec file...
describe...
it...
user = build_stubbed(:user)
end
end
I have also read the docs and tried all the other variants, I just keep getting...
Failure/Error: user = build_stubbed(:user)
NameError:
uninitialized constant User
which suggests I need a class called User with all the logic.
struct
like this:User = Struct.new :firstname, :lastname, :age
. Good explanation here. – Unopened