capybara-page-object 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Gemfile +3 -1
  2. data/Gemfile.lock +15 -2
  3. data/Rakefile +27 -13
  4. data/VERSION +1 -1
  5. data/capybara-page-object.gemspec +55 -27
  6. data/lib/capybara-page-object.rb +6 -8
  7. data/lib/collections.rb +11 -0
  8. data/lib/element.rb +11 -0
  9. data/lib/element/anchor.rb +11 -0
  10. data/lib/element/form.rb +64 -0
  11. data/lib/element/form_field.rb +20 -0
  12. data/lib/element/image.rb +20 -0
  13. data/lib/element/input.rb +28 -0
  14. data/lib/element/list.rb +21 -0
  15. data/lib/element/listitem.rb +7 -0
  16. data/lib/element/meta.rb +16 -0
  17. data/lib/element/select.rb +16 -0
  18. data/lib/{table.rb → element/table.rb} +1 -3
  19. data/lib/element/textarea.rb +16 -0
  20. data/lib/{extractors → extractor}/common.rb +3 -11
  21. data/lib/{extractors → extractor}/page_level.rb +3 -13
  22. data/lib/html5_data.rb +14 -0
  23. data/lib/key_value.rb +11 -0
  24. data/lib/navigation.rb +16 -0
  25. data/lib/node.rb +76 -0
  26. data/spec/common_spec.rb +46 -0
  27. data/spec/element/anchor_spec.rb +15 -0
  28. data/spec/element/base_spec.rb +19 -0
  29. data/spec/element/form_field_spec.rb +28 -0
  30. data/spec/element/form_spec.rb +69 -0
  31. data/spec/element/image_spec.rb +30 -0
  32. data/spec/element/input_spec.rb +49 -0
  33. data/spec/element/list_spec.rb +47 -0
  34. data/spec/element/listitem_spec.rb +25 -0
  35. data/spec/element/meta_spec.rb +23 -0
  36. data/spec/element/select_spec.rb +36 -0
  37. data/spec/element/table_spec.rb +30 -0
  38. data/spec/element/textarea_spec.rb +19 -0
  39. data/{test/page.html → spec/fixtures/node.html} +0 -0
  40. data/{test → spec}/helper.rb +2 -11
  41. data/spec/node_spec.rb +45 -0
  42. metadata +120 -109
  43. data/lib/base.rb +0 -29
  44. data/lib/image.rb +0 -13
  45. data/lib/page.rb +0 -15
  46. data/test/image.html +0 -2
  47. data/test/table.html +0 -10
  48. data/test/test_image.rb +0 -20
  49. data/test/test_page.rb +0 -59
  50. data/test/test_table.rb +0 -20
data/Gemfile CHANGED
@@ -6,10 +6,12 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
- gem "shoulda", ">= 0"
10
9
  gem "bundler", "~> 1.0.0"
11
10
  gem "jeweler", "~> 1.6.4"
12
11
  gem "rcov", ">= 0"
12
+ gem "rspec"
13
+ gem 'rake', '~> 0.9.2.2'
14
+ gem "rdoc", '~> 3.12'
13
15
  end
14
16
 
15
17
  gem "capybara"
data/Gemfile.lock CHANGED
@@ -10,12 +10,14 @@ GEM
10
10
  xpath (~> 0.1.4)
11
11
  childprocess (0.3.1)
12
12
  ffi (~> 1.0.6)
13
+ diff-lcs (1.1.3)
13
14
  ffi (1.0.11)
14
15
  git (1.2.5)
15
16
  jeweler (1.6.4)
16
17
  bundler (~> 1.0)
17
18
  git (>= 1.2.5)
18
19
  rake
20
+ json (1.6.6)
19
21
  mime-types (1.17.2)
20
22
  multi_json (1.1.0)
21
23
  nokogiri (1.5.2)
@@ -24,13 +26,22 @@ GEM
24
26
  rack (>= 1.0)
25
27
  rake (0.9.2.2)
26
28
  rcov (0.9.11)
29
+ rdoc (3.12)
30
+ json (~> 1.4)
31
+ rspec (2.8.0)
32
+ rspec-core (~> 2.8.0)
33
+ rspec-expectations (~> 2.8.0)
34
+ rspec-mocks (~> 2.8.0)
35
+ rspec-core (2.8.0)
36
+ rspec-expectations (2.8.0)
37
+ diff-lcs (~> 1.1.2)
38
+ rspec-mocks (2.8.0)
27
39
  rubyzip (0.9.6.1)
28
40
  selenium-webdriver (2.20.0)
29
41
  childprocess (>= 0.2.5)
30
42
  ffi (~> 1.0)
31
43
  multi_json (~> 1.0)
32
44
  rubyzip
33
- shoulda (2.11.3)
34
45
  xpath (0.1.4)
35
46
  nokogiri (~> 1.3)
36
47
 
@@ -41,5 +52,7 @@ DEPENDENCIES
41
52
  bundler (~> 1.0.0)
42
53
  capybara
43
54
  jeweler (~> 1.6.4)
55
+ rake (~> 0.9.2.2)
44
56
  rcov
45
- shoulda
57
+ rdoc (~> 3.12)
58
+ rspec
data/Rakefile CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'bundler'
5
+ require 'rspec'
6
+ require 'rspec/core/rake_task'
7
+
5
8
  begin
6
9
  Bundler.setup(:default, :development)
7
10
  rescue Bundler::BundlerError => e
@@ -25,24 +28,35 @@ Jeweler::Tasks.new do |gem|
25
28
  end
26
29
  Jeweler::RubygemsDotOrgTasks.new
27
30
 
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
31
+ #require 'rake/testtask'
32
+ # Rake::TestTask.new(:test) do |test|
33
+ # test.libs << 'lib' << 'test'
34
+ # test.pattern = 'test/**/test_*.rb'
35
+ # test.verbose = true
36
+ # end
37
+ #
38
+ # require 'rcov/rcovtask'
39
+ # Rcov::RcovTask.new do |test|
40
+ # test.libs << 'test'
41
+ # test.pattern = 'test/**/test_*.rb'
42
+ # test.verbose = true
43
+ # test.rcov_opts << '--exclude "gems/*"'
44
+ # end
45
+
46
+ desc "Run specs"
47
+ RSpec::Core::RakeTask.new do |t|
33
48
  end
34
49
 
35
- require 'rcov/rcovtask'
36
- Rcov::RcovTask.new do |test|
37
- test.libs << 'test'
38
- test.pattern = 'test/**/test_*.rb'
39
- test.verbose = true
40
- test.rcov_opts << '--exclude "gems/*"'
50
+ desc "Generate code coverage"
51
+ RSpec::Core::RakeTask.new(:coverage) do |t|
52
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
53
+ t.rcov = true
54
+ t.rcov_opts = ['--exclude', 'spec']
41
55
  end
42
56
 
43
- task :default => :test
57
+ task :default => :spec
44
58
 
45
- require 'rake/rdoctask'
59
+ require 'rdoc/task'
46
60
  Rake::RDocTask.new do |rdoc|
47
61
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
62
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "capybara-page-object"
8
- s.version = "0.2.1"
7
+ s.name = %q{capybara-page-object}
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Andy Waite"]
12
- s.date = "2012-03-26"
13
- s.description = "Page Objects for Capybara"
14
- s.email = "andy@andywaite.com"
11
+ s.authors = [%q{Andy Waite}]
12
+ s.date = %q{2012-04-01}
13
+ s.description = %q{Page Objects for Capybara}
14
+ s.email = %q{andy@andywaite.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.rdoc"
@@ -25,49 +25,77 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "capybara-page-object.gemspec",
28
- "lib/base.rb",
29
28
  "lib/capybara-page-object.rb",
30
- "lib/extractors/common.rb",
31
- "lib/extractors/page_level.rb",
32
- "lib/image.rb",
33
- "lib/page.rb",
34
- "lib/table.rb",
35
- "test/helper.rb",
36
- "test/image.html",
37
- "test/page.html",
38
- "test/table.html",
39
- "test/test_image.rb",
40
- "test/test_page.rb",
41
- "test/test_table.rb"
29
+ "lib/collections.rb",
30
+ "lib/element.rb",
31
+ "lib/element/anchor.rb",
32
+ "lib/element/form.rb",
33
+ "lib/element/form_field.rb",
34
+ "lib/element/image.rb",
35
+ "lib/element/input.rb",
36
+ "lib/element/list.rb",
37
+ "lib/element/listitem.rb",
38
+ "lib/element/meta.rb",
39
+ "lib/element/select.rb",
40
+ "lib/element/table.rb",
41
+ "lib/element/textarea.rb",
42
+ "lib/extractor/common.rb",
43
+ "lib/extractor/page_level.rb",
44
+ "lib/html5_data.rb",
45
+ "lib/key_value.rb",
46
+ "lib/navigation.rb",
47
+ "lib/node.rb",
48
+ "spec/common_spec.rb",
49
+ "spec/element/anchor_spec.rb",
50
+ "spec/element/base_spec.rb",
51
+ "spec/element/form_field_spec.rb",
52
+ "spec/element/form_spec.rb",
53
+ "spec/element/image_spec.rb",
54
+ "spec/element/input_spec.rb",
55
+ "spec/element/list_spec.rb",
56
+ "spec/element/listitem_spec.rb",
57
+ "spec/element/meta_spec.rb",
58
+ "spec/element/select_spec.rb",
59
+ "spec/element/table_spec.rb",
60
+ "spec/element/textarea_spec.rb",
61
+ "spec/fixtures/node.html",
62
+ "spec/helper.rb",
63
+ "spec/node_spec.rb"
42
64
  ]
43
- s.homepage = "http://github.com/andyw8/capybara-page-object"
44
- s.licenses = ["MIT"]
45
- s.require_paths = ["lib"]
46
- s.rubygems_version = "1.8.10"
47
- s.summary = "Page Objects for Capybara"
65
+ s.homepage = %q{http://github.com/andyw8/capybara-page-object}
66
+ s.licenses = [%q{MIT}]
67
+ s.require_paths = [%q{lib}]
68
+ s.rubygems_version = %q{1.8.6}
69
+ s.summary = %q{Page Objects for Capybara}
48
70
 
49
71
  if s.respond_to? :specification_version then
50
72
  s.specification_version = 3
51
73
 
52
74
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
75
  s.add_runtime_dependency(%q<capybara>, [">= 0"])
54
- s.add_development_dependency(%q<shoulda>, [">= 0"])
55
76
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
56
77
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
57
78
  s.add_development_dependency(%q<rcov>, [">= 0"])
79
+ s.add_development_dependency(%q<rspec>, [">= 0"])
80
+ s.add_development_dependency(%q<rake>, ["~> 0.9.2.2"])
81
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
58
82
  else
59
83
  s.add_dependency(%q<capybara>, [">= 0"])
60
- s.add_dependency(%q<shoulda>, [">= 0"])
61
84
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
85
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
63
86
  s.add_dependency(%q<rcov>, [">= 0"])
87
+ s.add_dependency(%q<rspec>, [">= 0"])
88
+ s.add_dependency(%q<rake>, ["~> 0.9.2.2"])
89
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
64
90
  end
65
91
  else
66
92
  s.add_dependency(%q<capybara>, [">= 0"])
67
- s.add_dependency(%q<shoulda>, [">= 0"])
68
93
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
69
94
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
70
95
  s.add_dependency(%q<rcov>, [">= 0"])
96
+ s.add_dependency(%q<rspec>, [">= 0"])
97
+ s.add_dependency(%q<rake>, ["~> 0.9.2.2"])
98
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
71
99
  end
72
100
  end
73
101
 
@@ -1,15 +1,13 @@
1
- require 'rubygems'
2
1
  require 'capybara'
3
- require File.dirname(__FILE__) + '/extractors/common'
4
- require File.dirname(__FILE__) + '/extractors/page_level'
5
- require File.dirname(__FILE__) + '/page'
6
- require File.dirname(__FILE__) + '/table'
7
- require File.dirname(__FILE__) + '/image'
2
+ require File.dirname(__FILE__) + '/node'
3
+ require File.dirname(__FILE__) + '/element'
4
+ require File.dirname(__FILE__) + '/html5_data'
8
5
 
9
6
  module Capybara
10
7
  module Node
11
- module Finders
12
- include Extractors::PageLevel
8
+ class Simple
9
+ include Extractor::PageLevel
10
+ include CapybaraPageObject::HTML5Data
13
11
  end
14
12
  end
15
13
  end
@@ -0,0 +1,11 @@
1
+ module CapybaraPageObject
2
+ module Collections
3
+ def tables(attr={})
4
+ extract('table', attr, CapybaraPageObject::Table)
5
+ end
6
+
7
+ def forms(attr={})
8
+ extract('form', attr)
9
+ end
10
+ end
11
+ end
data/lib/element.rb ADDED
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/element/anchor'
2
+ require File.dirname(__FILE__) + '/element/form'
3
+ require File.dirname(__FILE__) + '/element/image'
4
+ require File.dirname(__FILE__) + '/element/form_field'
5
+ require File.dirname(__FILE__) + '/element/input'
6
+ require File.dirname(__FILE__) + '/element/list'
7
+ require File.dirname(__FILE__) + '/element/listitem' # TODO make this two words
8
+ require File.dirname(__FILE__) + '/element/meta'
9
+ require File.dirname(__FILE__) + '/element/select'
10
+ require File.dirname(__FILE__) + '/element/table'
11
+ require File.dirname(__FILE__) + '/element/textarea'
@@ -0,0 +1,11 @@
1
+ module CapybaraPageObject
2
+ class Anchor < CapybaraPageObject::Node
3
+ def element_names
4
+ ['a']
5
+ end
6
+
7
+ def link
8
+ URI(root_node[:href])
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,64 @@
1
+ module CapybaraPageObject
2
+ class Form < CapybaraPageObject::Node
3
+
4
+ def fields
5
+ r = {}
6
+ r.merge! inputs
7
+ r.merge! selects
8
+ r.merge! textareas
9
+ end
10
+
11
+ def buttons
12
+ r = []
13
+ all('input').each do |element|
14
+ input = Input.new(element)
15
+ next unless input.button?
16
+ r << element
17
+ end
18
+ all('button').each do |button|
19
+ r << button
20
+ end
21
+ r
22
+ end
23
+
24
+ def respond_to?(sym)
25
+ fields.has_key?(sym.to_s) || super(sym)
26
+ end
27
+
28
+ def method_missing(sym, *args, &block)
29
+ return fields[sym.to_s] if fields.has_key?(sym.to_s)
30
+ super(sym, *args, &block)
31
+ end
32
+
33
+ private
34
+
35
+ def inputs
36
+ r = {}
37
+ all('input').each do |input_tag|
38
+ input = Input.new(input_tag)
39
+ next if input.button?
40
+ if input.checkable?
41
+ r[input.key] = !! input.checked?
42
+ else
43
+ r[input.key] = input_tag.value
44
+ end
45
+ end
46
+ r
47
+ end
48
+
49
+ def textareas
50
+ all('textarea').inject({}) do |result, element|
51
+ textarea = Textarea.new(element)
52
+ result.merge textarea.key => textarea.value
53
+ end
54
+ end
55
+
56
+ def selects
57
+ all('select').inject({}) do |result, element|
58
+ select = Select.new(element)
59
+ # TODO why is select.value not working here?
60
+ result.merge select.key => element.value
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,20 @@
1
+ module CapybaraPageObject
2
+ class FormField < CapybaraPageObject::Node
3
+
4
+ def key
5
+ root_node[:name]
6
+ end
7
+
8
+ def element_names
9
+ ['input', 'select', 'textarea']
10
+ end
11
+
12
+ def blank?
13
+ '' == value
14
+ end
15
+
16
+ def value
17
+ root_node.value
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module CapybaraPageObject
2
+ class Image < CapybaraPageObject::Node
3
+
4
+ def element_names
5
+ ['img']
6
+ end
7
+
8
+ def alt
9
+ root_node[:alt].strip
10
+ end
11
+
12
+ def key
13
+ alt
14
+ end
15
+
16
+ def value
17
+ URI(root_node[:src])
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ module CapybaraPageObject
2
+ class Input < CapybaraPageObject::Node
3
+
4
+ BUTTON_TYPES = ['submit', 'reset', 'button']
5
+ CHECKABLE_TYPES = ['radio', 'checkbox']
6
+
7
+ def element_names
8
+ ['input']
9
+ end
10
+
11
+ def key
12
+ root_node[:name]
13
+ end
14
+
15
+ def untyped?
16
+ root_node[:type].nil?
17
+ end
18
+
19
+ def button?
20
+ BUTTON_TYPES.include?(root_node[:type])
21
+ end
22
+
23
+ def checkable?
24
+ type = root_node[:type]
25
+ type && CHECKABLE_TYPES.include?(type)
26
+ end
27
+ end
28
+ end