seleniumrc_fc_webrat_mapper 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Niall Mullally
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = Seleniumrc_fu Webrat Mapper
2
+
3
+ For simplifying migrating of Seleniumrc_fu Rails plugin tests to Webrat tests without an extensive rewrite.
4
+
5
+ Extends Webrat::Methods and Webrat::Matchers modules to map Seleniumrc_fu methods to their Webrat equivalent.
6
+
7
+ Not a complete set of mappings, but can be easily extended.
8
+
9
+ == Installation
10
+
11
+ Require 'seleniumrc_fu_webrat_mapper' after 'webrat'.
12
+
13
+ require 'webrat'
14
+ require 'seleniumrc_fu_webrat_mapper'
15
+
16
+
17
+ Copyright (c) 2009 Niall Mullally, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the webrat_seleniumrc_fu_mappings plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the webrat_seleniumrc_fu_mappings plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'Vendor::Plugins::WebratSeleniumrcFuMappings'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ begin
26
+ require 'jeweler'
27
+ Jeweler::Tasks.new do |gemspec|
28
+ gemspec.name = "seleniumrc_fc_webrat_mapper"
29
+ gemspec.summary = "For simplifying migrating of Seleniumrc_fu Rails plugin tests to Webrat tests"
30
+ gemspec.email = "niall@4l.ie"
31
+ gemspec.homepage = "http://github.com/Sidane/seleniumrc_fu_webrat_mapper"
32
+ gemspec.authors = ["Niall Mullally"]
33
+ end
34
+ rescue LoadError
35
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
36
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ puts IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
@@ -0,0 +1,11 @@
1
+ class String
2
+
3
+ def xpath?
4
+ self =~ /^(\/)+/
5
+ end
6
+
7
+ def clean_selector
8
+ self.gsub(/(id=|link=|css=)*/, '')
9
+ end
10
+
11
+ end
@@ -0,0 +1,34 @@
1
+ module Webrat
2
+ module Matchers
3
+
4
+ include SharedMatchers
5
+
6
+ alias :assert_text_present :assert_contain
7
+ alias :assert_text_not_present :assert_not_contain
8
+
9
+ def assert_text(selector, content, &block)
10
+ if selector.xpath? # see core_extensions/string.rb
11
+ assert_have_xpath(selector, :content => content.to_s, &block)
12
+ else
13
+ assert_have_selector(selector.clean_selector, :content => content.to_s, &block)
14
+ end
15
+ end
16
+
17
+ def assert_element_present(selector, attributes = {}, &block)
18
+ if selector.xpath?
19
+ assert_have_xpath(selector, attributes, &block)
20
+ else
21
+ assert_have_selector(selector.clean_selector, attributes, &block)
22
+ end
23
+ end
24
+
25
+ def assert_element_not_present(selector, attributes = {}, &block)
26
+ if selector.xpath?
27
+ assert_have_no_xpath(selector, attributes, &block)
28
+ else
29
+ assert_have_no_selector(selector.clean_selector, attributes, &block)
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,24 @@
1
+ module Webrat
2
+ module Methods
3
+
4
+ alias :open :visit
5
+ alias :refresh :reload
6
+
7
+ def click_and_wait(text_or_title_or_id, options = {})
8
+ click_link(text_or_title_or_id.clean_selector, options)
9
+ end
10
+
11
+ alias :click :click_and_wait
12
+
13
+ def type(field_locator, value)
14
+ fill_in(field_locator.clean_selector, :with => value)
15
+ end
16
+
17
+ alias :webrat_select :select
18
+
19
+ def select(field, option_text)
20
+ webrat_select(option_text, :from => field)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,49 @@
1
+ module Webrat
2
+ module Selenium
3
+ module Matchers
4
+
5
+ include SharedMatchers
6
+
7
+ def assert_text_present(content)
8
+ assert_contain(content)
9
+ end
10
+
11
+ def assert_text_not_present(content)
12
+ assert_not_contain(content)
13
+ end
14
+
15
+ def assert_text(selector, content)
16
+ if selector.xpath? # see core_extensions/string.rb
17
+ assert_have_xpath(selector) && assert_contain(content)
18
+ else
19
+ assert_have_selector(selector.clean_selector) && assert_contain(content)
20
+ end
21
+ end
22
+
23
+ def assert_element_present(selector)
24
+ if selector.xpath?
25
+ assert_have_xpath(selector)
26
+ else
27
+ assert_have_selector(selector.clean_selector)
28
+ end
29
+ end
30
+
31
+ def assert_element_not_present(selector)
32
+ if selector.xpath?
33
+ assert_have_no_xpath(selector)
34
+ else
35
+ assert_have_no_selector(selector.clean_selector)
36
+ end
37
+ end
38
+
39
+ def assert_visible(selector)
40
+ assert selenium.is_visible(selector)
41
+ end
42
+
43
+ def assert_not_visible(selector)
44
+ assert !selenium.is_visible(selector)
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ module SharedMatchers
2
+
3
+ def assert_location_ends_in(pattern)
4
+ response.headers["Location"] =~ /pattern$/
5
+ end
6
+
7
+ end
@@ -0,0 +1,6 @@
1
+ require 'seleniumrc_fu_webrat_mapper/core_extensions/string'
2
+ require 'seleniumrc_fu_webrat_mapper/shared_matchers'
3
+ require 'seleniumrc_fu_webrat_mapper/selenium/matchers'
4
+ require 'seleniumrc_fu_webrat_mapper/matchers'
5
+ require 'seleniumrc_fu_webrat_mapper/methods'
6
+
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class MatchersTest < Test::Unit::TestCase
4
+
5
+ include Webrat::Matchers
6
+
7
+ def setup
8
+ @body = <<-HTML
9
+ <div id='main'>
10
+ <div class='inner'>hello, world!</div>
11
+ </div>
12
+ HTML
13
+ expects(:response_body).at_most_once.returns(@body)
14
+ end
15
+
16
+ def test_assert_text_present
17
+ assert_text_present('hello, world!')
18
+ end
19
+
20
+ def test_assert_text_not_present
21
+ assert_text_not_present('goodbye, world!')
22
+ end
23
+
24
+ def test_assert_text_with_css_selector
25
+ assert_text('div.inner', 'hello, world!')
26
+ end
27
+
28
+ def test_assert_text_with_xpath_selector
29
+ assert_text('//div[@class="inner"]', 'hello, world!')
30
+ end
31
+
32
+ def test_assert_element_present_with_css_selector
33
+ assert_element_present('css=div.inner')
34
+ end
35
+
36
+ def test_assert_element_present_xpath_selector
37
+ assert_element_present('//div[@class="inner"]')
38
+ end
39
+
40
+ def test_assert_element_present_with_invalid_selector
41
+ assert_raise Test::Unit::AssertionFailedError do
42
+ assert_element_present('//div[@class="outer"]')
43
+ end
44
+ end
45
+
46
+ def test_assert_element_present_with_attributes
47
+ assert_element_present('//div[@class="inner"]', :content => "hello, world!")
48
+ end
49
+
50
+ def test_assert_element_present_with_invalid_attributes
51
+ assert_raise Test::Unit::AssertionFailedError do
52
+ assert_element_present('//div[@class="inner"]', :content => "goodbye, world!")
53
+ end
54
+ end
55
+
56
+ def test_assert_element_not_present_with_css_selector
57
+ assert_element_not_present('div.outer')
58
+ end
59
+
60
+ def test_assert_element_not_present_xpath_selector
61
+ assert_element_not_present('//div[@class="outer"]')
62
+ end
63
+
64
+ def test_assert_element_not_present_with_valid_selector
65
+ assert_raise Test::Unit::AssertionFailedError do
66
+ assert_element_not_present('//div[@class="inner"]')
67
+ end
68
+ end
69
+
70
+ def test_assert_location_ends_in
71
+ expects(:response).returns(OpenStruct.new(:headers => {"Location" => "http://www.example.com/my/url/"}))
72
+ assert_location_ends_in('my/url')
73
+ end
74
+
75
+ def test_assert_location_ends_in_failure
76
+ expects(:response).returns(OpenStruct.new(:headers => {"Location" => "http://www.example.com/my/url/"}))
77
+ assert_location_ends_in('different/url')
78
+ end
79
+
80
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class MethodsTest < Test::Unit::TestCase
4
+
5
+ include Webrat::Methods
6
+
7
+ def test_open
8
+ Webrat::Session.any_instance.expects(:visit).with("/")
9
+ open "/"
10
+ end
11
+
12
+ def test_click_and_wait
13
+ Webrat::Session.any_instance.expects(:click_link).with("My Link", {})
14
+ click_and_wait "link=My Link"
15
+ end
16
+
17
+ def test_click
18
+ Webrat::Session.any_instance.expects(:click_link).with("My Link", {})
19
+ click "id=My Link"
20
+ end
21
+
22
+ def test_refresh
23
+ Webrat::Session.any_instance.expects(:reload)
24
+ refresh
25
+ end
26
+
27
+ def test_type
28
+ Webrat::Session.any_instance.expects(:fill_in).with("my_field", :with => "Monkeys")
29
+ type "my_field", "Monkeys"
30
+ end
31
+
32
+ def test_select
33
+ Webrat::Session.any_instance.expects(:select).with("Monkeys", :from => "my_select_menu")
34
+ select "my_select_menu", "Monkeys"
35
+ end
36
+
37
+ end
@@ -0,0 +1,59 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SeleniumMatchersTest < Test::Unit::TestCase
4
+
5
+ include Webrat::Selenium::Matchers
6
+
7
+ def test_assert_text_present
8
+ stubs(:assert_contain).with('content').returns(true)
9
+ assert assert_text_present('content')
10
+ end
11
+
12
+ def test_assert_text_not_present
13
+ stubs(:assert_not_contain).with('content').returns(true)
14
+ assert assert_text_not_present('content')
15
+ end
16
+
17
+ def test_assert_text
18
+ stubs(:assert_have_selector).with('div#my_id').returns(true)
19
+ stubs(:assert_contain).with('content').returns(true)
20
+ assert assert_text('div#my_id', 'content')
21
+ end
22
+
23
+ def test_assert_text_with_xpath
24
+ stubs(:assert_have_xpath).with('//div').returns(true)
25
+ stubs(:assert_contain).with('content').returns(true)
26
+ assert assert_text('//div', 'content')
27
+ end
28
+
29
+ def test_assert_element_present
30
+ stubs(:assert_have_selector).with('div#my_id').returns(true)
31
+ assert assert_element_present('div#my_id')
32
+ end
33
+
34
+ def test_assert_element_present_with_xpath
35
+ stubs(:assert_have_xpath).with('//div').returns(true)
36
+ assert assert_element_present('//div')
37
+ end
38
+
39
+ def test_assert_element_not_present
40
+ stubs(:assert_have_no_selector).with('div#my_id').returns(true)
41
+ assert assert_element_not_present('div#my_id')
42
+ end
43
+
44
+ def test_assert_element_not_present_with_xpath
45
+ stubs(:assert_have_no_xpath).with('//div').returns(true)
46
+ assert assert_element_not_present('//div')
47
+ end
48
+
49
+ def test_assert_visible
50
+ stubs(:selenium).returns(OpenStruct.new(:is_visible => true))
51
+ assert assert_visible("div#my_id")
52
+ end
53
+
54
+ def test_assert_visible
55
+ stubs(:selenium).returns(OpenStruct.new(:is_visible => false))
56
+ assert !assert_not_visible("div#my_id")
57
+ end
58
+
59
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class StringTest < Test::Unit::TestCase
4
+
5
+ def test_valid_xpath?
6
+ assert "//div[@id='my_id']".xpath?
7
+ end
8
+
9
+ def test_invalid_xpath?
10
+ assert !"#div[@id='my_id']".xpath?
11
+ end
12
+
13
+ def test_clean_selector
14
+ assert_equal "homepage", "id=homepage".clean_selector
15
+ end
16
+
17
+ def test_clean_selector_with_no_matching_string
18
+ assert_equal "not_cleaned=homepage", "not_cleaned=homepage".clean_selector
19
+ end
20
+
21
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'mocha'
4
+ require 'webrat'
5
+
6
+ lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
7
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
8
+
9
+ require 'seleniumrc_fu_webrat_mapper'
10
+
11
+ Webrat.configure do |config|
12
+ config.mode = :rails
13
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seleniumrc_fc_webrat_mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Niall Mullally
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-14 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: niall@4l.ie
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - MIT-LICENSE
26
+ - README.rdoc
27
+ - Rakefile
28
+ - VERSION
29
+ - install.rb
30
+ - lib/seleniumrc_fu_webrat_mapper.rb
31
+ - lib/seleniumrc_fu_webrat_mapper/core_extensions/string.rb
32
+ - lib/seleniumrc_fu_webrat_mapper/matchers.rb
33
+ - lib/seleniumrc_fu_webrat_mapper/methods.rb
34
+ - lib/seleniumrc_fu_webrat_mapper/selenium/matchers.rb
35
+ - lib/seleniumrc_fu_webrat_mapper/shared_matchers.rb
36
+ - test/matchers_test.rb
37
+ - test/methods_test.rb
38
+ - test/selenium_matchers_test.rb
39
+ - test/string_test.rb
40
+ - test/test_helper.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/Sidane/seleniumrc_fu_webrat_mapper
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --charset=UTF-8
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.5
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: For simplifying migrating of Seleniumrc_fu Rails plugin tests to Webrat tests
69
+ test_files:
70
+ - test/matchers_test.rb
71
+ - test/methods_test.rb
72
+ - test/selenium_matchers_test.rb
73
+ - test/string_test.rb
74
+ - test/test_helper.rb