factory-bot

Factory already registered: user (FactoryGirl::DuplicateDefinitionError)

给你一囗甜甜゛ 提交于 2019-12-03 04:11:28
Description of problem: - I've setup factory_girl_rails however whenever I try and load a factory it's trying to load it multiple times. Environment: - rails (3.2.1) - factory_girl (2.5.2) - factory_girl_rails (1.6.0) - ruby-1.9.3-p0 [ x86_64 ] > rake spec --trace ** Execute environment -- Creating User Factory -- Creating User Factory rake aborted! Factory already registered: user The only other thing I've changed is: /config/initializers/generator.rb Rails.application.config.generators do |g| g.test_framework = :rspec g.fixture_replacement :factory_girl end GEMFILE gem 'rails', '3.2.1' #

How come Factory Girl isn't sequencing unique attributes?

妖精的绣舞 提交于 2019-12-03 03:31:07
My controller spec fails because Factory Girl seems to be creating non-unique Users even though I sequence the User attributes that need to be unique. The Errors 1) TopicsController POST #create when topic is invalid should render new Failure/Error: let(:invalid_topic) {Factory.build :invalid_topic} ActiveRecord::RecordInvalid:Validation failed: Email has already been taken, Username has already been taken 2) TopicsController POST #create when topic is valid should redirect to show Failure/Error: let(:valid_topic) {Factory.build :topic} ActiveRecord::RecordInvalid: Validation failed: Email has

RSpec-rails-capybara - different failures with :js => true and without

冷暖自知 提交于 2019-12-03 03:06:59
I'm building a setup screen for billing of individuals. The controller/views are in the Admin namespace. When run the first test without :js => true I get one failure, which I assume is down to the fact that the link does not work as its a helper which uses a js script to build a nested set of fields (Based on Railscasts Single form, multiple tables - Nested Attributes). Failures: 1) Patient Setup create patient bill heading - with extended details -with valid data Failure/Error: fill_in "Extended Bill Heading", :with => 'Regular Registration' Capybara::ElementNotFound: cannot fill in, no text

RSpec failure: could not find table after migration…?

。_饼干妹妹 提交于 2019-12-03 03:06:46
问题 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 "test@test.com" f.password "blah" f.password_confirmation "blah" f.display_name "neezer" end Then I've added one test: require 'spec_helper' describe User do subject { Factory :user } it "can be created from a factory" do subject.should_not be_nil subject.should be_kind_of User end end Then I migrate my database using rake db

Factory-girl create that bypasses my model validation

泄露秘密 提交于 2019-12-03 02:54:24
问题 I am using Factory Girl to create two instances in my model/unit test for a Group. I am testing the model to check that a call to .current returns only the 'current' groups according to the expiry attribute as per below... describe ".current" do let!(:current_group) { FactoryGirl.create(:group, :expiry => Time.now + 1.week) } let!(:expired_group) { FactoryGirl.create(:group, :expiry => Time.now - 3.days) } specify { Group.current.should == [current_group] } end My problem is that I've got

How to create/build multiple instances of a factory in Factory Girl?

吃可爱长大的小学妹 提交于 2019-12-03 02:46:21
问题 How do I create multiple records or multiple factories of the same class? I tried: Factory.define :user do |user| user.email "someuser@somesite.com" user.password "somepassword" user.email "another_existing_user@somesite.com" user.password "somepassword" end and Factory.define :user do |user| user.email "someuser@somesite.com" user.password "somepassword" end Factory.define :user do |user| user.email "another_existing_user@somesite.com" user.password "somepassword" end But it doesn't work --

AssociationTypeMismatch and FactoryGirl

允我心安 提交于 2019-12-03 01:37:21
This has been causing some frustration recently... It seems that using Factories in my cucumber tests, in some situations causes AssociationTypeMismatch errors such as: MyModel(#65776650) expected, got MyModel(#28190030) (ActiveRecord::AssociationTypeMismatch) These seem to happen when there is an association reference - as if the Factory created object is different to the real one. See this question for more details: Cucumber duplicate class problem: AssociationTypeMismatch I have been gradually changing Factory calls to real Model.create or mock_model calls. It would be nice to keep using

Why do I get an undefined method 'have' error when running Rspec?

好久不见. 提交于 2019-12-03 01:30:38
I recently upgraded to Rails 4 and everything works fine except for my Rspec tests. require 'spec_helper' describe Invoice do before :each do @user = FactoryGirl.create(:activated_user) person = FactoryGirl.create(:person, :user => @user, :company => nil) @project = FactoryGirl.create(:project, :user => @user, :person_ids => [person.id], :invoice_recipient_id => person.id) end it "has a valid factory" do expect(FactoryGirl.build(:invoice, :project => @project, :user => @user)).to be_valid end it "is invalid without a number" do expect(FactoryGirl.build(:invoice, :project => @project, :user =>

Machinist vs FactoryGirl - pros and cons

…衆ロ難τιáo~ 提交于 2019-12-03 00:58:15
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? Ryan McGeary Machinist was actually heavily inspired by factory_girl , but varied because machinist's author wanted a different syntax. Since then, factory_girl added different syntax layers to simulate other factory libraries (including machinist's "blueprint" syntax). In other words, both are extremely similar, just with a different default syntax. Personally, I use factory_girl. MetalElf0 Actually, Machinist has a big

How to define an array / hash in Factory Girl?

风流意气都作罢 提交于 2019-12-03 00:29:10
问题 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 Factory since the return result is an array with a has inside. What would go here? Factory.define :dropbox_hash do ?? end Dropbox data looks like this: ["/home", {"revision"=>48, "rev"=>"30054214dc", "thumb_exists"=>false, "bytes"=>0, "modified"=>"Thu, 29 Dec 2011 01:53:26 +0000", "path"=>"/Home", "is