screengem 0.6.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21b69c903afb974665c2aa6e4a7bec85d358f77e6098073bc7aa13d1894f9f89
4
- data.tar.gz: 0a7dfb096d615137892bbcc736157fdd05f804868450bda7768ecb523ed34f4a
3
+ metadata.gz: f0f99a511e85ed2b6f1232ca2ffa53e296ab97be13bdaecadce83657b33e6915
4
+ data.tar.gz: 16e8d91f9c89f33a82a1d2e1b6c8917e016c132df1f101c6953d50c4ab1f7f89
5
5
  SHA512:
6
- metadata.gz: 371bac28fea725a28e8010a772836491991ab49aefe1f542d41b9e8eb5cac5f2cd758044174fe44af906f10eb95e8490974e5f2b9a11637f478f6c8846bed9a5
7
- data.tar.gz: 60777c62b2ac2e2801a8b9738c01e0418b21b3fbfb07a9e3f5de203887a0025b63f373ca7d1b5bc83b7812cbe81ca0d4d23e49cc3ed9ad460586e94341e45237
6
+ metadata.gz: 072bf89ce61351a3fcab0bc150cfe7319e10d60c67bffd8a056637f0a62c884cb5eae84a324dcfbabdc65755bc881c20fc192f2567364fab858cde0ae33d5c88
7
+ data.tar.gz: a34105be1cb51ef91a904f650befc987d49cdf3150e170264811b0106f3355f2f79749ba461d5d7a6c76d2d7cf88c1c17505e447ab2f25b5e1b7b9ec1300a1a5
data/.rubocop.yml CHANGED
@@ -39,18 +39,21 @@ Style/Documentation:
39
39
  Style/EmptyMethod:
40
40
  Enabled: false
41
41
 
42
- Style/FrozenStringLiteralComment:
42
+ Style/ExpandPathArguments:
43
43
  Enabled: false
44
44
 
45
- Style/MutableConstant:
45
+ Style/FrozenStringLiteralComment:
46
46
  Enabled: false
47
47
 
48
- Style/ExpandPathArguments:
48
+ Style/MutableConstant:
49
49
  Enabled: false
50
50
 
51
51
  Style/StringLiterals:
52
52
  EnforcedStyle: double_quotes
53
53
 
54
+ Style/SymbolArray:
55
+ Enabled: false
56
+
54
57
  Style/RescueModifier:
55
58
  Enabled: false
56
59
 
data/CHANGELOG.md CHANGED
@@ -2,12 +2,30 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.7.1 (2019-04-20)
6
+
7
+ ### Bug fixes
8
+
9
+ * Fixed failure to generate screen element methods unless no arg constructor.
10
+
11
+ ## 0.7.0 (2019-04-18)
12
+
13
+ ### New Features
14
+
15
+ * Introduce the `visit_path` method for subclasses of ScreenElement (no need to call `visit`).
16
+
17
+ ### Bug fixes
18
+
19
+ * Load the Rails environment to run the `screengem` command that creates dampening configurations
20
+
5
21
  ## 0.6.0 (2019-04-11)
6
22
 
7
23
  ### New Features
8
24
 
9
25
  * Whenever an actor recalls a value perform a `reload` on the value. Avoid the `reload` by passing `false` to the `reload:` argument.
10
26
 
27
+ ## 0.5.0 (2019-03-28)
28
+
11
29
  ### New Features
12
30
 
13
31
  * [RSpec Expectations](https://github.com/rspec/rspec-expectations) are available in all primitives: actions, questions, and tasks.
@@ -0,0 +1,42 @@
1
+ module Screengem
2
+ #
3
+ # Knows how to decorate public screen element methods with a visit invocation around any public method.
4
+ #
5
+ # This behaviour is turned on for any screen element instance that overrides the visit_path method.
6
+ #
7
+ class AutomaticVisit
8
+ attr_reader :screen_element
9
+
10
+ def initialize(screen_element)
11
+ @screen_element = screen_element
12
+ end
13
+
14
+ def method_missing(method, *args)
15
+ if screen_element.respond_to?(method)
16
+ forward_with_auto_visit(method, args)
17
+ else
18
+ super
19
+ end
20
+ end
21
+
22
+ def respond_to_missing?(method, *)
23
+ screen_element.respond_to?(method)
24
+ end
25
+
26
+ private
27
+
28
+ def forward_with_auto_visit(method, args)
29
+ screen_element.visit if auto_visit?(method)
30
+
31
+ screen_element.send(method, *args)
32
+ end
33
+
34
+ def auto_visit?(method)
35
+ methods_to_decorate.include?(method)
36
+ end
37
+
38
+ def methods_to_decorate
39
+ @methods_to_decorate ||= screen_element.public_methods(false) - [:visit, :visit_path]
40
+ end
41
+ end
42
+ end
data/lib/screengem/cli.rb CHANGED
@@ -8,6 +8,9 @@ module Screengem
8
8
  option :quiet, default: false, desc: "Suppress command output"
9
9
  desc "generate", "Create the sample dampening configuration"
10
10
  def generate
11
+ # Require Rails to be loaded so that we can successfully require questions and tasks.
12
+ require "./config/environment"
13
+
11
14
  root = options[:root]
12
15
 
13
16
  # Require all questions and tasks for inclusion in the sample configuration.
@@ -2,7 +2,22 @@ module Screengem
2
2
  #
3
3
  # Base class for all screen elements.
4
4
  #
5
+ # Calling visit does nothing when currently navigated to the target.
6
+ #
5
7
  class ScreenElement
6
8
  include Capybara::DSL
9
+
10
+ def visit(visit_uri = visit_path)
11
+ return if visit_uri == page.current_path
12
+
13
+ page.visit(visit_uri)
14
+ end
15
+
16
+ #
17
+ # Subclasses override the visit_path method to participate in auto visit.
18
+ # See Screengem::AutomaticVisit.
19
+ #
20
+ def visit_path
21
+ end
7
22
  end
8
23
  end
@@ -2,10 +2,17 @@ module Screengem
2
2
  #
3
3
  # Singleton that gives the ability to get references to screen elements.
4
4
  #
5
- # On initialization generate a factory method for each screen element we can find. Example:
5
+ # On initialization generate a factory method for each screen element. If the screen element
6
+ # defines a visit_path method then we wrap the screen element to support auto visit.
7
+ #
8
+ # Examples:
6
9
  #
7
10
  # def login_page
8
- # Pages::LoginPage.new
11
+ # ScreenElements::LoginPage.new
12
+ # end
13
+ #
14
+ # def login_page
15
+ # Screengem::AutomaticVisit.new(ScreenElements::LoginPage.new)
9
16
  # end
10
17
  #
11
18
  class ScreenElements
@@ -14,22 +21,41 @@ module Screengem
14
21
  def initialize
15
22
  generated_method_names = []
16
23
 
17
- Screengem::ScreenElement.descendants.each do |screen_element|
18
- class_name = screen_element.name
24
+ Screengem::ScreenElement.descendants.each do |screen_element_class|
25
+ class_name = screen_element_class.name
26
+
27
+ # Skip any anonymous classes. We can't do anything with them. Probably they're from testing.
28
+ next if class_name.blank?
29
+
19
30
  method_name = class_name.demodulize.underscore
20
31
 
32
+ # Create some safety by detecting and failing fast for duplicate creation method names
21
33
  if generated_method_names.include?(method_name)
22
34
  raise "Name collision: two screen elements resolve to '#{method_name}'."
23
35
  end
24
36
 
25
37
  generated_method_names << method_name
26
38
 
27
- class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
28
- def #{method_name}(*args)
29
- #{class_name}.new(*args)
30
- end
31
- RUBY
39
+ if auto_visit?(screen_element_class)
40
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
41
+ def #{method_name}(*args)
42
+ Screengem::AutomaticVisit.new(#{class_name}.new(*args))
43
+ end
44
+ RUBY
45
+ else
46
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
47
+ def #{method_name}(*args)
48
+ #{class_name}.new(*args)
49
+ end
50
+ RUBY
51
+ end
32
52
  end
33
53
  end
54
+
55
+ private
56
+
57
+ def auto_visit?(screen_element)
58
+ screen_element.instance_methods(false).include?(:visit_path)
59
+ end
34
60
  end
35
61
  end
@@ -1,3 +1,3 @@
1
1
  module Screengem
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.1"
3
3
  end
data/lib/screengem.rb CHANGED
@@ -7,6 +7,7 @@ require "active_support/core_ext"
7
7
  require "capybara/dsl"
8
8
  require "rspec/expectations"
9
9
 
10
+ require "screengem/automatic_visit"
10
11
  require "screengem/incorrect_answer"
11
12
  require "screengem/screen_element"
12
13
  require "screengem/screengem_error"
data/screengem.gemspec CHANGED
@@ -38,4 +38,5 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency "rspec", "~> 3.8"
39
39
  spec.add_development_dependency "rubocop", "~> 0.65"
40
40
  spec.add_development_dependency "rubocop-rspec", "~> 1.32"
41
+ spec.add_development_dependency "simplecov", "~> 0.16"
41
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: screengem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alistair McKinnell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-12 00:00:00.000000000 Z
11
+ date: 2019-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -148,6 +148,20 @@ dependencies:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
150
  version: '1.32'
151
+ - !ruby/object:Gem::Dependency
152
+ name: simplecov
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '0.16'
158
+ type: :development
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: '0.16'
151
165
  description:
152
166
  email:
153
167
  - alistairm@nulogy.com
@@ -175,6 +189,7 @@ files:
175
189
  - lib/screengem.rb
176
190
  - lib/screengem/action.rb
177
191
  - lib/screengem/actor.rb
192
+ - lib/screengem/automatic_visit.rb
178
193
  - lib/screengem/browser_action.rb
179
194
  - lib/screengem/cli.rb
180
195
  - lib/screengem/concerns/actionable.rb