alexrothenberg / ammeter

A gem that allows for you to write specs for your Rails 3 generators
MIT License
89 stars 28 forks source link

Rails assertions for generators #17

Open pabloh opened 11 years ago

pabloh commented 11 years ago

Rails provided assertions for generator tests aren't available, including them will make easier to add new matchers.

alexrothenberg commented 11 years ago

Could you please give me some more information about what you mean. Link to a TestUnit or MiniTest example that shows what you'd like to do with Ammeter & RSpec would be great.

Thanks

pabloh commented 11 years ago

There are many examples at https://github.com/rails/rails/blob/master/railties/test/generators

For example here: https://github.com/rails/rails/blob/master/railties/test/generators/model_generator_test.rb

You can see an assertion that tests file existence and its contents at the same time. Or another one that tests If a migration exists and if some method is defined inside it, also using a single assertion.

It would be nice if ammeter would allow to something like this:

file("file").should exist.and_contain(/some content/)

file("file").should be_a_migration do |contents|
  contents.should have_method(:change) do |body|
    body.should match(/t\.string :title/)
    body.assert match(/t\.text :body/)
    body.assert match(/t\.string :author/)
  end
end
alexrothenberg commented 11 years ago

ok i see what you are talking about now. These would be nice to have but to be honest I'm not sure when I'll have time to get around to it.

I'd love to merge a pull request if you're inclined to add some of these :)

d4rky-pl commented 10 years ago

Something akin to assert_method was implemented in #32 but it accepts string as a second argument. I was thinking of implementing something more similar but that'd break the rspec 2.x compatibility for now.

@alexrothenberg you should think about separate branches for rspec 2.x and 3.x versions if you want this gem to keep evolving instead of just keeping it working with newer releases.