Release of RSpec for Generators 0.4.0

Now with a full RSpec 2 test suite to demonstrate most of its
features. Wiki to be updated with latest changes ASAP.

This gem makes it very easy to spec that your generator generates
files as expected and also lets you easily verify that the content of
those files match what you expect

  • name of the class
  • subclass of class
  • class includes specific modules
  • contains certain instance or class methods

In general it has a lot of nice matchers to match on generated Ruby
source code (using regexp)

It also has a nice DSL to spec generated migration files in detail
(see below)

spec generated model file

it “should decorate an existing Account model file with include
Canable:Ables” do
with_generator do |g|
name = ‘account’
create_model name
g.run_generator [name]
g.should generate_model name do |content|
content.should have_class name do |klass|
klass.should include_module ‘Canable::Ables’

spec generated migration file

  g.should generate_migration name do |content|
    content.should have_migration name do |klass|
      klass.should have_up do |up|
        up.should have_create_table :users do |user_tbl|
          user_tbl.should have_columns :name => :string, :age

=> :string

      klass.should have_down do |up|
        up.should have_drop_table :users

spec generated Active Record observer

  g.run_generator [name]
  g.should generate_observer name do |content|
    content.should have_observer_class name do |klass|
      klass.should have_method :observe_me

and many more…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs