test_helper.rb
2.07 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
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
require 'test_help'
require 'controllers/selenium_controller'
module SeleniumOnRails::Paths
def selenium_tests_path
File.expand_path(File.dirname(__FILE__) + '/../test_data')
end
end
class SeleniumController
attr_accessor :layout_override
# Re-raise errors caught by the controller.
def rescue_action e
raise e
end
def render options = nil, deprecated_status = nil
if override_layout? options
options[:layout] = false
super options, deprecated_status
return response.body = @layout_override.gsub('@content_for_layout', response.body)
end
super options, deprecated_status
end
private
def override_layout? options
return false unless @layout_override
if options[:action] or options[:template]
options[:layout] != false #for action and template the default layout is used if not explicitly disabled
else
not [nil, false].include? options[:layout] #otherwise a layout has to be specified
end
end
end
class Test::Unit::TestCase
def assert_text_equal expected, actual
assert_equal clean_text(expected), clean_text(actual)
end
def clean_text text
text.gsub("\t", ' ').gsub("\r", '').gsub("\n", '').gsub(/ *</, '<')
end
end
class TestView < ActionView::Base
include SeleniumOnRails::PartialsSupport
alias_method :render_partial_without_override, :render_partial
def render_partial partial_path = default_template_name, object = nil, local_assigns = nil, status = nil
if @override
partial = render :inline => @override, :type => @override_type, :locals => local_assigns
extract_commands_from_partial partial
else
render_partial_without_override partial_path, object, local_assigns, status
end
end
def override_partial partial, type
@override, @override_type = partial, type
result = yield
@override, @override_type = nil, nil
result
end
end