Permalink
Browse files

We now run all tests in Rails 2.1.

git-svn-id: https://svn.openqa.org/svn/selenium-on-rails/selenium-on-rails@76 9274398c-e119-0410-8437-aa71ef7847aa
  • Loading branch information...
1 parent 766898b commit 9a82097b82274fefa471906610a4ea734557662a eric@8thlight.com committed Sep 12, 2008
View
8 lib/selenium_on_rails/rselenese.rb
@@ -8,7 +8,7 @@
# See SeleniumOnRails::TestBuilder for a list of available commands.
class SeleniumOnRails::RSelenese < SeleniumOnRails::TestBuilder
end
-ActionView::Base.register_template_handler 'rsel', SeleniumOnRails::RSelenese
+ActionView::Template.register_template_handler 'rsel', SeleniumOnRails::RSelenese
class SeleniumOnRails::RSelenese < SeleniumOnRails::TestBuilder
attr_accessor :view
@@ -20,16 +20,16 @@ def initialize view
end
# Render _template_ using _local_assigns_.
- def render template, locals
- local_assigns = locals
+ def render template
+ local_assigns = template.locals
title = (@view.assigns['page_title'] or local_assigns['page_title'])
table(title) do
test = self #to enable test.command
assign_locals_code = ''
local_assigns.each_key {|key| assign_locals_code << "#{key} = local_assigns[#{key.inspect}];"}
- eval assign_locals_code + "\n" + template
+ eval assign_locals_code + "\n" + template.source
end
end
View
8 lib/selenium_on_rails/selenese.rb
@@ -1,17 +1,17 @@
class SeleniumOnRails::Selenese
end
-ActionView::Base.register_template_handler 'sel', SeleniumOnRails::Selenese
+ActionView::Template.register_template_handler 'sel', SeleniumOnRails::Selenese
class SeleniumOnRails::Selenese
def initialize view
@view = view
end
- def render template, locals
- local_assigns = locals
+ def render template
+ local_assigns = template.locals
name = (@view.assigns['page_title'] or local_assigns['page_title'])
- lines = template.strip.split "\n"
+ lines = template.source.strip.split "\n"
html = ''
html << extract_comments(lines)
html << extract_commands(lines, name)
View
2 lib/views/selenium_on_rails/rselenese.rb
@@ -8,7 +8,7 @@
# See SeleniumOnRails::TestBuilder for a list of available commands.
class SeleniumOnRails::RSelenese < SeleniumOnRails::TestBuilder
end
-ActionView::Base.register_template_handler 'rsel', SeleniumOnRails::RSelenese
+ActionView::Template.register_template_handler 'rsel', SeleniumOnRails::RSelenese
class SeleniumOnRails::RSelenese < SeleniumOnRails::TestBuilder
attr_accessor :view
View
8 lib/views/selenium_on_rails/selenese.rb
@@ -1,16 +1,16 @@
class SeleniumOnRails::Selenese
end
-ActionView::Base.register_template_handler 'sel', SeleniumOnRails::Selenese
-# ActionView::Template.register_template_handler 'sel', SeleniumOnRails::Selenese
+# ActionView::Base.register_template_handler 'sel', SeleniumOnRails::Selenese
+ActionView::Template.register_template_handler 'sel', SeleniumOnRails::Selenese
class SeleniumOnRails::Selenese
def initialize view
@view = view
end
- def render template, locals
- local_assigns = locals
+ def render template
+ local_assigns = template.locals
name = (@view.assigns['page_title'] or local_assigns['page_title'])
lines = template.source.strip.split "\n"
html = ''
View
2 test/renderer_test.rb
@@ -15,7 +15,7 @@ def setup
def test_route
get :test_file, :testname => 'html.html' #initialize the controller
- assert_equal 'http://test.host/selenium/tests/suite/test_case.sel',
+ assert_equal 'http://test.host/selenium/tests/suite%2Ftest_case.sel',
@controller.url_for(:controller => 'selenium', :action => 'test_file', :testname => 'suite/test_case.sel')
end
View
22 test/rselenese_test.rb
@@ -4,10 +4,16 @@ class RSeleneseTest < Test::Unit::TestCase
include ERB::Util
def rselenese name, input, partial = nil, type = nil
- view = TestView.new(File.dirname(__FILE__))
+ view = TestView.new
+ view.finder.append_view_path File.dirname(__FILE__)
view.override_partial partial, type do
view.assigns['page_title'] = name
- view.render_template "rsel", input
+ path = File.dirname(__FILE__) + "html.rsel"
+ File.open(path, 'w+') do |index_file|
+ index_file << input
+ end
+ template = ActionView::Template.new(view, path, false, locals = {})
+ view.render_template template
end
end
@@ -305,7 +311,7 @@ def test_accessor_commands
assert_command_works :wait_for_table, :table_locator, :pattern
assert_command_works :wait_for_not_table, :table_locator, :pattern
- assert_raise RuntimeError do
+ assert_raise ActionView::TemplateError do
assert_command_works :store_selected, :locator, :option_locator, :variable
end
assert_command_works :assert_selected, :locator, :option_locator
@@ -411,7 +417,7 @@ def test_accessor_commands
assert_command_works :wait_for_attribute, :locator_and_attribute_name, :pattern
assert_command_works :wait_for_not_attribute, :locator_and_attribute_name, :pattern
- assert_raise RuntimeError do
+ assert_raise ActionView::TemplateError do
assert_command_works :store_ordered, :locator, :locator, :variable
end
assert_command_works :assert_ordered, :locator, :locator
@@ -445,7 +451,7 @@ def test_accessor_commands
assert_command_works :wait_for_visible, :locator
assert_command_works :wait_for_not_visible, :locator
- assert_raise RuntimeError do
+ assert_raise ActionView::TemplateError do
assert_command_works :store_error_on_next, :string
end
assert_command_works :assert_error_on_next, :string
@@ -455,7 +461,7 @@ def test_accessor_commands
assert_command_works :wait_for_error_on_next, :string
assert_command_works :wait_for_not_error_on_next, :string
- assert_raise RuntimeError do
+ assert_raise ActionView::TemplateError do
assert_command_works :store_failure_on_next, :string
end
assert_command_works :assert_failure_on_next, :string
@@ -617,7 +623,7 @@ def test_accessor_commands
assert_command_works :wait_for_expression, :script, :pattern
assert_command_works :wait_for_not_expression, :script, :pattern
- assert_raise RuntimeError do
+ assert_raise ActionView::TemplateError do
assert_command_works :store_whether_this_frame_match_frame_expression, :string, :string, :variable
end
assert_command_works :assert_whether_this_frame_match_frame_expression, :string, :string
@@ -627,7 +633,7 @@ def test_accessor_commands
assert_command_works :wait_for_whether_this_frame_match_frame_expression, :string, :string
assert_command_works :wait_for_not_whether_this_frame_match_frame_expression, :string, :string
- assert_raise RuntimeError do
+ assert_raise ActionView::TemplateError do
assert_command_works :store_whether_this_window_match_window_expression, :string, :string, :variable
end
assert_command_works :assert_whether_this_window_match_window_expression, :string, :string
View
16 test/selenese_test.rb
@@ -3,10 +3,16 @@
class SeleneseTest < Test::Unit::TestCase
def selenese name, input, partial = nil, type = nil
- view = TestView.new(File.dirname(__FILE__))
+ view = TestView.new
+ view.finder.append_view_path File.dirname(__FILE__)
view.override_partial partial, type do
view.assigns['page_title'] = name
- view.render_template "sel", input
+ path = File.dirname(__FILE__) + "html.sel"
+ File.open(path, 'w+') do |index_file|
+ index_file << input
+ end
+ template = ActionView::Template.new(view, path, false, locals = {})
+ view.render_template template
end
end
@@ -203,13 +209,13 @@ def test_partial_support_with_local_assigns
end
def test_raised_when_more_than_three_columns
- assert_raise RuntimeError, 'There might only be a maximum of three cells!' do
+ assert_raise ActionView::TemplateError, 'There might only be a maximum of three cells!' do
selenese 'name', '|col1|col2|col3|col4|'
end
end
def test_raised_when_more_than_one_set_of_commands
- assert_raise RuntimeError, 'You cannot have comments in the middle of commands!' do
+ assert_raise ActionView::TemplateError, 'You cannot have comments in the middle of commands!' do
input = <<END
comment
|command|
@@ -221,7 +227,7 @@ def test_raised_when_more_than_one_set_of_commands
end
def test_raised_when_incorrect_partial_format
- assert_raise RuntimeError, "Invalid format 'invalid'. Should be '|includePartial|partial|var1=value|var2=value|." do
+ assert_raise ActionView::TemplateError, "Invalid format 'invalid'. Should be '|includePartial|partial|var1=value|var2=value|." do
selenese 'name', '|includePartial|partial|a=valid|invalid|'
end
end
View
128 test/suite_renderer_test.rb
@@ -17,34 +17,16 @@ def test_empty_suite
get :test_file, :testname => 'empty_suite'
assert_response :success
- expected =<<END
-<html><head><title>test layout</title></head><body>
-<script type="text/javascript">
-<!--
-function openSuite(selector) {
- var suite = selector.options[selector.selectedIndex].value;
- if(suite == "header") return;
- if(top.location.href != location.href) //inside a frame
- top.location = "/selenium/TestRunner.html?test=tests" + suite
- else
- window.location = "/selenium/tests" + suite
-}
-//-->
-</script>
-<select onchange="openSuite(this)">
- <option value="header">Suites:</option>
- <option value="">..</option>
-</select>
-
-<table>
- <tr><th>Empty suite</th></tr>
-</table>
-</body></html>
-END
- assert_text_equal expected, @response.body
+ assert_tag :tag => "title", :content => "test layout"
+ assert_tag :tag => "script", :attributes => {:type => "text/javascript"}
+ assert_tag :tag => "select", :attributes => {:onchange => "openSuite(this)"},
+ :descendant => {:tag => "option", :attributes => {:value => "header"}, :content => "Suites:"},
+ :descendant => {:tag => "option", :attributes => {:value => ""}, :content => ".."}
+
+ assert_tag :tag => "table",
+ :descendant => {:tag => "th", :content => "Empty suite"}
end
-
def test_root_suite
_test_root_suite ''
end
@@ -83,81 +65,35 @@ def _test_root_suite testname
def test_suite_one
get :test_file, :testname => 'suite_one'
- assert_response :success
- expected =<<END
-<html><head><title>test layout</title></head><body>
-
-<script type="text/javascript">
-<!--
-function openSuite(selector) {
- var suite = selector.options[selector.selectedIndex].value;
- if(suite == "header") return;
- if(top.location.href != location.href) //inside a frame
- top.location = "/selenium/TestRunner.html?test=tests" + suite
- else
- window.location = "/selenium/tests" + suite
-}
-//-->
-</script>
-<select onchange="openSuite(this)">
- <option value="header">Suites:</option>
-
- <option value="">..</option>
-
- <option value="/suite_one/subsuite">Subsuite</option>
-
-</select>
-
-<table>
- <tr><th>Suite one</th></tr>
-
- <tr><td><a href="/selenium/tests/suite_one/suite_one_testcase1.sel">Suite one testcase1</a></td></tr>
-
- <tr><td><a href="/selenium/tests/suite_one/suite_one_testcase2.sel">Suite one testcase2</a></td></tr>
-
- <tr><td><a href="/selenium/tests/suite_one/subsuite/suite_one_subsuite_testcase.sel">Subsuite.Suite one subsuite testcase</a></td></tr>
-
-</table>
-</body></html>
-END
- assert_text_equal expected, @response.body
+
+ assert_response :success
+ assert_tag :tag => "title", :content => "test layout"
+ assert_tag :tag => "script", :attributes => {:type => "text/javascript"}
+ assert_tag :tag => "select", :attributes => {:onchange => "openSuite(this)"},
+ :descendant => {:tag => "option", :attributes => {:value => "header"}, :content => "Suites:"},
+ :descendant => {:tag => "option", :attributes => {:value => ""}, :content => ".."},
+ :descendant => {:tag => "option", :attributes => {:value => "/suite_one/subsuite"}, :content => "Subsuite"}
+
+ assert_tag :tag => "table",
+ :descendant => {:tag => "th", :content => "Suite one"},
+ :descendant => {:tag => "td", :content => "Suite one testcase1"},
+ :descendant => {:tag => "td", :content => "Suite one testcase2"},
+ :descendant => {:tag => "td", :content => "Subsuite.Suite one subsuite testcase"}
end
def test_sub_suite
get :test_file, :testname => 'suite_one/subsuite'
+
assert_response :success
- expected =<<END
-<html><head><title>test layout</title></head><body>
-
-<script type="text/javascript">
-<!--
-function openSuite(selector) {
- var suite = selector.options[selector.selectedIndex].value;
- if(suite == "header") return;
- if(top.location.href != location.href) //inside a frame
- top.location = "/selenium/TestRunner.html?test=tests" + suite
- else
- window.location = "/selenium/tests" + suite
-}
-//-->
-</script>
-<select onchange="openSuite(this)">
- <option value="header">Suites:</option>
-
- <option value="/suite_one">..</option>
-
-</select>
-
-<table>
- <tr><th>Subsuite</th></tr>
-
- <tr><td><a href="/selenium/tests/suite_one/subsuite/suite_one_subsuite_testcase.sel">Suite one subsuite testcase</a></td></tr>
-
-</table>
-</body></html>
-END
-
- assert_text_equal expected, @response.body
+ assert_tag :tag => "title", :content => "test layout"
+ assert_tag :tag => "script", :attributes => {:type => "text/javascript"}
+ assert_tag :tag => "select", :attributes => {:onchange => "openSuite(this)"},
+ :descendant => {:tag => "option", :attributes => {:value => "header"}, :content => "Suites:"},
+ :descendant => {:tag => "option", :attributes => {:value => "/suite_one"}, :content => ".."}
+
+ assert_tag :tag => "table",
+ :descendant => {:tag => "th", :content => "Subsuite"},
+ :descendant => {:tag => "td", :content => "Suite one subsuite testcase"}
end
def test_missing_tests_directory
View
1 test/test_helper.rb
@@ -6,6 +6,7 @@
require 'active_support'
require 'action_view/template_handler'
+require 'action_view/template_handlers/compilable'
require 'action_view/template_handlers/builder'
require 'action_view/template_handlers/erb'
require 'action_view/template_handlers/rjs'

0 comments on commit 9a82097

Please sign in to comment.