blob: 7c5183e6c84a9f781f0eb5dd5f0e399c6f8d8829 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
require 'abstract_unit'
require 'active_support/core_ext/module/remove_method'
require 'rails/generators'
require 'rails/generators/test_case'
module Rails
class << self
remove_possible_method :root
def root
@root ||= Pathname.new(File.expand_path('../../fixtures', __FILE__))
end
end
end
Rails.application.config.root = Rails.root
Rails.application.config.generators.templates = [File.join(Rails.root, "lib", "templates")]
# Call configure to load the settings from
# Rails.application.config.generators to Rails::Generators
Rails.application.load_generators
require 'active_record'
require 'action_dispatch'
require 'action_view'
module GeneratorsTestHelper
def self.included(base)
base.class_eval do
destination File.join(Rails.root, "tmp")
setup :prepare_destination
begin
base.tests Rails::Generators.const_get(base.name.sub(/Test$/, ''))
rescue
end
end
end
def copy_routes
routes = File.expand_path("../../../lib/rails/generators/rails/app/templates/config/routes.rb", __FILE__)
destination = File.join(destination_root, "config")
FileUtils.mkdir_p(destination)
FileUtils.cp routes, destination
end
def quietly
silence_stream(STDOUT) do
silence_stream(STDERR) do
yield
end
end
end
def silence_stream(stream)
old_stream = stream.dup
stream.reopen(IO::NULL)
stream.sync = true
yield
ensure
stream.reopen(old_stream)
old_stream.close
end
end
|