Permalink
Browse files

Merge branch 'master' of git@github.com:paytonrules/selenium-on-rails

Conflicts:

	.gitignore
	test/selenium_on_rails_config_test.rb

Huge number of changes, but mostly relating to testing.


git-svn-id: https://svn.openqa.org/svn/selenium-on-rails/selenium-on-rails@126 9274398c-e119-0410-8437-aa71ef7847aa
  • Loading branch information...
2 parents d5ae749 + 25e0918 commit dbb235f76e584eb017c459c2b449a219fad39955 eric@8thlight.com committed Mar 7, 2009
View
@@ -1,2 +1,10 @@
+<<<<<<< HEAD:.gitignore
config.yml
-gems
+gems
+=======
+/config.yml
+test_data/html.html
+test_data/html.rsel
+test_data/html.sel
+coverage/*
+>>>>>>> 25e0918d65600c8c5fb76674368dbac4520434c4:.gitignore
View
1 README
@@ -327,6 +327,7 @@ the Selenese format.
* Jonas Bengston -- original creator
* Marcos Tapajós http://www.improveit.com.br/en/company/tapajos -- Several useful features
* Ryan Bates, http://railscasts.com -- Fixes for Rails 2.1
+* Nando Vieira, http://simplesideias.com.br
== Information
View
@@ -32,6 +32,7 @@ begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |t|
t.test_files = FileList['test/*_test.rb']
+ t.rcov_opts = ['-x /site_ruby/ -x .*gems.* --rails']
end
rescue LoadError #if rcov isn't available, ignore
end
@@ -9,6 +9,7 @@ def selenium_path
end
def selenium_tests_path
+ return SeleniumOnRailsConfig.get("selenium_tests_path") if SeleniumOnRailsConfig.get("selenium_tests_path")
File.expand_path(File.join(RAILS_ROOT, 'test/selenium'))
end
@@ -1,4 +1,5 @@
require 'yaml'
+require 'erb'
class SeleniumOnRailsConfig
@@defaults = {:environments => ['test']}
@@ -14,9 +15,12 @@ def self.get var, default = nil
def self.configs
@@configs ||= nil
unless @@configs
- files = [File.join(RAILS_ROOT, 'config', 'selenium.yml')]
+ files = [File.join(RAILS_ROOT, 'config', 'selenium.yml'), File.expand_path(File.dirname(__FILE__) + '/../config.yml')]
files.each do |file|
- @@configs = YAML.load(ERB.new(IO.read(file)).result) if File.exist?(file)
+ if File.exist?(file)
+ @@configs = YAML.load(ERB.new(IO.read(file)).result)
+ break
+ end
end
@@configs ||= {}
end
View
@@ -34,3 +34,4 @@ browsers:
#result_dir: 'c:\result' # the directory where the results will be stored after a test:acceptance run
#fixtures_path: <%= "#{RAILS_ROOT}/spec/fixtures" %>
+#selenium_tests_path: <%= "#{RAILS_ROOT}/spec/selenium" %>
View
@@ -0,0 +1,37 @@
+# Please read as our directions have changed:
+# Move this file to your rails apps config directory and rename it to selenium.yml in order to configure the plugin
+
+#
+# General settings
+#
+
+environments:
+ - test
+# - development # Uncomment this line to enable in development environment. N.B. your development database will likely be altered/destroyed/abducted
+
+#selenium_path: 'c:\selenium' #path to selenium installation. only needed if you for some reason don't want to use the bundled version of selenium core
+
+#
+# rake test:acceptance settings
+#
+
+browsers:
+ # Windows
+ # firefox: 'c:\Program Files\Mozilla Firefox\firefox.exe'
+ # ie: 'c:\Program Files\Internet Explorer\iexplore.exe'
+
+ # Mac OS X
+ firefox: '/Applications/Firefox.app/Contents/MacOS/firefox-bin'
+ safari: '/Applications/Safari.app/Contents/MacOS/Safari'
+
+#host: 'localhost'
+#port_start: 3000
+#port_end: 3005
+#base_url_path: '/'
+#max_browser_duration: 120
+#multi_window: false
+
+#result_dir: 'c:\result' # the directory where the results will be stored after a test:acceptance run
+
+#fixtures_path: <%= "#{RAILS_ROOT}/spec/fixtures" %>
+#selenium_tests_path: <%= "#{RAILS_ROOT}/spec/selenium" %>
View
@@ -0,0 +1,72 @@
+require File.dirname(__FILE__) + '/test_helper'
+require 'mocha'
+RAILS_ROOT = File.expand_path(File.dirname(__FILE__) + "/")
+
+class SeleniumOnRails::PathsTest < Test::Unit::TestCase
+
+ include SeleniumOnRails::Paths
+
+ def test_selenium_tests_path_when_config_has_not_selenium_tests_path
+ SeleniumOnRailsConfig.expects(:get).with("selenium_tests_path").returns(nil)
+ assert_equal "#{RAILS_ROOT}/test/selenium", selenium_tests_path
+ end
+
+ def test_selenium_tests_path_when_config_has_selenium_tests_path
+ SeleniumOnRailsConfig.expects(:get).with("selenium_tests_path").returns("path").at_least_once
+ assert_equal "path", selenium_tests_path
+ end
+
+ def test_fixtures_path_when_config_has_not_fixtures_path
+ SeleniumOnRailsConfig.expects(:get).with("fixtures_path").returns(nil)
+ assert_equal "#{RAILS_ROOT}/test/fixtures", fixtures_path
+ end
+
+ def test_fixtures_path_when_config_has_fixtures_path
+ SeleniumOnRailsConfig.expects(:get).with("fixtures_path").returns("path").at_least_once
+ assert_equal "path", fixtures_path
+ end
+
+ def test_view_path
+ assert_equal File.expand_path("#{RAILS_ROOT}/../lib/views/my_view"), view_path('my_view')
+ end
+
+ def test_layout_path
+ assert_equal "layout.rhtml", layout_path
+ end
+
+ def test_skip_file_when_file_contain_CVS
+ assert skip_file?("file/with/CVS/in/the/middle/of/path")
+ end
+
+ def test_skip_file_when_file_contain_dot
+ assert skip_file?("file/with/./(dot)/in/the/middle/of/path")
+ end
+
+ def test_skip_file_when_file_contain_underline
+ assert skip_file?("file/with/_underline/in/the/middle/of/path")
+ end
+
+ def test_skip_file_when_file_contain_accent_mark
+ assert skip_file?("file/with/mark~/in/the/middle/of/path")
+ end
+
+ def test_skip_file_when_file_does_not_have_any_reason_to_skip
+ assert !skip_file?("my/valid/file")
+ end
+
+ def test_selenium_path
+ assert_equal File.expand_path("#{RAILS_ROOT}/../selenium-core") + "/", selenium_path
+ end
+
+ def test_selenium_path_when_selenium_core_installation_is_not_found
+ selenium_core_path = File.expand_path(File.dirname(__FILE__) + "/../selenium-core")
+
+ File.expects(:exist?).with("#{selenium_core_path}/core/TestRunner.html").returns(false)
+ File.expects(:exist?).with("#{selenium_core_path}/selenium/TestRunner.html").returns(false)
+ File.expects(:exist?).with("#{selenium_core_path}/javascript/TestRunner.html").returns(false)
+ File.expects(:exist?).with("#{selenium_core_path}/TestRunner.html").returns(false)
+ @@selenium_path = nil
+ assert_raise(RuntimeError) { selenium_path }
+ end
+
+end
View
@@ -2,7 +2,9 @@
class RendererTest < Test::Unit::TestCase
def setup
+ SeleniumOnRails::PartialsSupport.send(:include, SeleniumOnRails::PathsTestHelper)
@controller = SeleniumController.new
+ @controller.extend(SeleniumOnRails::PathsTestHelper)
ActionController::Routing::Routes.draw
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@@ -20,8 +22,6 @@ def test_route
end
def test_html
- get :test_file, :testname => 'html.html'
- assert_headers
expected =<<END
<html><head><title>test layout</title></head><body>
<p>Testing plain HTML</p>
@@ -32,8 +32,16 @@ def test_html
<p>and it works...</p>
</body></html>
END
+ File.open(test_path_for('html.html'), 'w+') { |index_file| index_file << expected }
+ get :test_file, :testname => 'html.html'
+ assert_headers
+
assert_text_equal expected, @response.body
end
+
+ def test_path_for(name)
+ "#{File.expand_path(File.dirname(__FILE__) + "/../test_data")}/#{name}"
+ end
def test_rhtml
get :test_file, :testname => 'rhtml.rhtml'
View
@@ -9,8 +9,8 @@ def render_rselenese(page_title, input)
create_rsel_file_from(input, "html.rsel")
@view = TestView.new
+ @view.extend(SeleniumOnRails::PathsTestHelper)
@sel = SeleniumOnRails::RSelenese.new(@view)
-
@sel.render ActionView::Template.new(test_path_for("html.rsel")), {'page_title' => page_title}
end
View
@@ -4,6 +4,7 @@ class SeleneseTest < Test::Unit::TestCase
def setup
@view = TestView.new
+ @view.extend(SeleniumOnRails::PathsTestHelper)
@sel = SeleniumOnRails::Selenese.new(@view)
end
@@ -46,7 +47,7 @@ def test_one_line
assert_selenese expected, 'One line', input
end
- def test_comments_only
+ def test_comments_only
expected = <<END
<p>Comment <strong>1</strong></p>
@@ -57,7 +58,6 @@ def test_comments_only
</table>
END
input = <<END
-
Comment *1*
Comment 2
@@ -5,6 +5,7 @@ class SeleniumControllerTest < Test::Unit::TestCase
def setup
@controller = SeleniumController.new
+ @controller.extend(SeleniumOnRails::PathsTestHelper)
ActionController::Routing::Routes.draw
SeleniumController.any_instance.stubs(:layout_path).returns(false)
@request = ActionController::TestRequest.new
@@ -12,14 +12,32 @@ class SeleniumOnRailsConfigTest < Test::Unit::TestCase
def setup
SeleniumOnRailsConfig.reset_config
@selenium_file = File.join(RAILS_ROOT, 'config', 'selenium.yml')
+ @config_file = File.expand_path(File.dirname(__FILE__) + '/../config.yml')
@selenium_content = File.read(File.dirname(__FILE__) + '/fixtures/selenium.yml')
+ @config_content = File.read(File.dirname(__FILE__) + '/fixtures/config.yml')
end
def test_get_selenium_yaml
File.expects(:exist?).with(@selenium_file).returns(true)
IO.expects(:read).with(@selenium_file).returns(@selenium_content)
+ IO.expects(:read).with(@config_file).never
+ IO.expects(:exist?).with(@config_file).never
+
assert_equal ["test_cache"], SeleniumOnRailsConfig.get(:environments)
assert_equal({"firefox"=>"script/openfirefox"}, SeleniumOnRailsConfig.get(:browsers))
end
-
+
+ def test_get_when_config_yml_exists_but_selenium_yaml_not
+ File.expects(:exist?).with(@selenium_file).returns(false)
+ File.expects(:exist?).with(@config_file).returns(true)
+ IO.expects(:read).with(@config_file).returns(@config_content)
+ IO.expects(:read).with(@selenium_file).never
+
+ assert_equal ["test"], SeleniumOnRailsConfig.get(:environments)
+ expected_config = {"safari"=>"/Applications/Safari.app/Contents/MacOS/Safari",
+ "firefox"=>"/Applications/Firefox.app/Contents/MacOS/firefox-bin"}
+
+ assert_equal(expected_config, SeleniumOnRailsConfig.get(:browsers))
+ end
+
end
@@ -3,6 +3,7 @@
class SeleniumSupportTest < Test::Unit::TestCase
def setup
@controller = SeleniumController.new
+ @controller.extend(SeleniumOnRails::PathsTestHelper)
ActionController::Routing::Routes.draw
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
View
@@ -5,6 +5,7 @@
class SetupTest < Test::Unit::TestCase
def setup
@controller = SeleniumController.new
+ @controller.extend(SeleniumOnRails::PathsTestHelper)
SeleniumController.any_instance.stubs(:clear_tables).returns([])
SeleniumController.any_instance.stubs(:layout_path).returns(false)
ActionController::Routing::Routes.draw
@@ -3,6 +3,7 @@
class SuiteRendererTest < Test::Unit::TestCase
def setup
@controller = SeleniumController.new
+ @controller.extend(SeleniumOnRails::PathsTestHelper)
ActionController::Routing::Routes.draw
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
View
@@ -6,6 +6,7 @@
gem 'activesupport'
require 'active_support'
+gem 'actionpack'
require 'action_view/template_handler'
require 'action_view/template_handlers/builder'
require 'action_view/template_handlers/erb'
@@ -31,11 +32,6 @@ def setup_controller_test(controller)
@response = ActionController::TestResponse.new
end
-module SeleniumOnRails::Paths
- def selenium_tests_path
- File.expand_path(File.dirname(__FILE__) + '/../test_data')
- end
-end
class SeleniumController
attr_accessor :layout_override
@@ -76,6 +72,12 @@ def clean_text text
end
+module SeleniumOnRails::PathsTestHelper
+ def selenium_tests_path
+ File.expand_path(File.dirname(__FILE__) + '/../test_data')
+ end
+end
+
class TestView < ActionView::Base
include SeleniumOnRails::PartialsSupport
View
@@ -1,6 +0,0 @@
-<p>Testing plain HTML</p>
-<table>
- <tr><th colspan="3">Test HTML</th></tr>
- <tr><td>open</td><td>/selenium/setup</td><td>&nbsp;</td></tr>
-</table>
-<p>and it works...</p>

0 comments on commit dbb235f

Please sign in to comment.