FixtureMe
Generate fixtures and fixture files for testing
If you want to generate fixtures from development database for a Ruby on Rails application here is a helper.
Installation
Add this line to your application's Gemfile:
gem 'fixture_me'
And then execute:
$ bundle
Or install it yourself as:
$ gem install fixture_me
Usage
rails console
Once your are inside Rails console
To generate fixtures for all models.
A new directory called fixtures would be created inside tmp directory (this is to make sure that this fixture generation would not override existing fixtures)
fixme = FixtureMe::AddFixtures.new
fixme.create_all_fixtures
to exclude created_at and updated_at columns
fixme = FixtureMe::AddFixtures.new
fixme.create_all_fixtures_no_timestamps
To generate fixtures one by one
a mymodel.yml file would be generated inside that file does not exist in the test/fixtures directory
'add_fixture' method would add the new record after the existing fixtures.
require "fixture_me"
obj = Mymodel.find(42)
obj.add_fixture
To exclude timestamps and ID
require "fixture_me"
obj = Mymodel.find(42)
obj.add_fixture_no_id_timestamps
On a last note please try to give some tender love to fixtures. There is nothing wrong with them. No doubt Factories are good. But why would you need that when there are fixtures bundled right there with Rails and they work like a charm with Rails. I'll have a dig at Rspec as well. Why on earth would one use Rspec when there is minitest.
Contributing
- Fork it ( https://github.com/iamfree-com/fixture_me/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request