Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails script/generate skip unnecessary files by default

Script/generate became very annoying since I started using rspec etc. I dont need unit test files and fixtures anymore, but script/generate makes them anyway.

Is it possible to set --skip-fixtures and --skip-test to be default system-wide (or at least project-wide)?

like image 750
Mantas Avatar asked Dec 13 '22 04:12

Mantas


2 Answers

You can edit your applications script/generate file to auto append options

#!/usr/bin/env ruby

ARGV << "--skip-fixture" if ["model"].include?(ARGV[0])

require File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'
like image 83
Corban Brook Avatar answered Dec 30 '22 07:12

Corban Brook


Well, for starters,

ruby script/generate rspec_model
ruby script/generate rspec_controller

At least that doesn't generate unit tests and it gets the specs there for me :)

But --skip-fixtures still has to get passed. I've 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 :)

like image 26
Brian Hogan Avatar answered Dec 30 '22 07:12

Brian Hogan