require File.dirname(__FILE__) + '/test_helper' class SeleneseTest < Test::Unit::TestCase def setup @view = TestView.new @view.extend(SeleniumOnRails::PathsTestHelper) @sel = SeleniumOnRails::Selenese.new(@view) end def render_selenese(page_title, input) create_sel_file_from(input, "html.sel") @sel.render ActionView::Template.new(test_path_for("html.sel")), {'page_title' => page_title} end def create_sel_file_from(input, name) File.open(test_path_for(name), 'w+') { |index_file| index_file << input } end def test_path_for(name) "#{File.expand_path(File.dirname(__FILE__) + "/../test_data")}/#{name}" end def assert_selenese expected, name, input assert_text_equal expected, render_selenese(name, input) end def test_empty expected = < Empty END input = '' assert_selenese expected, 'Empty', '' end def test_one_line expected = < One line open/  END input = '|open|/|' assert_selenese expected, 'One line', input end def test_comments_only expected = <Comment 1

Comment 2

Only comments
END input = < Only commands goBack   open/foo  fireEventtextFieldfocus END input = < Commands and comments goBack   fireEventtextFieldfocus

Comment 1

Comment 2

END input = <Comment 1

Comment 2

Comments and commands
goBack  
fireEventtextFieldfocus
END input = <Comment 1

Comment 2

Comments, commands and comments
goBack  
fireEventtextFieldfocus

Comment 3

END input = < HTML escaping typenameField<>& END input = '|type|nameField|<>&|' assert_selenese expected, 'HTML escaping', input end def test_partial_support expected = < Partial support typepartialSelenese partial END input = '|includePartial|override|' partial = '|type|partial|Selenese partial|' create_sel_file_from(partial, "_override.sel") assert_selenese(expected, 'Partial support', input) File.delete(test_path_for("_override.sel")) end def test_partial_support_with_local_assigns expected = < Partial support with local assigns typeassignsa=hello,b=world!,c_123ABC= typeassignsa=a b c d,b=,c_123ABC=hello END_EXPECTED input = <whatever typeassigns a=<%= a if defined? a%>, b=<%= b if defined? b%>, c_123ABC=<%= c_123ABC if defined? c_123ABC%> END_PARTIAL create_sel_file_from(partial, "_override.html") assert_selenese(expected, 'Partial support with local assigns', input) File.delete(test_path_for("_override.html")) end def test_raised_when_more_than_three_columns assert_raise RuntimeError, 'There might only be a maximum of three cells!' do render_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 input = <