Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Test::Unit support for 'rails generate model' #77

Open
wants to merge 1 commit into from

5 participants

@emk

Greetings, and thank you so much for such an excellent fixture replacement gem! I especially love the tight, painless integration between machinist and Rails 3.

One of my clients uses Test::Unit, and I discovered a small limitation when install machinist.

The existing install_generator supports both Test::Unit and RSpec,
but model_generator always assumes that our blueprints live in
spec/support/blueprints.rb.

This patch adds support for Test::Unit to model_generator. Note that
there is now a small amount of code duplication between model_generator
and install_generator that should probably by factored out into a shared
module.

No unit tests are included, because I didn't see any tests for the existing generators, and I'm not quite sure how to set them up.

If you have any suggestions on rewriting this patch to either (1) include unit tests, or (2) factor out the shared generator code, please let me know. I'll be glad to make any changes you suggest.

Once again, many thanks for your excellent gem!

@emk emk model_generator: Add support for Test::Unit
The existing install_generator supports both Test::Unit and RSpec,
but model_generator always assumes that our blueprints live in
spec/support/blueprints.rb.

This patch adds support for Test::Unit to model_generator.  Note that
there is now a small amount of code duplication between model_generator
and install_generator that should probably by factored out into a shared
module.
660ad9e
@dpehrson

Just ran into this as well, would be great to be able to use the machinist fixture replacement with Test::Unit

@lgs

me too

lsoave@ubuntu:~/rails/github/trends$ rails g scaffold trends 
Plural version of the model detected, using singularized version. Override with --force-plural.
      invoke  mongoid
      create    app/models/trend.rb
      invoke    rspec
      create      spec/models/trend_spec.rb
      invoke      machinist
      append        spec/support/blueprints.rb
/home/lsoave/.rvm/gems/ruby-1.9.2-p290@rails-3.2.1/gems/thor-0.14.6/lib/thor/actions/inject_into_file.rb:99:in `binread': No such file or directory - /home/lsoave/rails/github/trends/spec/support/blueprints.rb (Errno::ENOENT)
@jmbejar

Got the same problem because I'm using minitest instead of rspec :(

@danieltdt

@notahat any thoughts about this patch? I got the same problem here :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 19, 2011
  1. @emk

    model_generator: Add support for Test::Unit

    emk authored
    The existing install_generator supports both Test::Unit and RSpec,
    but model_generator always assumes that our blueprints live in
    spec/support/blueprints.rb.
    
    This patch adds support for Test::Unit to model_generator.  Note that
    there is now a small amount of code duplication between model_generator
    and install_generator that should probably by factored out into a shared
    module.
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 1 deletion.
  1. +11 −1 lib/generators/machinist/model/model_generator.rb
View
12 lib/generators/machinist/model/model_generator.rb
@@ -1,12 +1,22 @@
module Machinist
module Generators #:nodoc:
class ModelGenerator < Rails::Generators::NamedBase #:nodoc:
+ class_option :test_framework, :type => :string, :aliases => "-t", :desc => "Test framework to use Machinist with"
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
def create_blueprint
- append_file "spec/support/blueprints.rb", "\n#{class_name}.blueprint do\n # Attributes here\nend\n"
+ append_file blueprints_path, "\n#{class_name}.blueprint do\n # Attributes here\nend\n"
end
+ protected
+
+ def blueprints_path
+ if options[:test_framework].to_sym == :rspec
+ "spec/support/blueprints.rb"
+ else
+ "test/blueprints.rb"
+ end
+ end
end
end
end
Something went wrong with that request. Please try again.