Questions tagged [fabrication-gem]

Fabrication is a fixture replacement library for Ruby.

Fabrication allows you to define schematics for objects and generate valid instances of them on demand in your tests, seeds, or anywhere else. It works with any Ruby object but actively supports ActiveRecord, Mongoid, Sequel, and DataMapper objects.

It is fast, lightweight, and with no gem dependencies at all so you can use it anywhere you want.

69 questions
25
votes
4 answers

Comparing Factory Girl with Fabrication

There seems to be few resources about the fabrication gem, and I couldn't find a good comparison of the features that distinguish it from factory_girl. As of versions fabrication-2.2.3 and factory_girl-4.0.0, I can hardly find a difference. How do…
Hosam Aly
  • 41,555
  • 36
  • 141
  • 182
11
votes
1 answer

How to fabricate Mongoid document with embedded document using Fabrication?

I use Mongoid and Fabrication gems. I have switched to Mongoid.rc7 from beta20 and now I can't fabricate document with embedded document: #Models class User include Mongoid::Document embeds_many :roles end class Role include…
Voldy
  • 12,829
  • 8
  • 51
  • 67
8
votes
2 answers

How to define Fabricator for namespace class

I want to define Fabricator for class has namespace like 'Foo::Bar'. Tell me the way it can work. Here my codes. models/foo.rb class Foo include Mongoid::Document embedded_in :foo_container, polymorphic: true field :xxx…
utwang
  • 1,474
  • 11
  • 16
7
votes
1 answer

How to implement :with_trait using Fabrication

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 FactoryGirl. Is there a generally accepted way to do this with…
ocodo
  • 29,401
  • 18
  • 105
  • 117
6
votes
1 answer

How to refer to the object I'm Fabricating inside my Fabricator?

I'm using Ruby 2.1.1p76 and Rails 4.0.4 and the Fabrication gem. Is it possible to refer to the object currently being fabricated? I have a class Foo and a class Bar. I have fabricators for each. My problem is that each of class Foo and Bar…
dm78
  • 1,570
  • 1
  • 16
  • 28
4
votes
1 answer

Fabrication gem associations that depend on each other

The following is my fabricator: Fabricator(:my_fabricator) do my_first_association my_second_association end The problem here is that I need to pass my_first_association to my_second_association. Couldn't find anything related in the docs.
Patsy Issa
  • 11,113
  • 4
  • 55
  • 74
3
votes
1 answer

How do you define trait using Fabrication

I am learning how to use fabrication in Rails and we have decided to replace all our factory_girl code with fabrication. Suppose we have this code in factory_girl FactoryGirl.define do factory :user do trait(:no_credits) { credits 0 } …
python
  • 4,403
  • 13
  • 56
  • 103
3
votes
1 answer

Fabrication gem cyclic dependency

I've got a cyclic dependency when worked with fabrication gem. Here I'll show you what I've did. Let's suppose I have 2 models: class User < AR::Base has_many :messages class Message < AR::Base belongs_to :user So, the fabricators for them…
3
votes
2 answers

Referencing a field in a Fabrication

In the below example I would like abbr to just be the first 3 letters of name but I get a >> undefined local variable name... I guess because name goes out of scope in the {} block? Fabricator(:team) do name { Faker::Name.first_name } abbr {…
slindsey3000
  • 4,053
  • 5
  • 36
  • 56
3
votes
1 answer

How to use transient attributes in Fabrication's count parameter?

I have this fabricator for a Rails model: Fabricator(:foo) do transient n_iterations: 5 bar(count: :n_iterations) { Fabricate(:bar) } end However, this doesn't work as hoped. I've tried count: n_iterations, count: attrs[:n_iterations], and…
JacobEvelyn
  • 3,901
  • 1
  • 40
  • 51
3
votes
1 answer

How to fabricate and test has_and_belongs_to_many (HABTM) associations using Fabrication and RSpec?

I have 2 HABTM models: class Article < ActiveRecord::Base attr_accessible :title, :content belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' has_and_belongs_to_many :categories validates :title, :presence => true …
Terence Ponce
  • 9,123
  • 9
  • 31
  • 37
2
votes
1 answer

How to get a simple test to run with rspec + fabrication?

I'm trying to get a simple test up and running with rspec + fabrication. Unfortunately, not too many decent articles on this. In spec/model/event_spec.rb require 'spec_helper' describe Event do subject { Fabricate(:event) } describe…
Christian Fazzini
  • 19,613
  • 21
  • 110
  • 215
2
votes
1 answer

How to group attributes in Fabrication like using trait in Factory_Girl

Could you anyone through code show me how we can convert this particular factory_girl code in using Fabrication? factory :user do name "Friendly User" login { name } trait :male do name "John Doe" gender "Male" login { "#{name}…
python
  • 4,403
  • 13
  • 56
  • 103
2
votes
2 answers

How to test the keys and values of api response for Request specs

I am writing Request specs, and having trouble with to test api respond in json formate. I am using capybara and fabricator, here is my code which i trying... context 'discounts in api' do let(:user) { Fabricate(:user, activated: true) } …
Awais
  • 1,803
  • 22
  • 26
2
votes
1 answer

fabricator with hstore attribute

I am trying to build a fabricator using 'fabrication', '2.8.1' with a hstore attribute. Fabricator(:inventory_item_change) do attribute_changes Hash.new("num_units" => "to:50") state "scheduled" change_code 1 execution_at…
1
2 3 4 5