factory girl - Using FactoryGirl without Rails, ActiveRecord or any database with RSpec -
i wondering if knows if possible utilize factorygirl without of aforementioned pre-reqs.
i seek , utilize generate on-the-fly test info when driving ui automation tests both mobile , web, , perchance api.
i know create custom helper classes/methods , utilize getters/setters, etc, thought utilize awesome little gem.
i have searched quite extensively , tried setup basic rspec project (also tried cucumber too), no avail. still appears need classes instantiated relevant login in them in order consume it.
factorygirl.define mill :user firstname { faker::name.first_name } lastname { faker::name.last_name } age { 1 + rand(100) } end end
then if seek phone call in rspec file...
describe... it... user = build_stubbed(:user) end end
i have read docs , tried other variants, maintain getting...
failure/error: user = build_stubbed(:user) nameerror: uninitialized constant user
which suggests need class called user logic?
your surmise right -- still have write user
class yourself. factory_girl works fine non-activerecord classes, doesn't write them you.
by default factory_girl constructs instances calling new
no parameters, class should either not def initialize
or initialize
must take no parameters, activerecord model. easiest thing write user
so:
class user attr_accessor :firstname, :lastname, :age end
if decide need initialize
requires parameters, you can utilize factory_girl's initialize_with
tell how instantiate class.
rspec factory-girl
No comments:
Post a Comment