capybara-page-object 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.travis.yml +5 -0
  2. data/Gemfile +8 -9
  3. data/Gemfile.lock +27 -17
  4. data/README.markdown +32 -12
  5. data/Rakefile +0 -7
  6. data/VERSION +1 -1
  7. data/capybara-page-object.gemspec +41 -34
  8. data/lib/capybara-page-object.rb +12 -11
  9. data/lib/capybara-page-object/collections.rb +4 -0
  10. data/lib/capybara-page-object/component.rb +5 -0
  11. data/lib/{delegators.rb → capybara-page-object/delegators.rb} +0 -0
  12. data/lib/capybara-page-object/element.rb +6 -0
  13. data/lib/capybara-page-object/elements.rb +15 -0
  14. data/lib/capybara-page-object/elements/anchor.rb +6 -0
  15. data/lib/{element → capybara-page-object/elements}/form.rb +8 -16
  16. data/lib/capybara-page-object/elements/form_field.rb +10 -0
  17. data/lib/capybara-page-object/elements/head.rb +7 -0
  18. data/lib/capybara-page-object/elements/image.rb +7 -0
  19. data/lib/{element → capybara-page-object/elements}/input.rb +5 -2
  20. data/lib/{element → capybara-page-object/elements}/list.rb +1 -1
  21. data/lib/{element → capybara-page-object/elements}/list_item.rb +1 -1
  22. data/lib/capybara-page-object/elements/meta.rb +6 -0
  23. data/lib/{element → capybara-page-object/elements}/select.rb +0 -0
  24. data/lib/{element → capybara-page-object/elements}/table.rb +1 -1
  25. data/lib/capybara-page-object/elements/table_header.rb +4 -0
  26. data/lib/{element → capybara-page-object/elements}/table_row.rb +1 -1
  27. data/lib/{element → capybara-page-object/elements}/text_based_input.rb +0 -0
  28. data/lib/{element → capybara-page-object/elements}/textarea.rb +1 -3
  29. data/lib/capybara-page-object/extensions/capybara.rb +7 -0
  30. data/lib/capybara-page-object/extensions/enumerable.rb +10 -0
  31. data/lib/{html5_data.rb → capybara-page-object/html5_data.rb} +0 -0
  32. data/lib/{key_value.rb → capybara-page-object/key_value.rb} +0 -0
  33. data/lib/{node.rb → capybara-page-object/node.rb} +14 -10
  34. data/lib/capybara-page-object/page.rb +77 -0
  35. data/spec/common_spec.rb +6 -6
  36. data/spec/element/anchor_spec.rb +8 -3
  37. data/spec/element/form_field_spec.rb +7 -1
  38. data/spec/element/form_spec.rb +27 -17
  39. data/spec/helper.rb +13 -0
  40. data/spec/node_spec.rb +9 -0
  41. data/spec/page_spec.rb +90 -30
  42. metadata +58 -43
  43. data/lib/collections.rb +0 -17
  44. data/lib/element.rb +0 -14
  45. data/lib/element/TODO.md +0 -11
  46. data/lib/element/anchor.rb +0 -7
  47. data/lib/element/form_field.rb +0 -15
  48. data/lib/element/head.rb +0 -15
  49. data/lib/element/image.rb +0 -15
  50. data/lib/element/meta.rb +0 -11
  51. data/lib/element/table_header.rb +0 -4
  52. data/lib/page.rb +0 -40
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ script: SKIP_COVERAGE=1 rake
data/Gemfile CHANGED
@@ -1,17 +1,16 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
1
+ source :rubygems
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
3
  group :development do
9
- gem "bundler", "~> 1.0.0"
10
- gem "jeweler", "~> 1.6.4"
11
- gem "rcov", ">= 0"
4
+ gem "bundler", "~> 1.1.0"
5
+ gem "jeweler", "~> 1.8.3"
6
+ gem 'simplecov', :require => false
12
7
  gem "rspec"
13
8
  gem 'rake', '~> 0.9.2.2'
14
9
  gem "rdoc", '~> 3.12'
15
10
  end
16
11
 
12
+ group :test do
13
+ end
14
+
15
+ gem "activesupport", '~> 3.0' # for OrderedHash
17
16
  gem "capybara"
data/Gemfile.lock CHANGED
@@ -1,6 +1,8 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ activesupport (3.0.0)
5
+ addressable (2.2.7)
4
6
  capybara (1.1.2)
5
7
  mime-types (>= 1.16)
6
8
  nokogiri (>= 1.3.3)
@@ -13,35 +15,42 @@ GEM
13
15
  diff-lcs (1.1.3)
14
16
  ffi (1.0.11)
15
17
  git (1.2.5)
16
- jeweler (1.6.4)
18
+ jeweler (1.8.3)
17
19
  bundler (~> 1.0)
18
20
  git (>= 1.2.5)
19
21
  rake
22
+ rdoc
20
23
  json (1.6.6)
21
- mime-types (1.17.2)
22
- multi_json (1.1.0)
24
+ libwebsocket (0.1.3)
25
+ addressable
26
+ mime-types (1.18)
27
+ multi_json (1.3.2)
23
28
  nokogiri (1.5.2)
24
29
  rack (1.4.1)
25
30
  rack-test (0.6.1)
26
31
  rack (>= 1.0)
27
32
  rake (0.9.2.2)
28
- rcov (0.9.11)
29
33
  rdoc (3.12)
30
34
  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)
39
- rubyzip (0.9.6.1)
40
- selenium-webdriver (2.20.0)
35
+ rspec (2.9.0)
36
+ rspec-core (~> 2.9.0)
37
+ rspec-expectations (~> 2.9.0)
38
+ rspec-mocks (~> 2.9.0)
39
+ rspec-core (2.9.0)
40
+ rspec-expectations (2.9.1)
41
+ diff-lcs (~> 1.1.3)
42
+ rspec-mocks (2.9.0)
43
+ rubyzip (0.9.7)
44
+ selenium-webdriver (2.21.2)
41
45
  childprocess (>= 0.2.5)
42
46
  ffi (~> 1.0)
47
+ libwebsocket (~> 0.1.3)
43
48
  multi_json (~> 1.0)
44
49
  rubyzip
50
+ simplecov (0.6.1)
51
+ multi_json (~> 1.0)
52
+ simplecov-html (~> 0.5.3)
53
+ simplecov-html (0.5.3)
45
54
  xpath (0.1.4)
46
55
  nokogiri (~> 1.3)
47
56
 
@@ -49,10 +58,11 @@ PLATFORMS
49
58
  ruby
50
59
 
51
60
  DEPENDENCIES
52
- bundler (~> 1.0.0)
61
+ activesupport (~> 3.0)
62
+ bundler (~> 1.1.0)
53
63
  capybara
54
- jeweler (~> 1.6.4)
64
+ jeweler (~> 1.8.3)
55
65
  rake (~> 0.9.2.2)
56
- rcov
57
66
  rdoc (~> 3.12)
58
67
  rspec
68
+ simplecov
data/README.markdown CHANGED
@@ -1,8 +1,8 @@
1
- [![Build Status](https://secure.travis-ci.org/andyw8/capybara-page-object.png)](http://travis-ci.org/andyw8/capybara-page-object)
1
+ [![Build Status](https://secure.travis-ci.org/andyw8/capybara-page-object.png)](http://travis-ci.org/andyw8/capybara-page-object) [![Dependency Status](https://gemnasium.com/andyw8/capybara-page-object.png)](https://gemnasium.com/andyw8/capybara-page-object)
2
2
 
3
3
  # capybara-page-object #
4
4
 
5
- Page Objects for Capybara
5
+ [Page Objects](http://code.google.com/p/selenium/wiki/PageObjects) for Capybara
6
6
 
7
7
  ## Installation ##
8
8
 
@@ -30,10 +30,7 @@ features/step_definitions/product_steps.rb
30
30
 
31
31
  ```ruby
32
32
  Given /^the products:$/ do |table|
33
- @products = []
34
- table.raw.flatten.each do |p|
35
- @products << Product.create!(:title => p)
36
- end
33
+ @products = table.raw.flatten.map { |p| Product.create!(:title => p) }
37
34
  end
38
35
 
39
36
  When /^I visit the store$/ do
@@ -41,28 +38,51 @@ When /^I visit the store$/ do
41
38
  end
42
39
 
43
40
  Then /^those products should be listed$/ do
44
- @page.product_titles.should == @products.collect{ |p| p.title }
41
+ @page.product_titles.should == @products.map{ |p| p.title }
45
42
  end
46
43
  ```
47
44
 
48
- features/support/pages/products/index.rb
45
+ features/pages/products/index.rb
49
46
 
50
47
  ```ruby
51
48
  module Pages
52
49
  module Products
53
50
  class Index < CapybaraPageObject::Page
54
- def path
55
- '/products'
56
- end
51
+
52
+ path 'products'
53
+
54
+ component :navigation { Components::Navigation.new find('#nav') }
55
+ component :product_list { Components::ProductList.new find('#products') }
57
56
 
58
57
  def product_titles
59
- all('.products .title').collect(&:text)
58
+ product_list.titles
60
59
  end
61
60
  end
62
61
  end
63
62
  end
63
+
64
+ module Compnents
65
+ class ProductList < CapybaraPageObject::Component
66
+ def titles
67
+ source.all('.title').collect(&:text)
68
+ end
69
+ end
70
+ end
64
71
  ```
65
72
 
73
+ ## Usage ##
74
+
75
+ Create a class to represent a page, component or element, and include the appropriate module:
76
+
77
+ * CapybaraPageObject::Page to represent a whole page
78
+ * CapybaraPageObject::Component to represent part of a page (e.g. a sidebar)
79
+ * CapybaraPageObject::Element to represent a single element (e.g. a <footer> tag)
80
+
81
+ ## Best Practices ##
82
+
83
+ * Avoid CSS or XPath selectors in your step definitions - do this within the page/component/element objects
84
+ * Avoid assertions in the page models themselves - do this in the step definitions
85
+
66
86
  ## Demo Project ##
67
87
 
68
88
  [Depot](https://github.com/andyw8/depot)
data/Rakefile CHANGED
@@ -47,13 +47,6 @@ desc "Run specs"
47
47
  RSpec::Core::RakeTask.new do |t|
48
48
  end
49
49
 
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']
55
- end
56
-
57
50
  task :default => :spec
58
51
 
59
52
  require 'rdoc/task'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{capybara-page-object}
8
- s.version = "0.5.0"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Andy Waite}]
12
- s.date = %q{2012-04-08}
12
+ s.date = %q{2012-04-22}
13
13
  s.description = %q{Page Objects for Capybara}
14
14
  s.email = %q{andy@andywaite.com}
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
+ ".travis.yml",
21
22
  "Gemfile",
22
23
  "Gemfile.lock",
23
24
  "LICENSE.txt",
@@ -26,29 +27,32 @@ Gem::Specification.new do |s|
26
27
  "VERSION",
27
28
  "capybara-page-object.gemspec",
28
29
  "lib/capybara-page-object.rb",
29
- "lib/collections.rb",
30
- "lib/delegators.rb",
31
- "lib/element.rb",
32
- "lib/element/TODO.md",
33
- "lib/element/anchor.rb",
34
- "lib/element/form.rb",
35
- "lib/element/form_field.rb",
36
- "lib/element/head.rb",
37
- "lib/element/image.rb",
38
- "lib/element/input.rb",
39
- "lib/element/list.rb",
40
- "lib/element/list_item.rb",
41
- "lib/element/meta.rb",
42
- "lib/element/select.rb",
43
- "lib/element/table.rb",
44
- "lib/element/table_header.rb",
45
- "lib/element/table_row.rb",
46
- "lib/element/text_based_input.rb",
47
- "lib/element/textarea.rb",
48
- "lib/html5_data.rb",
49
- "lib/key_value.rb",
50
- "lib/node.rb",
51
- "lib/page.rb",
30
+ "lib/capybara-page-object/collections.rb",
31
+ "lib/capybara-page-object/component.rb",
32
+ "lib/capybara-page-object/delegators.rb",
33
+ "lib/capybara-page-object/element.rb",
34
+ "lib/capybara-page-object/elements.rb",
35
+ "lib/capybara-page-object/elements/anchor.rb",
36
+ "lib/capybara-page-object/elements/form.rb",
37
+ "lib/capybara-page-object/elements/form_field.rb",
38
+ "lib/capybara-page-object/elements/head.rb",
39
+ "lib/capybara-page-object/elements/image.rb",
40
+ "lib/capybara-page-object/elements/input.rb",
41
+ "lib/capybara-page-object/elements/list.rb",
42
+ "lib/capybara-page-object/elements/list_item.rb",
43
+ "lib/capybara-page-object/elements/meta.rb",
44
+ "lib/capybara-page-object/elements/select.rb",
45
+ "lib/capybara-page-object/elements/table.rb",
46
+ "lib/capybara-page-object/elements/table_header.rb",
47
+ "lib/capybara-page-object/elements/table_row.rb",
48
+ "lib/capybara-page-object/elements/text_based_input.rb",
49
+ "lib/capybara-page-object/elements/textarea.rb",
50
+ "lib/capybara-page-object/extensions/capybara.rb",
51
+ "lib/capybara-page-object/extensions/enumerable.rb",
52
+ "lib/capybara-page-object/html5_data.rb",
53
+ "lib/capybara-page-object/key_value.rb",
54
+ "lib/capybara-page-object/node.rb",
55
+ "lib/capybara-page-object/page.rb",
52
56
  "spec/common_spec.rb",
53
57
  "spec/element/anchor_spec.rb",
54
58
  "spec/element/base_spec.rb",
@@ -79,27 +83,30 @@ Gem::Specification.new do |s|
79
83
  s.specification_version = 3
80
84
 
81
85
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
86
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0"])
82
87
  s.add_runtime_dependency(%q<capybara>, [">= 0"])
83
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
84
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
85
- s.add_development_dependency(%q<rcov>, [">= 0"])
88
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.0"])
89
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
90
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
86
91
  s.add_development_dependency(%q<rspec>, [">= 0"])
87
92
  s.add_development_dependency(%q<rake>, ["~> 0.9.2.2"])
88
93
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
89
94
  else
95
+ s.add_dependency(%q<activesupport>, ["~> 3.0"])
90
96
  s.add_dependency(%q<capybara>, [">= 0"])
91
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
92
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
93
- s.add_dependency(%q<rcov>, [">= 0"])
97
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
98
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
99
+ s.add_dependency(%q<simplecov>, [">= 0"])
94
100
  s.add_dependency(%q<rspec>, [">= 0"])
95
101
  s.add_dependency(%q<rake>, ["~> 0.9.2.2"])
96
102
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
97
103
  end
98
104
  else
105
+ s.add_dependency(%q<activesupport>, ["~> 3.0"])
99
106
  s.add_dependency(%q<capybara>, [">= 0"])
100
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
101
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
102
- s.add_dependency(%q<rcov>, [">= 0"])
107
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
108
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
109
+ s.add_dependency(%q<simplecov>, [">= 0"])
103
110
  s.add_dependency(%q<rspec>, [">= 0"])
104
111
  s.add_dependency(%q<rake>, ["~> 0.9.2.2"])
105
112
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
@@ -1,13 +1,14 @@
1
1
  require 'capybara'
2
- require 'node'
3
- require 'element'
4
- require 'html5_data'
5
- require 'page'
2
+ require 'capybara-page-object/extensions/enumerable'
3
+ require 'active_support/ordered_hash'
6
4
 
7
- module Capybara
8
- module Node
9
- class Simple
10
- include CapybaraPageObject::HTML5Data
11
- end
12
- end
13
- end
5
+ require 'capybara-page-object/key_value'
6
+ require 'capybara-page-object/delegators'
7
+ require 'capybara-page-object/html5_data'
8
+
9
+ require 'capybara-page-object/node'
10
+ require 'capybara-page-object/element'
11
+ require 'capybara-page-object/elements'
12
+ require 'capybara-page-object/page'
13
+ require 'capybara-page-object/component'
14
+ require 'capybara-page-object/extensions/capybara'
@@ -0,0 +1,4 @@
1
+ module CapybaraPageObject
2
+ module Collections
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ module CapybaraPageObject
2
+ class Component < CapybaraPageObject::Element
3
+ include CapybaraPageObject::Collections
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module CapybaraPageObject
2
+ class Element < CapybaraPageObject::Node
3
+ include CapybaraPageObject::Collections
4
+ include CapybaraPageObject::HTML5Data
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ require 'capybara-page-object/elements/text_based_input'
2
+ require 'capybara-page-object/elements/anchor'
3
+ require 'capybara-page-object/elements/form'
4
+ require 'capybara-page-object/elements/image'
5
+ require 'capybara-page-object/elements/form_field'
6
+ require 'capybara-page-object/elements/head'
7
+ require 'capybara-page-object/elements/input'
8
+ require 'capybara-page-object/elements/list'
9
+ require 'capybara-page-object/elements/list_item'
10
+ require 'capybara-page-object/elements/meta'
11
+ require 'capybara-page-object/elements/select'
12
+ require 'capybara-page-object/elements/table'
13
+ require 'capybara-page-object/elements/table_row'
14
+ require 'capybara-page-object/elements/table_header'
15
+ require 'capybara-page-object/elements/textarea'
@@ -0,0 +1,6 @@
1
+ module CapybaraPageObject
2
+ class Anchor < CapybaraPageObject::Element
3
+ field(:link) { source[:href] }
4
+ field(:uri) { URI link }
5
+ end
6
+ end
@@ -1,7 +1,10 @@
1
+ require 'active_support/ordered_hash'
2
+
1
3
  module CapybaraPageObject
2
- class Form < CapybaraPageObject::Node
4
+
5
+ class Form < CapybaraPageObject::Element
3
6
  def fields
4
- r = {}
7
+ r = ActiveSupport::OrderedHash.new
5
8
  r.merge! inputs
6
9
  r.merge! selects
7
10
  r.merge! textareas
@@ -20,19 +23,8 @@ module CapybaraPageObject
20
23
  r
21
24
  end
22
25
 
23
- def respond_to?(sym)
24
- fields.has_key?(sym.to_s) || super(sym)
25
- end
26
-
27
- def method_missing(sym, *args, &block)
28
- return fields[sym.to_s] if fields.has_key?(sym.to_s)
29
- super(sym, *args, &block)
30
- end
31
-
32
- private
33
-
34
26
  def inputs
35
- all('input').each_with_object do |input_tag, hash|
27
+ all('input').each_with_object(ActiveSupport::OrderedHash.new) do |input_tag, hash|
36
28
  input = Input.new(input_tag)
37
29
  next if input.button?
38
30
  if input.checkable?
@@ -44,14 +36,14 @@ module CapybaraPageObject
44
36
  end
45
37
 
46
38
  def textareas
47
- all('textarea').inject({}) do |result, element|
39
+ all('textarea').inject(ActiveSupport::OrderedHash.new) do |result, element|
48
40
  textarea = Textarea.new(element)
49
41
  result.merge textarea.key => textarea.value
50
42
  end
51
43
  end
52
44
 
53
45
  def selects
54
- all('select').inject({}) do |result, element|
46
+ all('select').inject(ActiveSupport::OrderedHash.new) do |result, element|
55
47
  select = Select.new(element)
56
48
  result.merge select.key => select.value
57
49
  end