Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:paytonrules/selenium-on-rails
Browse files Browse the repository at this point in the history
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
eric@8thlight.com committed Mar 7, 2009
2 parents d5ae749 + 25e0918 commit dbb235f
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 20 deletions.
10 changes: 9 additions & 1 deletion .gitignore
@@ -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
1 change: 1 addition & 0 deletions README
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/selenium_on_rails/paths.rb
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions lib/selenium_on_rails_config.rb
@@ -1,4 +1,5 @@
require 'yaml'
require 'erb'

class SeleniumOnRailsConfig
@@defaults = {:environments => ['test']}
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions selenium.yml.example
Expand Up @@ -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" %>
37 changes: 37 additions & 0 deletions test/fixtures/config.yml
@@ -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" %>
72 changes: 72 additions & 0 deletions test/paths_test.rb
@@ -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
12 changes: 10 additions & 2 deletions test/renderer_test.rb
Expand Up @@ -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
Expand All @@ -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>
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion test/rselenese_test.rb
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/selenese_test.rb
Expand Up @@ -4,6 +4,7 @@ class SeleneseTest < Test::Unit::TestCase

def setup
@view = TestView.new
@view.extend(SeleniumOnRails::PathsTestHelper)
@sel = SeleniumOnRails::Selenese.new(@view)
end

Expand Down Expand Up @@ -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>
Expand All @@ -57,7 +58,6 @@ def test_comments_only
</table>
END
input = <<END
Comment *1*
Comment 2
Expand Down
1 change: 1 addition & 0 deletions test/selenium_controller_test.rb
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion test/selenium_on_rails_config_test.rb
Expand Up @@ -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
1 change: 1 addition & 0 deletions test/selenium_support_test.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/setup_test.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/suite_renderer_test.rb
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions test/test_helper.rb
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 0 additions & 6 deletions test_data/html.html

This file was deleted.

0 comments on commit dbb235f

Please sign in to comment.