Rails script / generate skip unnecessary files by default

Script / generate has become very annoying since I started using rspec etc. I no longer need unit test files and armatures, but script / generate does them anyway.

Is it possible to set --skip-fixtures and --skip-test by default for the whole system (or at least for the whole project)?

+4
source share
3 answers

You can edit your script applications / generate a file for auto-add options

 #!/usr/bin/env ruby ARGV << "--skip-fixture" if ["model"].include?(ARGV[0]) require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate' 
+6
source

Well, for starters,

 ruby script/generate rspec_model ruby script/generate rspec_controller 

At least this will not generate unit tests and it gets the specifications for me :)

But -skip-lamps still have to go through. I just made my own aliases in .bash_profile

 alias model='ruby script/generate rspec_model $1 --skip-fixture' 

Then I can just do

 model bar name:string active:boolean 

and it all works :)

+6
source

I use minitest_rails as a testing platform, and you can set some default values ​​through the config / application.rb file.

 config.generators do |g| g.test_framework :mini_test, :spec => true, :fixture => false end 

When you create a model (and controller), it now automatically skips the instrument. In this example, Unit Test will also be created using the minitest_spec format.

0
source

All Articles