I am using Mocha and Factory_girl in a JRuby rails application. When I call the factory I would like to return the objects with some mocking already done. Here is a code snippet of what I am trying to do.
Factory.define :tweet_feed_with_tweets, :parent => :tweet_feed do |t|
t.expects(:pull_tweets).returns([Factory.build(:status),Fac...
I just started to use factory girl to replace fixtures when I am testing. I am working on a twitter client and I am trying to use factory girl to create the twitter objects for testing. When I create them individually it is fine. But, if I try to associate them I get the error below.
Factory.define :status, :class => Twitter::Status,...
Hi there.
I'm still new to rails and testing with rspec, so hopefully you can help me.
I have a controller which requires login. I use the restful authentication function of rails.
To create things in tests I'm using the factory framework factorygirl.
Ok the problem is the following:
I want to test a controller (authentication requ...
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 home page):
Factory....
The Factory Girl docs offer this syntax for creating (I guess) parent-child associations...
Factory.define :post do |p|
p.author {|a| a.association(:user) }
end
A post belongs to a User (its "author").
What if you want to define a Factory to create Users, that have a bunch of Posts?
Or what if it's a many-to-many situation (...
Update
Answered below. In case the linked site disappears, you can use mocha to stub the initial state and prevent overwriting as in ...
require 'mocha'
class OrderTest < ActiveSupport::TestCase
def setup
Order.any_instance.stubs(:set_initial_state)
@order = Factory(:order, :state => "other_state")
end
...
end
Origina...
I'm trying to set up Factory Girl with Test::Unit and Shoulda in Ruby on Rails. I have installed the gem, created my factory file under the test/factories directory, and created my spec file under the test/models directory. The current error I'm getting is 'ArgumentError: No such factory: test', which leads me to believe that the test_fa...
Recently I switched from fixtures to factory_girl to test my Ruby on Rails application. If I run rake test:units, to run the tests in my /units directory, they all run perfectly. The same is true if I run my functional tests (in my /functional directory) with rake test:functionals.
However, if I simply run rake test, to run both my unit...
Hi,
i'm developing test for REST using shoulda and factory_girl. Code below
context "on :delete to :destroy" do
setup do
@controller = NewsArticlesController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@news_article = Factory.create(:news_article)
en...
Can anyone suggest a better way to make a factory use a pre-built model
instance for its association? For example, so that it would be possible
below to define a child of the Message factory so that a call to
Factory(:my_message) could substitute for
Factory(:message,:sender=>@me) ?
Sometimes the setup hash is more involved than in this...
Situation
# Models
class User < ActiveRecord::Base
has_many :items
end
class Items < ActiveRecord::Base
belongs_to :user
validates_presence_of :user_id
end
# Factories
Factory.define(:user) do |u|
u.name "foo"
end
Factory.define(:user_with_items, :parent => :user) do |u|
u.items {|items| [items.association(:item), ...
I'm looking for a way to speed up my Shoulda + FactoryGirl tests.
The model I'm trying to test (StudentExam) has associations to other models. These associated objects must exist before I can create a StudentExam. For that reason, they are created in setup.
However, one of our models (School) takes significant time to create. Becaus...
I normally use this step to set up records with factory_girl:
Given /^the following (.+) records?:$/ do |factory, table|
table.hashes.each do |hash|
Factory(factory, hash)
end
end
And here's my work-around when setting up associations:
Given the following group record:
| id | name |
| 1 | foo |
And the following item re...
Just to clear the air, I am not some cruel factory master trying to silence working ladies. I am having a very annoying problem where when using Thoughtbot's factory girl in my specs, every time Factory.create(:foo) is used, the newly created ActiveRecord model instance is logged to the console. This makes looking at my console output ...
Hi,
could you tell me plz - how to write tests for projects, which uses in model establish_connection to connect another database?
...
I'm working with a Rails 2.2 project working to update it. I'm replacing existing fixtures with factories (using factory_girl) and have had some issues. The problem is with models that represent tables with lookup data. When I create a Cart with two products that have the same product type, each created product is re-creating the same pr...
I have an issue where I have a parent model Foo, which both has_many :bars and has_many :bazes. Finally, I also have a join model BarBaz which belongs_to :bar and belongs_to :baz. I want to validate all bar_bazes so that its bar and baz both belong to the same foo. But I can't seem to figure out a way to define a factory for this mode...
I recently noticed my test database is not being cleaned up after my tests run if my tests subclass Test::Unit::TestCase. If my tests subclass ActiveSupport::TestCase, everything is cleaned up properly.
Can anyone explain why, and/or provide an explanation of using one versus the other?
I am using shoulda and factory_girl.
Thanks.
...
I have a User factory that references a Company
Factory.define :user do |f|
f.first_name "John"
f.last_name "Smith"
f.password "test01"
f.password_confirmation {|u| u.password}
f.email "[email protected]"
f.association :company, :factory => :company
end
Factory.define :company do |f|
f.name "My Company"
end
The Com...
To start out, here is the failing message:
ActiveRecord::RecordInvalid in 'Event should be valid'
Validation failed: Single access token has already been taken, Login has already been taken, Email has already been taken
Here is my factory:
Factory.define :valid_event, :class => Event do |e|
e.event_date "2010-01-01"
e.critter { |...