[rspec-users] RSpec 2 - specs for Rails generators :)

Kristian Mandrup kmandrup.github at gmail.com
Sun Jul 11 09:54:54 EDT 2010


http://github.com/kristianmandrup/canable

In my fork of jnunemaker's canable I show my port of the unit test way
of testing generators for RSpec 2.
It still needs some tidying up to make it even more elegant ;)
Feel free to provide suggestions etc.

Kristian

RSpec 2 example
---
describe 'Generator' do

  before :each do
    remove_model_file 'account'
  end

  GeneratorSpec.with_generator 'Generator' do |g, c, gc|
    gc.tests Canable::Generators::ModelGenerator
  end

  it "should not work without a User mode file" do
    GeneratorSpec.with_generator do |g|
      g.run_generator %w{account}
      g.should_not generate_file('app/models/account.rb')
    end
  end

  it "should not work without a User mode file" do
    GeneratorSpec.with_generator do |g|
      create_model_file 'account'
      g.run_generator %w{account}
      g.should generate_file('app/models/account.rb')
    end
  end
end


More information about the rspec-users mailing list