factory-bot Questions

2

Solved

I have the following factory: FactoryGirl.define do factory :foo do sequence(:name) { |n| "Foo #{n}" } trait :y do sequence(:name) { |n| "Fooy #{n}" } end end end If I run create :foo cr...
Malayan asked 16/6, 2015 at 16:28

1

My frontend is an EmberJS-based app. It's totally async in nature, so testing it with Capybara is pain and misery. On the other hand, Ember provides a fantastic test suite out of the box which make...

1

Putting aside arguments on whether or not you should test existence of a model's associations, I have a model called Order and I am validating that it has at least one item in its has_many associat...
Velda asked 20/6, 2014 at 14:7

5

Solved

I have a model Foo that has_many 'Bar'. I have a factory_girl factory for each of these objects. The factory for Bar has an association to Foo; it will instantiate a Foo when it creates the Bar. I...
Elsi asked 30/5, 2010 at 2:34

1

I'm considering migrating many mocks from FactoryGirl over to the Fabrication gem. However, so far I've been unable to find any information on implementing the trait pattern available in FactoryGi...
Tear asked 5/4, 2015 at 8:48

2

Solved

I have already built some elaborate FactoryGirl factory definitions for testing a Rails project, and for this purpose they are working well. I'd now like to use the same definitions with a script...
Galitea asked 3/4, 2013 at 2:12

2

I am new to Rspec and Factory girl and would like my test to run on a specific database state. I understand I can get Factory girl to create these records, and the objects will be destroyed after t...
Boarish asked 24/1, 2014 at 2:22

1

Solved

I have a factory for user. I want the users to be confirmed by default. But given a trait unconfirmed, I don't want them to be confirmed. While I have a working implementation, which is based on i...
Kim asked 18/2, 2015 at 13:27

1

I'm trying to make a factory for my User model, but when I run rspec, I get Failure/Error: user = build(:user, email: "[email protected]") NameError: uninitialized constant User When I ho...
Conspecific asked 17/2, 2015 at 22:9

3

Solved

If I want to create and instance using "create" build strategy and then want to use "attributes_for" build strategy for verification, is it possible to do? And if I use sequences in the factory? Is...
Frederickfredericka asked 30/11, 2010 at 19:52

1

Any links to documentation proving or disproving my thoughts here would be very appreciated; I can't seem to find any. AFAIK, if you had a Rails application with a Product model, you could define ...
Melodist asked 29/1, 2015 at 19:48

3

This simple example uses DataMapper's before :save callback (aka hook) to increment callback_count. callback_count is initialized to 0 and should be set to 1 by the callback. This callback is invo...
Melisenda asked 3/3, 2013 at 0:10

3

Solved

I have a Family class so defined: class Family < ActiveRecord::Base after_initialize :initialize_family belongs_to :user validates :user, :presence => true validates :name, :presenc...
Eugene asked 6/5, 2011 at 19:32

2

Updated I'm trying to get Factory Girl to fill my "Release Date" field with a date, a random date, frankly any date right now because I keep getting " Validation failed: Release date can't be blank...
Aircondition asked 30/9, 2013 at 11:19

1

Solved

I'm trying to test that my user has a photo value when I upload an image. It works fine in the browser, and the basic functionality of the test passes, but if I try to assert that user.photo is not...

2

Solved

Is it possible for FactoryGirl to define a random number say from 0-10? factory :rating do ranking 1 #random number? recipe end I'd really like the ranking number generated to be a random va...
Merari asked 2/10, 2013 at 16:22

1

I'm trying to user FactoryGirl to create a list of items, but I need the items to not be in order. This is what I have, but I would like it to be DRYer. spec.rb context "three out of order" do b...
Thaliathalidomide asked 18/11, 2014 at 21:43

5

Solved

I am trying to write a test that simulates some return values from Dropbox's REST service that gives me back data in an Array, with a nested hash. I am having trouble figuring out how to code my F...
Swinge asked 5/4, 2012 at 16:54

4

Solved

I work on a project with a structure like: projects/warehouse/core projects/warehouse/products/bottles projects/warehouse/products/boxes In this project, the application logic, gems, etc. are al...
Zomba asked 10/10, 2013 at 14:48

1

Solved

I'm working with FactoryGirl in version 4.4. I'm trying to create after(:create) callbacks but I'm failing on evaluator variables. FactoryGirl.define do factory :organization do name 'example' ...
Wicklow asked 26/8, 2014 at 16:1

1

Solved

In the old version something like this was possible (more examples): Factory.sequence(:email, 50..60) do |n| "user_#{n}@example.com" end Using this in the new FactoryGirl version will create an...
Hairworm asked 18/8, 2014 at 12:27

3

Solved

I have a naked rails 3 app with one model, generated using rails g model User. I've added a factory (using factory_girl_rails): Factory.define :user do |f| f.email "[email protected]" f.pa...
Tacklind asked 10/3, 2011 at 18:53

1

I'm trying to write tests, on which company objects are saved. But, company objects are not saved, and there is no company record on the table. Why and how can I fix the problem? db/schema.rb Act...
Archiearchiepiscopacy asked 26/6, 2014 at 11:3

1

Solved

I am trying to include a custom helper module in all my feature tests. I have tried creating the module in spec_helper.rb, but I get the following error: uninitialized constant FeatureHelper (Name...
Glyndaglynias asked 24/6, 2014 at 9:10

7

Similar to the problem described here: http://rpheath.com/posts/411-how-to-use-factory-girl-with-rspec in Short (shorten'd code): spec_helper: config.use_transactional_fixtures = true config.use...
Wizardly asked 26/7, 2010 at 9:49

© 2022 - 2024 — McMap. All rights reserved.