[rspec-users] RSpec 2 add-on for testing and specifying generators - initial release

Kristian Mandrup kmandrup.github at gmail.com
Wed Aug 4 06:22:14 EDT 2010


Alright, I will rename it when I get to it. Just improved it in a
major fashion! Now as simple as this to set it up :)

# spec/spec_helper.rb

require 'rspec'
require 'rspec_for_generators'

Rails.application.configure do
  # use default rails tmp dir
  config.root_dir = TmpRails.root_dir(__FILE__)
end

# configure it!
RSpec::Generator.configure!

And to use it in a spec:

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require_generator :demo

describe 'model_generator' do
  include RSpec::Rails::Orm::ActiveRecord

  before :each do
    RSpec::Generator.setup_generator 'model_generator' do
      tests DemoGenerator
    end
    remove_model 'account'
  end

  after :each do
    remove_model 'account'
  end

  it "should decorate an existing Account model file with include
Demo" do
    RSpec::Generator.with_generator do |g|
      name = 'account'
      create_model name
      g.run_generator %w{account}
      g.should generate_file name, :model do |content|
        content.should have_class name do |klass|
          klass.should include_module 'Demo'
        end
      end
    end
  end
end

On Aug 4, 5:22 am, David Chelimsky <dchelim... at gmail.com> wrote:
> On Aug 3, 2010, at 3:06 PM, Kristian Mandrup wrote:
>
>
>
> >http://github.com/kristianmandrup/rspec_for_generators
>
> > When creating Rails generators I noticed that the only option I could
> > find for testing was to use a special Rails TestCase class created
> > specifically for use with Test Unit.
> > So I thought I could wrap it to be used with RSpec 2 instead. I now
> > have a working first release with room for lots of improvements!  But
> > at least it seems to work fine for now, as demonstrated by a small
> > RSpec 2 test suite that comes with it.
>
> > Note: This library is NOT in any way an official RSpec 2 release of
> > any sort. I only use the RSpec name to indicate that it is an add-on
> > component for RSpec 2. That it can be used with RSpec 2.
> > Not sure what other convention there would be to indicate this?
>
> > Maybe I should rename it to something like the following to make it
> > more clear?
>
> > rspec2-addon-for-generators
>
> Ben Mabey called his email-spec. So maybe generator-spec?
>
>
>
> > Hope you find it useful as a starting point. Free feel to patch it,
> > refactor etc.
> > Enjoy!
>
> > Kristian
> > _______________________________________________
> > rspec-users mailing list
> > rspec-us... at rubyforge.org
> >http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users


More information about the rspec-users mailing list