A smart gem with a dumb name; Dummier is a rails generator for automating the creation of rails testing applications.
Dummier was inspired by José Valim's enginex which creates a standard gem structure for you. Enginex creates a test/dummy
app for you, but what if we want to re-create it? Or leave it out of git?
The idea behind Dummier is that we don't check test/dummy
into git, but rather generate it on the fly for the gems we're developing. It just seems DRY'er that way.
Dummier is simple; just run the binary from your gem's root directory and it will generate a stripped-down & gem-dev-ready rails app in test/dummy
. While it's doing it's thing, Dummer triggers a few hooks along the way for easy customization.
To catch the hooks, just create appropriately named files in test/dummy_hooks
inside your gem. See Hooks below for more info.
To install from RubyGems:
gem install dummier
To install with bundler:
gem 'dummier', '>= 0.3.2'
To package for development in your gemspec:
s.add_development_dependency('dummier', '>= 0.3.2')
After you've installed Dummier, just cd
into the gem your developing and run the binary:
bundle exec dummier
Dummier calls the following hooks along the way, in this order:
- before_delete
- before_app_generator
- after_app_generator
- before_migrate
- after_migrate
Place appropriately named files in test/dummy_hooks
and dummier will find and execute them automatically!
You can use Rails::Generators::Actions as well as Thor::Actions in your hooks. Also, since hooks are just eval
'd into the Dummer::AppGenerator, you have access to all of those methods as well.
If a hook throws an error, Dummier will raise a Dummier::HookException
and exit immediately.
Here's a before_migrate.rb
hook that will install Spree Commerce by running a generator before migrating the test/dummy
database.
# test/dummy_hooks/before_migrate.rb
run "rails g spree:install"
Here's an example taken from has_magick_title:
# test/dummy_hooks/after_app_generator.rb
run "rails g scaffold post title:string"
gsub_file "app/models/post.rb", "end", %(
has_magick_title
end)
gsub_file "config/routes.rb", "resources :posts", %(
resources :posts
root :to => "posts#index")
gsub_file "app/views/posts/show.html.erb", "<%= @post.title %>", %(
<%= magick_title_for @post %>)
To get setup for testing, clone this repo, bundle up and run rake.
git clone git://github.com/citrus/dummier.git
cd dummier
bundle install
bundle exec rake
Enjoy!
0.3.2 - 2012/3/12
- revert to using rake "db:migrate", :env => "test" for running migrations
0.3.1 - 2012/3/12
- use bundle exec when running rake db:migrate
- better gem dependency defintions
- use rescue StandardError vs rescue Exception
0.3.0 - 2012/1/26
- exit and raise a Dummier::HookException when a hook raises an exception
0.2.4 - 2011/9/7
- fixed travis ci build image path (thanks @fritzek)
0.2.3 - 2011/9/6
- refactored AppGenerator#run!
- new app generator tests
0.2.2 - 2011/8/31
- added to travis-ci.org
- fixed ruby 1.8.7, rbx and ree compatibility
0.2.1 - 2011/8/31
- merged GH#1 - Thanks @holdensmagicalunicorn
- revised readme
0.2.0 - 2011/6/18
- moved the dummy_hooks to your test folder rather than in lib. makes more sense that way.
0.1.1 - 2011/6/1
- added your gem's
test/dummy_hooks/templates
folder into the generator'ssource_paths
0.1.0 - 2011/5/20
- removed spork and wrote a basic hook test
- improved documentation
0.1.0.rc1 - 2011/5/11
- added spork and some tests
2011/5/10
- it exists!
- Spencer Steffen (@citrus)
- Fritz Thielemann (@fritzek)
- @holdensmagicalunicorn
Copyright (c) 2011 - 2012 Spencer Steffen and Citrus, released under the New BSD License All rights reserved.