# Release of RSpec for Generators 0.4.0

**URL:** <https://www.ruby-forum.com/t/release-of-rspec-for-generators-0-4-0/192888>\
**Category:** RSpec\
**Created:** [August 7, 2010, 5:28pm UTC](https://www.ruby-forum.com/t/release-of-rspec-for-generators-0-4-0/192888 "2010-08-07T17:28:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kristianm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kristianm](https://www.ruby-forum.com/u/kristianm)\
**Post date:** [August 7, 2010, 5:28pm UTC](https://www.ruby-forum.com/t/release-of-rspec-for-generators-0-4-0/192888/1 "2010-08-07T17:28:38Z")

</div>

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

[http://github.com/kristianmandrup/rspec\_for\_generators](http://github.com/kristianmandrup/rspec_for_generators)

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’  
end  
end  
end  
end

# 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  
end  
end

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

```

# 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
    end
  end

```

and many more…
