
Security News
Rspack Introduces Rslint, a TypeScript-First Linter Written in Go
Rspack launches Rslint, a fast TypeScript-first linter built on typescript-go, joining in on the trend of toolchains creating their own linters.
== Overview
/!\Version 2.0.2 is compatible with ActiveRecord < 3.1
/!\Version 2.0.3 is compatible with ActiveRecord >= 3.1
Factory Boy aims to avoid slow unit tests due to usage of create/find fixtures in database, with factory_girl for example.
Factory Boy can be used as factory_girl except that factories are not created in database.
ActiveRecord::Base finders are stubbed to return fixtures (plants) you have instanciated.
Now, Factory Boy 2 handle stub of Active Record (3+) queries. This means, the fixtures(plants) created with factory boy are retrieved via a AR queries(and only with AR new queries) of your models.
It does not pretend to stub 100% of all queries, but the coverage can be estimated at about 80%-90% of useful queries.
Active Record is stubbed only when at least one Plant is created in a test.
After each test everything is unstubbed. That means, if you have a case where a particular(complex) query is executed but not right stubbed with factory boy you can test using fixtures in databases(with factory girl or just model.create ..), skipping factory boy process.
Tested with ruby 1.9+, ActiveRecord 3.1(version 2.0.2) and ActiveRecord 3.1+ (version 2.0.3) Tests are suppose to use ActiveSupport::TestCase
See some examples below. You should see unit tests to inspect tested stubbed queries!
== Quality Metrics
{}[https://codeclimate.com/github/anoiaque/factory_boy]
== Continuous Integration
http://travis-ci.org/anoiaque/factory_boy.png
== Queries it supposes to handle
The better way to see queries handled is to see all unit tests.
== Queries NOT handled
== Ids
Each plant fixture has now an (unique) id.
== Usage
Define your Plants (~ Factories if factory_girl) in test/plants.rb
Examples :
Plant.define :address do |address| address.number = 12 address.street = "rue de Brest" end
Plant.define :user do |user| user.name="Bart" user.age=800 user.addresses = [Plant(:address)] end
Get it with :
user = Plant(:user)
Example of tests :
def test___1 address = Plant(:address, :street => 'rue des Lilas') user = Plant(:user, :name => 'Joe', :addresses => [address])
assert_equal user, User.find #OK
assert_equal user, User.find(:first) #OK
assert_equal user, User.find(:last) #OK
assert_equal [user], User.where(:name => 'Joe') #OK
assert_equal [user], User.where("name = 'Joe' and addresses.street = 'rue des Lilas'").joins(':addresses) #OK
assert_equal [address], user.addresses.where(:street => 'rue des Lilas') #OK
end
def test___2 2.times { Plant(:user) } assert_equal 2, User.find(:all).size #OK end
You can also create a particular plant of user like that:
user = Plant(:user, :name => "Marie", :age => age)
== Specification of the class of the fixture definition
Plant.define :admin, :class => User do |user| user.name = "Bart" user.age = 800 end
== Associations
Assign fixtures to association in definition of plant :
Plant.define :profile do |profile| profile.password = "BREIZH!" end
Plant.define :address do |address| address.number = 12 address.street = "rue de Brest" end
Plant.define :user do |user| user.name = "Bart" user.age = 800 user.profile = Plant(:profile) user.adresses = [Plant(:address)] end
== Definitions with dependent attributes
If you want to use the value of another attribute in definition, do like that :
Plant.define :user do |user| user.name = "Marie" user.adresses = [Plant(:address, :street => "Rue de #{user.name}")] end
== Sequences
As with factory_girl you are able to use sequences, like that :
Plant.sequence :email do |n| "incognito#{n}@kantena.com" end
Plant.next(:email) # => "incognito1@kantena.com" Plant.next(:email) # => "incognito2@kantena.com"
== In Development
== Install
gem install factory_boy
== Change Log
If you use it, thanks to report feedbacks here, as issue or by git mail box, it will help me to enhance it. Thanks!
FAQs
Unknown package
We found that factory_boy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Rspack launches Rslint, a fast TypeScript-first linter built on typescript-go, joining in on the trend of toolchains creating their own linters.
Security News
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.