factory-bot

RSpec can't find Factorys from Factorygirl

拈花ヽ惹草 提交于 2019-12-06 00:21:59
问题 i will use RSpec with Factory girl in my Rails3 Project. I have installed factory girl but it don't find the factorys i have this error Failure/Error: Factory.build(:user).should_be valid No such factory: user spec/factories/user_factory.rb : Factory.define :user do |u| u.username 'otto' end spec/spec_helper.rb ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'factory_girl' Dir[Rails.root.join("spec/support/**/*.rb")]

How do I define sequences in FactoryGirlRails?

℡╲_俬逩灬. 提交于 2019-12-05 19:01:25
Previously in Factory girl, we could define sequences like so: # /spec/factories.rb FactoryGirl.define do # this is the sequence in question: sequence(:random_token) { Digest::MD5.hexdigest(rand.to_s) } factory :story do sequence(:title) { |n| "My Cool Story##{n}" } # Call the sequence here: token { Factory.next(:random_token) } description { "#{title} description"} end end Now, when I try that approach - I get a deprecation warning telling me: WARNING: FactoryGirl::Sequence#next is deprecated. Use #run instead. When I replace #next with #run, I get a no-method error. I can't find the new

Building a json stub using FactoryGirl

℡╲_俬逩灬. 提交于 2019-12-05 17:43:04
I am try to build a json using a factory, but when i try to build it's empty. Below is Factory class. require 'faker' FactoryGirl.define do factory :account do |f| f.name {Faker::Name.name} f.description {Faker::Name.description} end factory :accjson, class:Hash do "@type" "accountResource" "createdAt" "2014-08-07T14:31:58" "createdBy" "2" "disabled" "false" end end Below is how i am trying to build. hashed_response = FactoryGirl.build(:accjson) expect(account.to_json).to eq(hashed_response.to_json); But my hashed_response always seems to be empty object . Using FactoryGirl to create a json is

How to resolve factory_girl wrong number of arguments error

丶灬走出姿态 提交于 2019-12-05 17:21:22
问题 #rspec test code @room = FactoryGirl.build(:room) #factory definition factory :room do length {10} width {20} end #code implementation class Room attr_accessor :length, :width def initialize(length,width) @length = length @width = width end end Running rspec results in this error when trying to build the @room ArgumentError: wrong number of arguments (0 for 2) 回答1: FactoryGirl does not currently support initializers with arguments. So it fails when it's trying to do Room.new when you run

Factory Girl - has many associations

旧街凉风 提交于 2019-12-05 12:41:16
I'm using factory girl with rspec, here is what I have: factories.rb Factory.define :user do |f| f.sequence(:fname) { |n| "fname#{n}" } f.sequence(:lname) { |n| "lname#{n}" } f.sequence(:email) { |n| "email#{n}@google.com" } f.password "password" f.password_confirmation { |u| u.password } f.invitation_code "xxxxxxx" end Factory.define :group do |f| f.sequence(:name) { |n| "myGroup#{n}" } f.sequence(:private_email) { |n| "myGroup#{n}" } end Factory.define :permission do |f| f.role_id 1 end groups_controller_spec.rb describe GroupsController do include Devise::TestHelpers before (:each) do

How to Populate Lookup tables in Testing (Rails)

这一生的挚爱 提交于 2019-12-05 10:38:24
I am using Cucumber, Rspec, and Factory Girl for the testing of my Rails Application. But I have several lookup tables that contain mostly static data. So I'm trying to figure out the best way to populate these when testing. Doing them individually in FactoryGirl seems tedious and I'd like to stay away from Fixtures. For development and production, I populate them in my seeds.rb file. Thanks! Use Factory Girl .sequence, Populator and Faker and you'll never run out of lab rats! Factory.define(:model) do |m| m.sequence(:title) { |n| "model-#{n}" } m.author Faker::Name.name m.short Populator

Using factory_girl_rails with Rspec on namespaced models

自闭症网瘾萝莉.ら 提交于 2019-12-05 08:28:38
问题 I have a web service that serves Ads to several different clients. The structure of the Ad varies between clients, and therefore, I am using namespaces for my models and controllers by the client name to differentiate between Ads. From the high level, it looks like this: 'app/models/client1/ad.rb' class Client1::Ad < ActiveRecord::Base attr_accessible :title, :description end 'app/models/client2/ad.rb' class Client2::Ad < ActiveRecord::Base attr_accessible :title, :description, :source end In

Using FactoryGirl without Rails, ActiveRecord or any database with RSpec

馋奶兔 提交于 2019-12-05 08:00:27
I was wondering if anyone knows whether it's possible to use FactoryGirl without any of the aforementioned prerequisites. I would like to use it to generate on-the-fly test data when driving UI automation tests for both mobile and web, and even possibly API. I know I could create some custom helper classes/methods and use getters and setters, etc., but I thought it would be good to use this awesome little gem. I have searched quite extensively and also tried to set up a basic RSpec project (I also tried Cucumber), but to no avail. It still appears that I need classes to be instantiated with

Rspec, Devise, Factory girl - how to sign in Factory user through Rspec controller test?

≡放荡痞女 提交于 2019-12-05 05:12:23
I have a Posts controller and I have just installed Devise to add some authentication quickly and easily. Before I installed Devise, I had created some tests for the 'new' action of my Posts controller. After installing Devise, my tests were failing until i added the config.include Devise::TestHelpers, :type => :controller line to my spec_helper.rb file. I also have the line before_filter :authenticate_user!, :except => [:show, :index] in my PostsController. Now when I run my tests, they all pass except these 2: it "should be successful" do get :new response.should be_success end it "should

How can I build/create a many-to-many association in factory_girl?

ぃ、小莉子 提交于 2019-12-05 05:09:19
问题 I have a Person model that has a many-to-many relationship with an Email model and I want to create a factory that lets me generate a first and last name for the person (this is already done) and create an email address that is based off of that person's name. Here is what I have for create a person 's name: Factory.sequence :first_name do |n| first_name = %w[FirstName1 FirstName2] # ... etc (I'm using a real subset of first names) first_name[(rand * first_name.length)] end Factory.sequence