env.rb
1.87 KB
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
require 'test/unit'
module Test::Unit::Assertions
def assert_generated_file(path)
assert_file_exists(path)
if block_given?
File.open(File.join(@rails_root, path)) do |file|
expected = yield
body = file.read
assert body.include?(expected),
"expected #{expected} but was #{body}"
end
end
end
def assert_generated_empty_file(path)
assert_file_exists(path)
File.open(File.join(@rails_root, path)) do |file|
body = file.read
assert body.empty?,
"expected body to be empty but was #{body.inspect}"
end
end
def assert_file_exists(path)
file = File.join(@rails_root, path)
assert File.exists?(file), "#{file} expected to exist, but did not"
assert File.file?(file), "#{file} expected to be a file, but is not"
end
def assert_generated_views_for(name, *actions)
actions.each do |action|
assert_generated_file("app/views/#{name}/#{action}.html.erb") do
yield if block_given?
end
end
end
def assert_generated_migration(name)
file = Dir.glob("#{@rails_root}/db/migrate/*_#{name}.rb").first
file = file.match(/db\/migrate\/[0-9]+_\w+/).to_s << ".rb"
assert_generated_file(file) { "timestamps" }
assert_generated_file(file) { yield if block_given? }
end
def assert_generated_route_for(name, *actions)
routeable_actions = actions.collect { |action| ":#{action}" }.join(", ")
assert_generated_file("config/routes.rb") do
" map.resources :#{name.to_s}, :only => [#{routeable_actions}]"
end
end
def assert_has_empty_method(body, *methods)
methods.each do |name|
assert body.include?(" def #{name}\n end"),
"should have method #{name} in #{body.inspect}"
yield(name, $2) if block_given?
end
end
end
class BlitzWorld
include Test::Unit::Assertions
end
World do
BlitzWorld.new
end