omghax-test_rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +21 -0
- data/README.txt +110 -0
- data/Rakefile +13 -0
- data/lib/test/rails/controller_test_case.rb +382 -0
- data/lib/test/rails/functional_test_case.rb +79 -0
- data/lib/test/rails/helper_test_case.rb +64 -0
- data/lib/test/rails/ivar_proxy.rb +31 -0
- data/lib/test/rails/pp_html_document.rb +74 -0
- data/lib/test/rails/rake_tasks.rb +50 -0
- data/lib/test/rails/render_tree.rb +93 -0
- data/lib/test/rails/test_case.rb +28 -0
- data/lib/test/rails/version.rb +11 -0
- data/lib/test/rails/view_test_case.rb +597 -0
- data/lib/test/rails.rb +295 -0
- data/lib/test/zentest_assertions.rb +134 -0
- data/test/test_help.rb +36 -0
- data/test/test_rails_controller_test_case.rb +58 -0
- data/test/test_rails_helper_test_case.rb +48 -0
- data/test/test_rails_view_test_case.rb +275 -0
- data/test/test_zentest_assertions.rb +128 -0
- metadata +94 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
class HTML::Document
|
2
|
+
def pretty_print(q)
|
3
|
+
q.object_address_group self do
|
4
|
+
q.breakable
|
5
|
+
q.seplist @root.children_without_newlines do |v| q.pp v end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class HTML::Node
|
11
|
+
def children_without_newlines
|
12
|
+
@children.reject do |c|
|
13
|
+
HTML::Text == c.class and c.content_without_whitespace == "\n"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def pretty_print(q)
|
18
|
+
q.group 1, '[NODE ', ']' do
|
19
|
+
q.breakable
|
20
|
+
q.seplist children_without_newlines do |v| q.pp v end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class HTML::Tag
|
26
|
+
def pretty_print(q)
|
27
|
+
case @closing
|
28
|
+
when :close then
|
29
|
+
q.text "[close #{@name}]"
|
30
|
+
when :self then
|
31
|
+
pretty_print_tag 'empty', q
|
32
|
+
when nil then
|
33
|
+
pretty_print_tag 'open ', q
|
34
|
+
else
|
35
|
+
raise "Unknown closing #{@closing.inspect}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def pretty_print_tag(type, q)
|
40
|
+
q.group 1, "(#{type} #{@name.inspect}", ')' do
|
41
|
+
unless @attributes.empty? then
|
42
|
+
q.breakable
|
43
|
+
q.pp @attributes
|
44
|
+
end
|
45
|
+
unless children_without_newlines.empty? then
|
46
|
+
q.breakable
|
47
|
+
q.group 1, '[', ']' do
|
48
|
+
q.seplist children_without_newlines do |v|
|
49
|
+
q.pp v
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class HTML::Text
|
58
|
+
def content_without_whitespace
|
59
|
+
@content.gsub(/^[ ]+/, '').sub(/[ ]+\Z/, '')
|
60
|
+
end
|
61
|
+
|
62
|
+
def pretty_print(q)
|
63
|
+
q.pp content_without_whitespace
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class HTML::CDATA
|
68
|
+
def pretty_print(q)
|
69
|
+
q.group 1, '[', ']' do
|
70
|
+
q.pp @content
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'code_statistics'
|
2
|
+
|
3
|
+
def define_test_task(test_type)
|
4
|
+
desc "Run the #{test_type} tests in test/#{test_type}s"
|
5
|
+
Rake::TestTask.new "#{test_type}s" => [ 'db:test:prepare' ] do |t|
|
6
|
+
t.libs << 'test'
|
7
|
+
t.pattern = "test/#{test_type}s/**/*_test.rb"
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace :test do
|
13
|
+
define_test_task 'helper'
|
14
|
+
define_test_task 'view'
|
15
|
+
define_test_task 'controller'
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Run all tests'
|
19
|
+
task :test => %w[
|
20
|
+
test:units
|
21
|
+
test:controllers
|
22
|
+
test:helpers
|
23
|
+
test:views
|
24
|
+
test:functionals
|
25
|
+
test:integration
|
26
|
+
]
|
27
|
+
|
28
|
+
dirs = [
|
29
|
+
%w[Libraries lib/],
|
30
|
+
%w[Models app/models],
|
31
|
+
%w[Unit\ tests test/unit],
|
32
|
+
%w[Helpers app/helpers],
|
33
|
+
%w[Helper\ tests test/helpers],
|
34
|
+
%w[Components components],
|
35
|
+
%w[Controllers app/controllers],
|
36
|
+
%w[Controller\ tests test/controllers],
|
37
|
+
%w[View\ tests test/views],
|
38
|
+
%w[Functional\ tests test/functional],
|
39
|
+
%w[Integration\ tests test/integration],
|
40
|
+
%w[APIs app/apis],
|
41
|
+
]
|
42
|
+
|
43
|
+
dirs = dirs.map { |name, dir| [name, File.join(RAILS_ROOT, dir)] }
|
44
|
+
dirs = dirs.select { |name, dir| File.directory? dir }
|
45
|
+
|
46
|
+
STATS_DIRECTORIES.replace dirs
|
47
|
+
|
48
|
+
new_test_types = ['Controller tests', 'Helper tests', 'View tests']
|
49
|
+
CodeStatistics::TEST_TYPES.push(*new_test_types)
|
50
|
+
|
@@ -0,0 +1,93 @@
|
|
1
|
+
##
|
2
|
+
# test/rails/render_tree.rb adds debug rendering to ActionView::Base#render.
|
3
|
+
#
|
4
|
+
# Debug rendering prints out a tree of calls to render allowing you to easily
|
5
|
+
# visualize where rendering occurs in unfamiliar code.
|
6
|
+
|
7
|
+
class ActionView::Base
|
8
|
+
|
9
|
+
alias plain_render render # :nodoc:
|
10
|
+
|
11
|
+
##
|
12
|
+
# List of render types for ActionView::Base#render
|
13
|
+
|
14
|
+
RENDERS = [:partial, :template, :file, :action, :text, :inline, :nothing,
|
15
|
+
:update]
|
16
|
+
|
17
|
+
##
|
18
|
+
# Add debug output to rendering.
|
19
|
+
#
|
20
|
+
# When you include lib/rails/render_tree a tree of renders will be displayed
|
21
|
+
# in the console. This is especially useful when writing tests.
|
22
|
+
#
|
23
|
+
# This test:
|
24
|
+
#
|
25
|
+
# require 'test/test_helper'
|
26
|
+
# require 'test/rails/render_tree'
|
27
|
+
#
|
28
|
+
# class ThingsViewTest < Test::Rails::ViewTestCase
|
29
|
+
#
|
30
|
+
# fixtures :goals
|
31
|
+
#
|
32
|
+
# def test_body
|
33
|
+
# assigns[:goal] = goals(:first)
|
34
|
+
# assigns[:related_goals_moved] = []
|
35
|
+
# assigns[:related_goals_instead] = []
|
36
|
+
#
|
37
|
+
# render :partial => 'things/body'
|
38
|
+
#
|
39
|
+
# assert_tag :tag => 'div', :attributes => { :id => 'entriesbucket' }
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# Will give this output when run:
|
45
|
+
#
|
46
|
+
# $ ruby test/views/things_view_test.rb -n test_body
|
47
|
+
# Loaded suite test/views/things_view_test
|
48
|
+
# Started
|
49
|
+
# "things/_body"
|
50
|
+
# :partial => "widgets/goals_gallery_teaser"
|
51
|
+
# "widgets/_goals_gallery_teaser"
|
52
|
+
# :partial => "entries_bucket"
|
53
|
+
# "things/_entries_bucket"
|
54
|
+
# :partial => "things/ask_a_question"
|
55
|
+
# "things/_ask_a_question"
|
56
|
+
# "widgets/forms/related_goals"
|
57
|
+
# .
|
58
|
+
# Finished in 1.293523 seconds.
|
59
|
+
#
|
60
|
+
# 1 tests, 1 assertions, 0 failures, 0 errors
|
61
|
+
|
62
|
+
def render(*args)
|
63
|
+
@level ||= 0
|
64
|
+
|
65
|
+
print ' ' * @level
|
66
|
+
|
67
|
+
case args.first
|
68
|
+
when String then
|
69
|
+
p args.first
|
70
|
+
when Hash then
|
71
|
+
hash = args.first
|
72
|
+
if hash.include? :collection and hash.include? :partial then
|
73
|
+
puts "%p => %p" % [:collection, hash[:partial]]
|
74
|
+
else
|
75
|
+
found = hash.keys & RENDERS
|
76
|
+
if found.length == 1 then
|
77
|
+
puts "%p => %p" % [found.first, hash[found.first]]
|
78
|
+
else
|
79
|
+
raise "Dunno: %p" % [hash]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
else
|
83
|
+
raise "Dunno: %p" % [args]
|
84
|
+
end
|
85
|
+
|
86
|
+
@level += 1
|
87
|
+
result = plain_render(*args)
|
88
|
+
@level -= 1
|
89
|
+
result
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
##
|
2
|
+
# Test::Rails::TestCase is an abstract test case for Test::Rails test cases.
|
3
|
+
#--
|
4
|
+
# Eventually this will hold the fixture setup stuff.
|
5
|
+
|
6
|
+
class Test::Rails::TestCase < Test::Unit::TestCase
|
7
|
+
|
8
|
+
undef_method :default_test
|
9
|
+
|
10
|
+
# Set defaults because Rails has poor ones (and these don't inherit properly)
|
11
|
+
self.use_transactional_fixtures = true
|
12
|
+
self.use_instantiated_fixtures = false
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
module Test::Unit::Assertions
|
17
|
+
##
|
18
|
+
# TODO: should this go in this file?
|
19
|
+
# Asserts that model indeed has a given callback
|
20
|
+
#
|
21
|
+
# assert_callback(Model, :before_save, :something)
|
22
|
+
|
23
|
+
def assert_callback(model_class, callback, method_name, message=nil)
|
24
|
+
vars = model_class.instance_variable_get(:@inheritable_attributes)
|
25
|
+
assert vars.has_key?(callback), message
|
26
|
+
assert_include vars[callback], method_name, message
|
27
|
+
end
|
28
|
+
end
|