2009-05-19 50 views

回答

7

您可以運行生成器並忽略模型/遷移/燈具。

ruby script/generate rspec_model User --skip-migration --skip-fixture --skip 

我一直在尋找寫東西來做到這一點,但沒有任何其他人的興趣。

17

在用於Rails 3的rspec-rails-2中,所有rspec生成器都已被刪除。

您可以通過運行導軌模型生成器來解決此問題。您可以添加-s以跳過任何現有文件,並且可以使用--migration = false跳過創建遷移文件。

像這樣:

rails generate model example -s --migration=false 
+0

無法在導軌上工作3.2.x – Rubytastic 2013-03-28 19:11:22

0

https://gist.github.com/omenking/7774140

require 'fileutils' 
namespace :spec do 

    def progress name, x, y 
    print "\r #{name}: #{x}/#{y} %6.2f%%" % [x.to_f/y * 100] 
    end 

    def generate_files name 
    kind  = name.to_s.singularize 
    collection = Dir.glob Rails.root.join('app',name.to_s,'**','*').to_s 
    root  = Rails.root.join('app',name.to_s).to_s<<'/' 
    ext  = case name 
        when :controllers then '_controller.rb' 
        when :models  then '.rb' 
       end 
    count = collection.count 
    collection.each_with_index do |i,index| 
     `rails g #{kind} #{$1} -s` if i =~ /#{root}(.+)#{ext}/ 
     progress name, index, count 
    end 
    end 

    task generate_missing: :environment do 
    generate_files :controllers 
    generate_files :models 
    end 
end 

# if you dont want certian things generated than 
# configure your generators in your application.rb eg. 
# 
# config.generators do |g| 
#  g.orm :active_record 
#  g.template_engine :haml 
#  g.stylesheets false 
#  g.javascripts false 
#  g.test_framework :rspec, 
#      fixture: false, 
#      fixture_replacement: nil 
# end 
# 
1

如果缺少規範的數量是相當小的,你可以簡單地缺少規範運行的每個組件rails generate命令。

當發生衝突時,只需選擇不覆蓋原始文件。生成器將忽略現有文件並生成缺失的文件。