JayZ
Where
Description:
A model factory. Say no to fixtures. Documentation is available at rubydoc
Compatibility
Ruby version 1.9.2 and 1.9.3 and Rails version 3.1
GemTesters has more information on which platforms the Gem is tested.
Installation
Install as a gem:
gem install jay_z
Examples
Rails, ActiveRecord and minitest
Update Gemfile
group :development, :test do gem 'jay_z', :require => 'jay_z/rails' end
Install the gem
$ bundle install
Generate (test|spec)/blueprint.rb file
$ rails generate jay_z:install
Update config/application.rb
config.generators do |g| g.test_framework :mini_test, :spec => true, :fixture_replacement => :jay_z end
Generate a model object with its factory
$ rails generate model Comment post_id:integer body:text
It adds to the end of file (test|spec)/blueprint.rb
class Comment < Blueprint(ActiveRecord) default do post_id { 1 } body { "MyText" } end end
Modify the generated blueprint according to your preferences
class Comment < Blueprint(ActiveRecord) default do post { Post.make.save } body { "MyText" } end end
Write tests in test/comment_test.rb
require "minitest_helper" class CommentTest < MiniTest::Rails::Model before do @comment = Comment.make.new end it "must be valid" do @comment.valid?.must_equal true end end
How to test the installed Gem
gem install rubygems-test
gem test jay_z
For more info see: GemTesters