factory-bot

Undefined method after_create with FactoryGirl

不想你离开。 提交于 2019-12-10 02:28:29
问题 I'm trying to defined a has_many relationship in FactoryGirl using the after_create callback, like so in /spec/factories/emails.rb: FactoryGirl.define do factory :email do after_create do |email| email.attachments << FactoryGirl.build(:attachment) end end end The attachment is defined in a seperate factory /spec/factories/attachment.rb: FactoryGirl.define do factory :attachment do # Attach the file to paperclip file { fixture_file_upload(Rails.root.join('spec', 'support', 'myimage.png'),

FactoryGirl: Factory not registered: user (ArgumentError)

寵の児 提交于 2019-12-10 00:58:23
问题 Having a lot trouble getting all the ducks in the right order with FactoryGirl. Set up a minimalist rails app (3.0.11), factory_girl_rails (1.4.0), factory_girl (2.3.2) & cucumber-rails (1.2.1) and ruby-1.8.7-p352. The cucumber test is: Feature: a Scenario: test factory-girl Given the following user exists: | name | email | | Brandon | brandon@example.com | The result is this: cucumber Using the default profile... "Adam Advertiser" "a@b.com" #<User id: nil, name: nil, created_at: nil, updated

railstutorial.org - undefined method `Factory'

☆樱花仙子☆ 提交于 2019-12-09 09:28:34
问题 I'm attempting to follow railstutorial.org, and am currently on Chapter 7, where you start using factories: http://railstutorial.org/chapters/modeling-and-viewing-users-two#sec:tests_with_factories I'm using Rails 3.0.1 and ruby-1.9.2-p0 I can't for the life of me get my rspec tests to pass though, the error i get is Failures: 1) UsersController GET 'show' should be successful Failure/Error: @user = Factory(:user) undefined method `Factory' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1

How to use FactoryGirl factories from an engine

亡梦爱人 提交于 2019-12-09 02:56:20
问题 We have two web apps that share the same database and models. To keep it DRY we created an engine that contains all those models. This engine is included in the respective apps via the Gemfile. We do have tests with RSpec and FactoryGirl inside the engine. Now we are trying to write integration tests and we would like to use the factories from the engine without copying or symlinking. Is there a way to achieve this programmatically? 回答1: Ok so this works: https://github.com/thoughtbot/factory

Rspec/FactoryGirl: clean database state

自作多情 提交于 2019-12-09 02:28:04
问题 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 the test run, but what happens if I have data in the database. For example: I want my test to run when there are 3 records in the database that I created through Factory Girl. However, I currently already have 1 model record in the database, and I don't want to delete it just for the test. Having

Factory Girl: How to set up a has_many/through association

穿精又带淫゛_ 提交于 2019-12-08 23:19:53
问题 I've been struggling with setting up a has_many/through relationship using Factory Girl. I have the following models: class Job < ActiveRecord::Base has_many :job_details, :dependent => :destroy has_many :details, :through => :job_details end class Detail < ActiveRecord::Base has_many :job_details, :dependent => :destroy has_many :jobs, :through => :job_details end class JobDetail < ActiveRecord::Base attr_accessible :job_id, :detail_id belongs_to :job belongs_to :detail end My Factory:

Does a framework like Factory Girl exist for Java? [closed]

安稳与你 提交于 2019-12-08 22:48:51
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Factory Girl is a handy framework in rails for easily creating instances of models for testing. From the Factory Girl home page: factory_girl allows you to quickly define prototypes for each of your models and ask for instances with properties that are important to the test at hand. An example (also from the

Rspec validates_uniqueness_of test failing with additional validation errors

和自甴很熟 提交于 2019-12-08 08:45:36
问题 I have 2 scoped uniqueness validations on my answer model, I am trying to test these using Rspec and the respective shoulda matchers. As seen in the test trace below, the uniqueness validations message is present in the errors array however, there are also 2 and sometimes 3 other errors present; "body can't be blank (nil)", "body is too short (minimum is 10 characters) (nil)", "user_id can't be blank (nil)" . I'm not sure where they are coming from, as body and user attributes are set

Capybara::ElementNotFound: Unable to find field “Email” Railstutorial(chapter 9)

我的梦境 提交于 2019-12-08 05:30:32
问题 I am following Railstutorial (chapter 9) The test for" delete links " is passed for first time but from the next time it starts giving some kind of errors like: Failures: 1) User pages index delete links as an admin user Failure/Error: sign_in admin Capybara::ElementNotFound: Unable to find field "Email" # ./spec/support/utilities.rb:20:in `sign_in' # ./spec/requests/user_pages_spec.rb:38:in `block (5 levels) in <top (required)>' 2) User pages index delete links as an admin user Failure/Error

RSpec: Include a custom helper module in spec_helper.rb

霸气de小男生 提交于 2019-12-07 20:46:44
问题 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 (NameError) Here is my spec_helper.rb as it currently is: # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' require 'capybara/rspec' include