This repository has been archived by the owner on Oct 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
test_helper.rb
78 lines (67 loc) · 2.06 KB
/
test_helper.rb
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'bundler'
Bundler.require
require 'test/unit'
require 'rails/all'
require 'rails/generators'
require 'rails/generators/test_case'
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
end
Rails.application = TestApp
module Rails
def self.root
@root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails'))
end
end
Rails.application.config.root = Rails.root
# Call configure to load the settings from
# Rails.application.config.generators to Rails::Generators
Rails::Generators.configure!
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
def copy_routes
routes = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'routes.rb'))
destination = File.join(Rails.root, "config")
FileUtils.mkdir_p(destination)
FileUtils.cp File.expand_path(routes), destination
end
# Asserts the given class exists in the given content. When a block is given,
# it yields the content of the class.
#
# assert_file "test/functional/accounts_controller_test.rb" do |controller_test|
# assert_class "AccountsControllerTest", controller_test do |klass|
# assert_match /context "index action"/, klass
# end
# end
#
def assert_class(klass, content)
assert content =~ /class #{klass}(\(.+\))?(.*?)\nend/m, "Expected to have class #{klass}"
yield $2.strip if block_given?
end
def generator_list
{
:rails => ['scaffold', 'controller'],
:erubis => ['scaffold'],
:simple_form => ['scaffold'],
:formtastic => ['scaffold'],
:authlogic => ['session'],
:koala => ['install'],
:shoulda => ['controller', 'scaffold']
}
end
def path_prefix(name)
case name
when :rails
'rails/generators'
else
'generators'
end
end
def require_generators(generator_list)
generator_list.each do |name, generators|
generators.each do |generator_name|
require File.join(path_prefix(name), name.to_s, generator_name.to_s, "#{generator_name}_generator")
end
end
end
alias :require_generator :require_generators
require_generators generator_list