require 'test/unit' require 'rails/all' require 'rails/generators' require 'rails/generators/test_case' require 'rspec_for_generators/rails_spec_helper' # Call configure to load the settings from # Rails.application.config.generators to Rails::Generators # require the generators def require_generators *generator_list generator_list.each do |name, generators| if !generators || generators.empty require File.join('generators', name.to_s, "#{name.to_s}_generator") else generators.each do |generator_name| require File.join('generators', name.to_s, generator_name.to_s, "#{generator_name}_generator") end end end end alias :require_generator :require_generators module RSpec module Generator class << self attr_accessor :generator, :test_method_name, :remove_temp_dir def remove_rails_dir! FileUtils.rm_rf ::TmpRails.root end def configure_root_dir path, options = {} ::Rails.application.configure do config.root_dir = options == :custom ? TmpRails.root_dir(File.dirname(path) + '/../tmp', :custom) : TmpRails.root_dir(path) end ::RSpec.configure do |config| config.after(:suite) do ::RSpec::Generator.remove_rails_dir! if remove_temp_dir end end ::RSpec::Generators::TestCase.destination ::Rails.root ::Rails::Generators.configure! end def run_generator *args, &block generator.run_generator *args if block block.arity < 1 ? generator.instance_eval(&block) : block.call(generator, self) end end def check(&block) if block block.arity < 1 ? self.instance_eval(&block) : block.call(self) end end def with(generator, &block) if block block.arity < 1 ? generator.instance_eval(&block) : block.call(generator, self, generator.class) end end def with_generator &block with(get_generator, &block) end def setup_generator test_method_name=nil, &block clean! if test_method_name generator = get_generator(test_method_name).extend(RSpec::Generator::Helpers) if block block.arity < 1 ? generator.class.instance_eval(&block) : block.call(generator.class) end end protected def clean! if generator generator.class.generator_class = nil end @generator = nil end def get_generator test_method_name=nil @generator ||= RSpec::Generators::TestCase.new(test_method_name + '_spec') end end # class self end end