Machinist vs FactoryGirl - pros and cons
Hi, 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? ...
Hi, 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? ...
Is there any way to logout and login another user when testing with Authlogic? The following test case just fails class MessagesControllerTest < ActionController::TestCase setup :activate_authlogic should "sender send a message and recipient delete it" do @sender = Factory(:user, :login => 'sender') @recipient = Factory(:u...
I'm using the factory_girl plugin in my rails application. For each model, I have a corresponding ruby file containing the factory data e.g. Factory.define :valid_thing, :class => Thing do |t| t.name 'Some valid thing' # t.user ??? end I have lots of different types of users (already defined in the user factory). If I try the foll...
Here's my models : Class Audition belongs_to :video end Class Video has_one :audition end and my factories : Factory.define :video do |v| v.filename {Sham.filename} v.video_url {Sham.url} end Factory.define :audition do |a| a.video {|a| a.association(:video)} a.label {Sham.label} end How could I create a vide...
I have Rspec + Shoulda + FactoryGirl and I am receiving the following error when attempting to call Shoulda's have_many or belong_to methods. All Shoulda methods used in the "validations" group work fine: > NoMethodError in 'A Project > associations should When you call a > matcher in an example without a > String, like this: > > s...
I'm just getting into Factory Girl and I am running into a difficulty that I'm sure should be much easier. I just couldn't twist the documentation into a working example. Assume I have the following models: class League < ActiveRecord::Base has_many :teams end class Team < ActiveRecord::Base belongs_to :league has_many :play...
I have two factories (post_factory.rb, comment_factory.rb) in separate files. I'd like to create a bit complex factory, which will create a post with associated comments for me. I created a third file, called complex_factory.rb, and wrote the following code: Factory.define :post_with_comments, :parent => :post do |post| post.after_cre...
I have a model defined this way class Lga < ActiveRecord::Base validates_uniqueness_of :code validates_presence_of :name end I've defined a factory for Lgas with Factory.sequence(:lga_id) { |n| n + 10000 } Factory.define :lga do |l| id = Factory.next :lga_id l.code "lga_#{id}" l.name "LGA #{id}" end However, when I run ...
I am (finally) attempting to write some integration tests for my application (because every deploy is getting scarier). Since testing is a horribly documented feature of Rails, this was the best I could get going with shoulda. class DeleteBusinessTest < ActionController::IntegrationTest context "log skydiver in and" do setup do...
Hi there, I'm trying to run cucumber features with factory girl factories on a fresh Rails 3 application. Here is my Gemfile: source "http://gemcutter.org" gem "rails", "3.0.0.beta" gem "pg" gem "factory_girl", :git => "git://github.com/thoughtbot/factory_girl.git", :branch => "rails3" gem "rspec-rails", ">= 2.0.0.beta.4" gem "capybar...
Im trying to test my successfully creates a new user after login (using authlogic). Ive added a couple of new fields to the user so just want to make sure that the user is saved properly. The problem is despite creating a valid user factory, whenever i try to grab its attributes to post to the create method, password and password confir...
I need to pass extra arguments to factory girl to be used in a callback. Something like this (but more complex really): Factory.define :blog do |blog| blog.name "Blah" blog.after_create do |blog| blog.posts += sample_posts blog.save! end end and then create it with something like this: Factory.create(:blog, :sample_pos...
i am trying to simulate a session using factory girl/shoulda (it worked with fixtures but i am having problems with using factories). i have following factories (user login and email both have 'unique' validations): Factory.define :user do |u| u.login 'quentin' u.email '[email protected]' end Factory.define :session_user, :class =...
I have written my basic models and defined their associations as well as the migrations to create the associated tables. EDIT - Adding emphasis to what I specifically want to test. I want to be able to test: The associations are configured as intended The table structures support the associations properly I've written FG factorie...
When building the following factory: Factory.define :user do |f| f.sequence(:name) { |n| "foo#{n}" } f.resume_type_id { ResumeType.first.id } end ResumeType.first returns nil and I get an error. ResumeType records are loaded via fixtures. I checked using the console and the entries are there, the table is not empty. I've found ...
I'm able to get my Gemfile how I like it: # Gemfile source "http://gemcutter.org" gem "rails", :git => "git://github.com/rails/rails.git" git "git://github.com/rails/arel.git" git "git://github.com/rails/rack.git" gem "sqlite3-ruby" group :test do gem "shoulda", :git => "git://github.com/thoughtbot/shoulda.git", :branch => ...
I am using Factory Girl but like the machinist syntax. So I wonder, if there is any way creating a named blueprint for class, so that I can have something like that: User.blueprint(:no_discount_user) do admin false hashed_password "226bc1eca359a09f5f1b96e26efeb4bb1aeae383" is_trader false name "foolish...
I have a model Foo that has_many 'Bar'. I have a factory_girl factory for each of these objects. The factory for Bar has an association to Foo; it will instantiate a Foo when it creates the Bar. I'd like a Factory that creates a Foo that contains a Bar. Ideally this Bar would be created through the :bar factory, and respect the build st...
I have installed both shoulda and factory_girl, I can run shoulda just fine, but when I add this: require 'factory_girl' Factory.define :user do |u| u.mail '[email protected]' u.pass 'secret' end to my test/test_helper.rb I'm getting this error: /test/test_helper.rb:1:in `require': no such file to load -- factory_girl (LoadError)...
I am trying to test a model's attributes for formatting with this: # myapp/test/unit/comment_test.rb require 'test_helper' class CommentTest < ActiveSupport::TestCase should_belong_to :article should_validate_presence_of :name should_validate_presence_of :email should_validate_presence_of :content should_validate_presence_of...