Machinist is a factory framework for building test objects in Ruby. It's made to be a drop-in replacement for fixtures in Ruby on Rails testing suites.
Questions tagged [machinist]
34 questions
40
votes
3 answers
Machinist vs FactoryGirl - pros and cons
I'm working with factory_girl, but looking at the machinist gem. Could you tell me please - what are the pros and cons of migrating to machinist? Have you compared those libs?

Alexey Poimtsev
- 2,845
- 3
- 35
- 63
16
votes
3 answers
Singleton factories in factory_girl/machinist?
Is there some configuration in a factory of factory girl/machinist that forces it to create objects with the same factory name just once during test case and return the same instance all the time? I know, i can do something like:
def singleton name
…

Alexey
- 9,197
- 5
- 64
- 76
9
votes
4 answers
Rails 3: Duplicate validation error messages during testing
I'm getting some weird validation behavior: it's duplicating my validation error messages and I can't figure out what's causing it... it doesn't do this in the rails console.
Here is the validation from my Phone model:
# phone.rb
validates :number,…

wulftone
- 1,628
- 1
- 18
- 34
8
votes
1 answer
RSpec and Machinist error: Too many open files
This morning I am having the following error:
14) Deal on creation sets frozen to false or nil
Failure/Error: Unable to find matching line from backtrace
Errno::EMFILE:
Too many open files - identify -format %wx%h…

rtacconi
- 14,317
- 20
- 66
- 84
8
votes
5 answers
Rails integration test with the devise gem
I want to write an rails integration test (with ActionDispatch::IntegrationTest). I am using devise for authentication and machinist for test models. I cannot successfully sign in.
Here is a simple example:
class UserFlowsTest <…

hiwaylon
- 465
- 7
- 15
7
votes
3 answers
Is there a way in factory_girl to get attributes_for and create for the same instance element?
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 it possible in Machinist gem?

Alexey
- 9,197
- 5
- 64
- 76
4
votes
1 answer
When would a ruby array count not equal to the number of elements in an array?
I'm running testunit (with machinist) and getting this very strange result when I run the ruby debugger
(rdb:1) @document.document_items
[]
(rdb:1) @document.document_items.count
2
(rdb:1) @document.document_items.length
0
(rdb:1)…

zlog
- 3,316
- 4
- 42
- 82
4
votes
2 answers
Machinist, how do I reference the object I'm making and pass it to an association? (AssociationTypeMismatch)
I'm trying to build factories for relatively complex models.
I have a Pressroom model, which belongs to Source, and Source has many Pressrooms. When creating the Source, if pressrooms is empty, an initial pressroom is created in an after_create…

Martin Svalin
- 2,227
- 1
- 17
- 23
4
votes
3 answers
Test data generation for Ember.js (like factory_girl or machinist)
I'm writing unit and integration tests against an Ember.js application, and I can't connect to the server when the application is under test. This means I need to use DS.FixtureAdapter to back up my data store.
But I'm not personally a fan of…

emk
- 60,150
- 6
- 45
- 50
3
votes
1 answer
Machinist + RSpec and reserved words
I have a blueprint:
Model.blueprint(:something) do
name "Some name"
context "some context"
end
"context" is an attribute of Model, but it is also a reserved word of RSpec. When I try to make and object I get ArgumentError on "context" line.
Any…

Tomek Wałkuski
- 989
- 12
- 22
3
votes
1 answer
Is there any rails factory to help me test non persistant models?
I'm working on a rails application on which the models are plain ruby classes without any persistence layer (no active record or similar). I want to test these models from RSpec with all the niceties that some factories provide (machinist,…

Diego Echeverri
- 163
- 1
- 9
3
votes
2 answers
can cucumber and rspec use the same blueprints.rb file
I'm using Rails 3, machinist 2, cucumber and rspec all together and have two blueprints.rb files. One in the spec directory and one in the features/support directory.
Is it a good idea to just have one blueprints.rb file?
If it is, what is the…

map7
- 5,096
- 6
- 65
- 128
2
votes
1 answer
Why don't machinist objects save inside nested blocks?
This is my spec code that isn't working:
require 'spec_helper'
describe User do
describe "blah" do
it "should save itself" do
user = User.make!
u = User.find user.id
user = User.make!
u = User.find user.id
end
…

nimblegorilla
- 1,183
- 2
- 9
- 19
2
votes
1 answer
validates_uniqueness_of failing with tests, machinist
I have a validates_uniqueness_of validation on my model:
#SwimMeetRelayEvent.rb
validates_uniqueness_of :event_number_digit, :scope => [:swim_meet_id, :event_number_alpha]
validates_uniqueness_of :event_number_alpha, :scope => [:swim_meet_id,…

telecasterrok
- 209
- 2
- 12
2
votes
0 answers
Time zone change on DateTime method (Rails 4.2.8)
I am trying to upgrade from rails 4.2.7 to 4.2.8 and found a case where the DateTime method of rails switches the time zone to local on reload from database which was not seen in rails 4.2.7. On rails 4.2.8, the unit test of my app rely on the…

user3757655
- 21
- 1
- 3