testable 0.3.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +37 -25
  3. data/.hound.yml +31 -12
  4. data/.rubocop.yml +4 -0
  5. data/.travis.yml +7 -0
  6. data/CODE_OF_CONDUCT.md +1 -1
  7. data/Gemfile +3 -1
  8. data/{LICENSE.txt → LICENSE.md} +2 -2
  9. data/README.md +36 -17
  10. data/Rakefile +52 -11
  11. data/bin/console +2 -2
  12. data/bin/setup +0 -0
  13. data/examples/testable-capybara-context.rb +64 -0
  14. data/examples/testable-capybara-rspec.rb +70 -0
  15. data/examples/testable-capybara.rb +46 -0
  16. data/examples/testable-info.rb +65 -0
  17. data/examples/testable-watir-context.rb +67 -0
  18. data/examples/testable-watir-datasetter.rb +52 -0
  19. data/examples/testable-watir-events.rb +44 -0
  20. data/examples/testable-watir-ready.rb +34 -0
  21. data/examples/testable-watir-test.rb +80 -0
  22. data/examples/testable-watir.rb +118 -0
  23. data/lib/testable.rb +142 -10
  24. data/lib/testable/attribute.rb +38 -0
  25. data/lib/testable/capybara/dsl.rb +82 -0
  26. data/lib/testable/capybara/node.rb +30 -0
  27. data/lib/testable/capybara/page.rb +29 -0
  28. data/lib/testable/context.rb +73 -0
  29. data/lib/testable/deprecator.rb +40 -0
  30. data/lib/testable/element.rb +162 -31
  31. data/lib/testable/errors.rb +6 -2
  32. data/lib/testable/extensions/core_ruby.rb +13 -0
  33. data/lib/testable/extensions/data_setter.rb +144 -0
  34. data/lib/testable/extensions/dom_observer.js +58 -4
  35. data/lib/testable/extensions/dom_observer.rb +73 -0
  36. data/lib/testable/locator.rb +63 -0
  37. data/lib/testable/logger.rb +16 -0
  38. data/lib/testable/page.rb +216 -0
  39. data/lib/testable/ready.rb +49 -7
  40. data/lib/testable/situation.rb +9 -28
  41. data/lib/testable/version.rb +7 -6
  42. data/testable.gemspec +19 -9
  43. metadata +90 -23
  44. data/circle.yml +0 -3
  45. data/lib/testable/data_setter.rb +0 -51
  46. data/lib/testable/dom_update.rb +0 -19
  47. data/lib/testable/factory.rb +0 -27
  48. data/lib/testable/interface.rb +0 -114
@@ -20,13 +20,6 @@ module Testable
20
20
  raise Testable::Errors::NoUrlForDefinition
21
21
  end
22
22
 
23
- def url_match_is_empty
24
- puts "PROBLEM: url_matches attribute empty.\n" \
25
- "The url_matches attribute is empty on the definition " \
26
- "'#{retrieve_class(caller)}'.\n\n"
27
- raise Testable::Errors::NoUrlMatchForDefinition
28
- end
29
-
30
23
  def no_url_match_is_possible
31
24
  puts "PROBLEM: No url_is or url_matches attribute.\n" \
32
25
  "You called a '#{retrieve_method(caller)}' action but the " \
@@ -35,6 +28,13 @@ module Testable
35
28
  raise Testable::Errors::NoUrlMatchPossible
36
29
  end
37
30
 
31
+ def url_match_is_empty
32
+ puts "PROBLEM: url_matches attribute empty.\n" \
33
+ "The url_matches attribute is empty on the definition " \
34
+ "'#{retrieve_class(caller)}'.\n\n"
35
+ raise Testable::Errors::NoUrlMatchForDefinition
36
+ end
37
+
38
38
  def title_is_empty
39
39
  puts "PROBLEM: title_is attribute empty.\n" \
40
40
  "The title_is attribute is empty on the definition " \
@@ -49,13 +49,6 @@ module Testable
49
49
  raise Testable::Errors::NoTitleForDefinition
50
50
  end
51
51
 
52
- def no_locator(definition, identifier)
53
- puts "PROBLEM: No locator provided.\n" \
54
- "You are using '#{identifier}' on '#{definition}'. " \
55
- "But there is no locator provided with it.\n\n"
56
- raise Testable::Errors::NoLocatorForDefinition
57
- end
58
-
59
52
  def not_ready_validation(message)
60
53
  puts "PROBLEM: A ready validation error was encountered.\n" \
61
54
  "A ready validation failed to validate. The ready check was " \
@@ -65,24 +58,12 @@ module Testable
65
58
  raise Testable::Errors::PageNotValidatedError, message
66
59
  end
67
60
 
68
- def no_ready_check_possible
69
- puts "PROBLEM: A when ready call has no action.\n" \
70
- "You called a when_ready on a definition but did not provide " \
71
- "any action for it. Add a block with logic that should be " \
72
- "executed if the ready check passes.\n\n"
73
- raise Testable::Errors::NoBlockForWhenReady
74
- end
75
-
76
- def retrieve_class(caller)
77
- caller[1][/`.*'/][8..-3]
78
- end
79
-
80
61
  def retrieve_method(caller)
81
62
  caller[0][/`.*'/][1..-2]
82
63
  end
83
64
 
84
- def empty_locator(locator, values)
85
- locator[0].nil? && values.empty? && !values[0].is_a?(Hash)
65
+ def retrieve_class(caller)
66
+ caller[1][/`.*'/][8..-3]
86
67
  end
87
68
  end
88
69
  end
@@ -1,24 +1,25 @@
1
1
  module Testable
2
2
  module_function
3
3
 
4
- VERSION = "0.3.0".freeze
4
+ VERSION = "0.8.0".freeze
5
5
 
6
6
  def version
7
7
  """
8
8
  Testable v#{Testable::VERSION}
9
9
  watir: #{gem_version('watir')}
10
10
  selenium-webdriver: #{gem_version('selenium-webdriver')}
11
+ capybara: #{gem_version('capybara')}
11
12
  """
12
13
  end
13
14
 
14
- def dependencies
15
- Gem.loaded_specs.values.map { |spec| "#{spec.name} #{spec.version}\n" }
16
- .uniq.sort.join(",").split(",")
17
- end
18
-
19
15
  def gem_version(name)
20
16
  Gem.loaded_specs[name].version
21
17
  rescue NoMethodError
22
18
  puts "No gem loaded for #{name}."
23
19
  end
20
+
21
+ def dependencies
22
+ Gem.loaded_specs.values.map { |spec| "#{spec.name} #{spec.version}\n" }
23
+ .uniq.sort.join(",").split(",")
24
+ end
24
25
  end
@@ -1,7 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'testable/version'
3
+ require "testable/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "testable"
@@ -9,25 +8,36 @@ Gem::Specification.new do |spec|
9
8
  spec.authors = ["Jeff Nyman"]
10
9
  spec.email = ["jeffnyman@gmail.com"]
11
10
 
12
- spec.summary = %q{Provides a semantic DSL to construct fluent interfaces for test execution logic.}
11
+ spec.summary = %q{Web and API Automation, using Capybara and Watir}
13
12
  spec.description = %q{Provides a semantic DSL to construct fluent interfaces for test execution logic.}
14
13
  spec.homepage = "https://github.com/jeffnyman/testable"
15
14
  spec.license = "MIT"
16
15
 
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
- f.match(%r{^(test|spec|features)/})
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/jeffnyman/testable"
18
+ spec.metadata["changelog_uri"] = "https://github.com/jeffnyman/testable/blob/master/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
24
  end
20
25
  spec.bindir = "exe"
21
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
27
  spec.require_paths = ["lib"]
23
28
 
24
- spec.add_development_dependency "bundler", "~> 1.13"
25
- spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.required_ruby_version = ">= 2.3"
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", ">= 12.3.3"
26
33
  spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency "simplecov"
27
35
  spec.add_development_dependency "rubocop"
28
36
  spec.add_development_dependency "pry"
29
37
 
30
- spec.add_runtime_dependency "watir", "~> 6.0"
38
+ spec.add_runtime_dependency "watir", ["~> 6.16"]
39
+ spec.add_runtime_dependency "capybara", [">= 2", "< 4"]
40
+ spec.add_runtime_dependency "webdrivers", ["~> 4.0"]
31
41
 
32
42
  spec.post_install_message = %{
33
43
  (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Nyman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-03 00:00:00.000000000 Z
11
+ date: 2020-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rubocop
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +100,48 @@ dependencies:
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '6.0'
103
+ version: '6.16'
90
104
  type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '6.0'
110
+ version: '6.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: capybara
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '2'
118
+ - - "<"
119
+ - !ruby/object:Gem::Version
120
+ version: '4'
121
+ type: :runtime
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '2'
128
+ - - "<"
129
+ - !ruby/object:Gem::Version
130
+ version: '4'
131
+ - !ruby/object:Gem::Dependency
132
+ name: webdrivers
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '4.0'
138
+ type: :runtime
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '4.0'
97
145
  description: Provides a semantic DSL to construct fluent interfaces for test execution
98
146
  logic.
99
147
  email:
@@ -106,22 +154,40 @@ files:
106
154
  - ".hound.yml"
107
155
  - ".rspec"
108
156
  - ".rubocop.yml"
157
+ - ".travis.yml"
109
158
  - CODE_OF_CONDUCT.md
110
159
  - Gemfile
111
- - LICENSE.txt
160
+ - LICENSE.md
112
161
  - README.md
113
162
  - Rakefile
114
163
  - bin/console
115
164
  - bin/setup
116
- - circle.yml
165
+ - examples/testable-capybara-context.rb
166
+ - examples/testable-capybara-rspec.rb
167
+ - examples/testable-capybara.rb
168
+ - examples/testable-info.rb
169
+ - examples/testable-watir-context.rb
170
+ - examples/testable-watir-datasetter.rb
171
+ - examples/testable-watir-events.rb
172
+ - examples/testable-watir-ready.rb
173
+ - examples/testable-watir-test.rb
174
+ - examples/testable-watir.rb
117
175
  - lib/testable.rb
118
- - lib/testable/data_setter.rb
119
- - lib/testable/dom_update.rb
176
+ - lib/testable/attribute.rb
177
+ - lib/testable/capybara/dsl.rb
178
+ - lib/testable/capybara/node.rb
179
+ - lib/testable/capybara/page.rb
180
+ - lib/testable/context.rb
181
+ - lib/testable/deprecator.rb
120
182
  - lib/testable/element.rb
121
183
  - lib/testable/errors.rb
184
+ - lib/testable/extensions/core_ruby.rb
185
+ - lib/testable/extensions/data_setter.rb
122
186
  - lib/testable/extensions/dom_observer.js
123
- - lib/testable/factory.rb
124
- - lib/testable/interface.rb
187
+ - lib/testable/extensions/dom_observer.rb
188
+ - lib/testable/locator.rb
189
+ - lib/testable/logger.rb
190
+ - lib/testable/page.rb
125
191
  - lib/testable/ready.rb
126
192
  - lib/testable/situation.rb
127
193
  - lib/testable/version.rb
@@ -129,9 +195,12 @@ files:
129
195
  homepage: https://github.com/jeffnyman/testable
130
196
  licenses:
131
197
  - MIT
132
- metadata: {}
198
+ metadata:
199
+ homepage_uri: https://github.com/jeffnyman/testable
200
+ source_code_uri: https://github.com/jeffnyman/testable
201
+ changelog_uri: https://github.com/jeffnyman/testable/blob/master/CHANGELOG.md
133
202
  post_install_message: "\n(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)\n
134
- \ Testable 0.3.0 has been installed.\n(::) (::) (::) (::) (::) (::) (::) (::) (::)
203
+ \ Testable 0.8.0 has been installed.\n(::) (::) (::) (::) (::) (::) (::) (::) (::)
135
204
  (::) (::) (::)\n "
136
205
  rdoc_options: []
137
206
  require_paths:
@@ -140,17 +209,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
209
  requirements:
141
210
  - - ">="
142
211
  - !ruby/object:Gem::Version
143
- version: '0'
212
+ version: '2.3'
144
213
  required_rubygems_version: !ruby/object:Gem::Requirement
145
214
  requirements:
146
215
  - - ">="
147
216
  - !ruby/object:Gem::Version
148
217
  version: '0'
149
218
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.5.1
219
+ rubygems_version: 3.1.2
152
220
  signing_key:
153
221
  specification_version: 4
154
- summary: Provides a semantic DSL to construct fluent interfaces for test execution
155
- logic.
222
+ summary: Web and API Automation, using Capybara and Watir
156
223
  test_files: []
data/circle.yml DELETED
@@ -1,3 +0,0 @@
1
- checkout:
2
- post:
3
- - mkdir -p spec/reports
@@ -1,51 +0,0 @@
1
- class Object
2
- def chain(method_chain, arg = nil)
3
- return self if method_chain.empty?
4
- method_chain.split('.').inject(self) do |o, m|
5
- if arg.nil?
6
- o.send(m.intern)
7
- else
8
- o.send(m.intern, arg)
9
- end
10
- end
11
- end
12
- end
13
-
14
- module Testable
15
- module DataSetter
16
- def using(data)
17
- data.each do |key, value|
18
- use_data_with(key, value) if object_enabled_for(key)
19
- end
20
- end
21
-
22
- alias using_data using
23
- alias use_data using
24
- alias using_values using
25
- alias use_values using
26
-
27
- private
28
-
29
- def use_data_with(key, value)
30
- element = send(key.to_s)
31
- set_and_select(key, element, value)
32
- check_and_uncheck(key, element, value)
33
- end
34
-
35
- def set_and_select(key, element, value)
36
- chain("#{key}.set", value) if element.class == Watir::TextField
37
- chain("#{key}.set") if element.class == Watir::Radio
38
- chain("#{key}.select", value) if element.class == Watir::Select
39
- end
40
-
41
- def check_and_uncheck(key, element, value)
42
- return chain("#{key}.check") if element.class == Watir::CheckBox && value
43
- chain("#{key}.uncheck") if element.class == Watir::CheckBox
44
- end
45
-
46
- def object_enabled_for(key)
47
- web_element = send(key.to_s)
48
- web_element.enabled? && web_element.visible?
49
- end
50
- end
51
- end
@@ -1,19 +0,0 @@
1
- module Watir
2
- class Element
3
- OBSERVER_FILE = "/extensions/dom_observer.js".freeze
4
- DOM_OBSERVER = File.read("#{File.dirname(__FILE__)}#{OBSERVER_FILE}").freeze
5
-
6
- def dom_updated?(delay: 1.1)
7
- driver.manage.timeouts.script_timeout = delay + 1
8
- driver.execute_async_script(DOM_OBSERVER, wd, delay)
9
- ensure
10
- driver.manage.timeouts.script_timeout = 1
11
- end
12
-
13
- alias dom_updated dom_updated?
14
- alias dom_is_updated dom_updated?
15
- alias dom_is_changed dom_updated?
16
- alias when_dom_updated dom_updated?
17
- alias when_dom_changed dom_updated?
18
- end
19
- end
@@ -1,27 +0,0 @@
1
- module Testable
2
- module Factory
3
- # Creates a definition context for actions. If an existing context
4
- # exists, that context will be re-used.
5
- def on(definition, visit = false, &block)
6
- unless @context.is_a?(definition)
7
- @context = definition.new(@browser) if @browser
8
- @context = definition.new unless @browser
9
- @context.visit if visit
10
- end
11
-
12
- yield @context if block
13
- @context
14
- end
15
-
16
- alias on_page on
17
- alias while_on on
18
-
19
- # Creates a definition context for actions and establishes the
20
- # context for execution.
21
- def on_view(definition, &block)
22
- on(definition, true, &block)
23
- end
24
-
25
- alias on_visit on_view
26
- end
27
- end