tooth 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/tooth.rb +76 -0
  2. metadata +95 -0
data/lib/tooth.rb ADDED
@@ -0,0 +1,76 @@
1
+ module PageObject
2
+ def within scope_locator, &block
3
+ within_scope_klass = Class.new
4
+ within_scope_klass.extend PageObject
5
+ within_scope_klass.instance_variable_set :@page_element, page_element
6
+ within_scope_klass.element_with_finders = -> { element_with_finders.find(scope_locator) }
7
+ within_scope_klass.class_eval &block
8
+ end
9
+
10
+ def link name, locator
11
+ page_element[name] = ->(*args){ element_with_finders.find_link(locator_string(locator, args)) }
12
+ end
13
+
14
+ def field name, locator
15
+ page_element[name] = ->(*args){ element_with_finders.find_field(locator_string(locator, args)) }
16
+ end
17
+
18
+ def button name, locator
19
+ page_element[name] = ->(*args){ element_with_finders.find_button(locator_string(locator, args)) }
20
+ end
21
+
22
+ def element name, locator, options = {}
23
+ page_element[name] = ->(*args){
24
+ element_with_finders.find(locator_string(locator, args), options)
25
+ }
26
+ end
27
+
28
+ def component name, component_class, locator, options = {}
29
+ page_element[name] = ->(*args){
30
+ component_element = find(locator_string(locator, args), options)
31
+ component_class.tap do |cmp|
32
+ cmp.element_with_finders = component_element
33
+ end
34
+ }
35
+ end
36
+
37
+ # convenience methods
38
+ def shows? &block
39
+ instance_eval &block
40
+ end
41
+ alias :scenario :shows?
42
+
43
+ def not_shows? &block
44
+ instance_eval &block
45
+ rescue Capybara::ElementNotFound
46
+ else
47
+ raise 'Element is shown'
48
+ end
49
+ protected
50
+ # currently this is not thread safe solution, because we do not create instance of component, but reuse component class.
51
+ # here we trade usability of the framework for the thread safeness. Need to think about this issue and better solutions.
52
+ attr_writer :element_with_finders
53
+
54
+ private
55
+ def locator_string(locator, args)
56
+ locator.kind_of?(Proc) ? locator.call(*args) : locator
57
+ end
58
+
59
+ def page_element; @page_element ||= {} end
60
+
61
+ def element_with_finders
62
+ if @element_with_finders
63
+ @element_with_finders.kind_of?(Proc) ? @element_with_finders.call : @element_with_finders
64
+ else
65
+ Capybara.current_session
66
+ end
67
+ end
68
+
69
+ def method_missing(meth, *args, &block)
70
+ if( element_finder = page_element[meth.to_sym])
71
+ element_finder.call(*args)
72
+ else
73
+ element_with_finders.send(meth, *args, &block)
74
+ end
75
+ end
76
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tooth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aliaksei Kliuchnikau
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capybara
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sinatra
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Simple page objects for Capybara. All tooth-generated methods return
63
+ Capybara Elements so that you can use these familiar objects for your needs.
64
+ email: aliaksei.kliuchnikau@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/tooth.rb
70
+ homepage: https://github.com/kliuchnikau/tooth
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.23
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Simple page objects for Capybara
94
+ test_files: []
95
+ has_rdoc: