screengem 0.9.1 → 0.13.0

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: b6fdea9053a69b15255d54d9a1a3ae9cf34fe0973ef857dd17c12d023ba00eb4
4
- data.tar.gz: bff48e6b9db7aa91e0beaf5400002f82f797fa6246d926c769ecdcc697ab06a5
3
+ metadata.gz: ac2f7d84aaffa8c289ae50df7e43bbb0c383fd484f0189b164506f0b1a179c15
4
+ data.tar.gz: 17052ca08f46778aa1b1af991f30fa6cf299a09a900432f9f9144a3feaba53aa
5
5
  SHA512:
6
- metadata.gz: 1477cd2253855d1ddcf5d2e820c0419f5d2726b44c464507ea77557c4c73ecf5be8229921a79d44dece85883aea1a5c14a88f16ed647737516d7cfa35127af81
7
- data.tar.gz: 7609872a5856218b3717f336d2bd9c3e92e9d087598d363eb8142def96067a4e42eb39f3aebfd30bb50e6b3fa3aff96c3d3ea143c359d64eabee1e42f4d9fbc3
6
+ metadata.gz: df490d4d6ebd176d35657c5b11d9e01aeb925adb86b4f0724c2d43615c3a72976512666e7bebedb1658de2428c6d2455f53bb9e5819d53f4d5be25e57b52b5d7
7
+ data.tar.gz: eb386240b263bdcf4366513165b3e123bc0f91604dd939d1f4b43cde2e961aca8f9f0abe76381e78db10dbc4245c71e9c0162c0e1e727eda89c5b1f93ce4d6c9
data/.rubocop.yml CHANGED
@@ -1,5 +1,22 @@
1
1
  require: rubocop-rspec
2
2
 
3
+ AllCops:
4
+ TargetRubyVersion: 2.7
5
+ NewCops: enable
6
+
7
+ Lint/ConstantDefinitionInBlock:
8
+ Exclude:
9
+ - spec/**/*_spec.rb
10
+
11
+ Layout/SpaceAroundMethodCallOperator:
12
+ Enabled: false
13
+
14
+ Lint/RaiseException:
15
+ Enabled: false
16
+
17
+ Lint/StructNewOverride:
18
+ Enabled: false
19
+
3
20
  Metrics/AbcSize:
4
21
  Enabled: false
5
22
 
@@ -15,6 +32,10 @@ Metrics/MethodLength:
15
32
  Metrics/ModuleLength:
16
33
  Enabled: false
17
34
 
35
+ Naming/VariableNumber:
36
+ Enabled: true
37
+ EnforcedStyle: snake_case
38
+
18
39
  RSpec/AnyInstance:
19
40
  Enabled: false
20
41
 
@@ -24,6 +45,9 @@ RSpec/DescribedClass:
24
45
  RSpec/ExampleLength:
25
46
  Max: 20
26
47
 
48
+ RSpec/MultipleMemoizedHelpers:
49
+ Max: 8
50
+
27
51
  RSpec/MultipleExpectations:
28
52
  Max: 5
29
53
 
@@ -36,9 +60,24 @@ RSpec/MessageSpies:
36
60
  RSpec/NotToNot:
37
61
  EnforcedStyle: to_not
38
62
 
63
+ Style/ExponentialNotation:
64
+ Enabled: false
65
+
66
+ Style/HashEachMethods:
67
+ Enabled: false
68
+
69
+ Style/HashTransformKeys:
70
+ Enabled: false
71
+
72
+ Style/HashTransformValues:
73
+ Enabled: false
74
+
39
75
  Style/Documentation:
40
76
  Enabled: false
41
77
 
78
+ Style/DocumentDynamicEvalDefinition:
79
+ Enabled: false
80
+
42
81
  Style/EmptyMethod:
43
82
  Enabled: false
44
83
 
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.3
1
+ 2.7.3
data/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.13.0 (2021-06-13)
6
+
7
+ * Relax the ActiveSupport dependency
8
+ * Latest development dependencies
9
+
10
+ ## 0.12.0 (2021-01-27)
11
+
12
+ * Relax the thor dependency
13
+ * Latest development dependencies
14
+
15
+ ## 0.11.0 (2020-04-26)
16
+
17
+ ### Breaking Changes
18
+
19
+ * Questions answer negatively by throwing an exception rather than returning false
20
+
21
+ ## 0.10.1 (2020-01-11)
22
+
23
+ * Relax the thor dependency
24
+
25
+ ## 0.10.0 (2020-01-11)
26
+
27
+ * Remove action abstraction
28
+ * Latest development dependencies
29
+
5
30
  ## 0.9.1 (2019-10-22)
6
31
 
7
32
  * Relax the require_all dependency
data/README.md CHANGED
@@ -24,15 +24,14 @@ An Actor is able to remember and recall key-value pairs.
24
24
 
25
25
  A Question responds to answer.
26
26
 
27
- A Task responds to perform and may execute one or more actions.
27
+ A Task responds to perform.
28
28
 
29
29
  ![Core Domain Model](/images/ScreengemCore.png)
30
30
 
31
31
  ## Actor Memory
32
32
 
33
- Actors are able to remember and recall facts. This is the recommended way to
34
- pass state between steps. To clear all actor's memory before each scenario
35
- add a hook:
33
+ Actors are able to remember and recall facts. This is the recommended way to pass state
34
+ between steps. To clear every actor's memory before each scenario add a hook:
36
35
 
37
36
  ```
38
37
  Before do
@@ -40,6 +39,20 @@ Before do
40
39
  end
41
40
  ```
42
41
 
42
+ ## Performing Tasks
43
+
44
+ Actors are able to perform tasks. A task may be implemented by interacting with domain services,
45
+ domain models, application databases, and the application via screen elements.
46
+
47
+ Capybara is available to all screen elements and is the recommended way to interact with a browser.
48
+
49
+ ## Answering Questions
50
+
51
+ Actors are able to answer questions. A question is considered to be answered affirmatively
52
+ when no exception is thrown and negatively when an exception is thrown.
53
+
54
+ [RSpec expectations](https://github.com/rspec/rspec-expectations) are available in all questions and are the recommended way to implement a question.
55
+
43
56
  ## Dampening
44
57
 
45
58
  It sometimes makes sense to slow down the automation. This is known as dampening.
Binary file
data/lib/screengem.rb CHANGED
@@ -8,7 +8,6 @@ require "capybara/dsl"
8
8
  require "rspec/expectations"
9
9
 
10
10
  require "screengem/automatic_visit"
11
- require "screengem/incorrect_answer"
12
11
  require "screengem/rails_routes"
13
12
  require "screengem/screen_element"
14
13
  require "screengem/screengem_error"
@@ -18,15 +17,12 @@ require "screengem/primitive_key"
18
17
  require "screengem/dampen_configuration"
19
18
  require "screengem/dampen_configuration_generator"
20
19
 
21
- require "screengem/concerns/actionable"
22
20
  require "screengem/concerns/configurable"
23
21
  require "screengem/concerns/dampenable"
24
22
  require "screengem/concerns/executable"
25
23
 
26
24
  require "screengem/dsl"
27
25
 
28
- require "screengem/action"
29
- require "screengem/browser_action"
30
26
  require "screengem/question"
31
27
  require "screengem/task"
32
28
 
@@ -35,9 +31,6 @@ require "screengem/actor"
35
31
 
36
32
  require "screengem/factories/factory_creation_error"
37
33
 
38
- require "screengem/factories/action_factory"
39
- require "screengem/factories/browser_action_factory"
40
- require "screengem/factories/standard_action_factory"
41
34
  require "screengem/factories/question_factory"
42
35
  require "screengem/factories/task_factory"
43
36
 
@@ -1,14 +1,14 @@
1
1
  module Screengem
2
2
  #
3
- # Mixin that allows an actor to perform tasks, ask questions, take actions, and
4
- # to remember and recall tagged values.
3
+ # Mixin that allows an actor to perform tasks, ask questions, and to remember and
4
+ # recall tagged values.
5
5
  #
6
6
  # Return self for those methods that may be chained in the step definition DSL.
7
7
  #
8
8
  # The ability to remember and recall values is used to carry state forward from one
9
9
  # step definition to another (as the preferred alternative to instance variables).
10
10
  #
11
- # Action, question, and task instances (aka primitives) are configured with:
11
+ # Question and task instances (aka primitives) are configured with:
12
12
  # (1) a reference to the actor that is interacting with the primitive
13
13
  # (2) a reference to the screen instance that hosts accessors to the screen elements.
14
14
  #
@@ -18,11 +18,7 @@ module Screengem
18
18
  #
19
19
  def asks(*questions)
20
20
  questions.each do |question|
21
- question.configure(self, screen)
22
-
23
- next if question.answer
24
-
25
- raise incorrect_answer(question)
21
+ question.configure(self, screen).answer
26
22
  end
27
23
 
28
24
  self
@@ -33,9 +29,7 @@ module Screengem
33
29
  #
34
30
  def performs(*tasks)
35
31
  tasks.each do |task|
36
- task.configure(self, screen)
37
-
38
- task.perform
32
+ task.configure(self, screen).perform
39
33
  end
40
34
 
41
35
  self
@@ -66,25 +60,8 @@ module Screengem
66
60
  self
67
61
  end
68
62
 
69
- #
70
- # Used by an actor to take one or more actions.
71
- #
72
- # Used to implement tasks. Actions do not appear in step definitions.
73
- #
74
- def takes_action(*actions)
75
- actions.each do |action|
76
- action.configure(self, screen)
77
-
78
- action.execute
79
- end
80
- end
81
-
82
63
  private
83
64
 
84
- def incorrect_answer(question)
85
- Screengem::IncorrectAnswer.new(question)
86
- end
87
-
88
65
  def recollections
89
66
  ActorMemory.instance.recollections(self)
90
67
  end
@@ -25,12 +25,6 @@ module Screengem
25
25
  # A boolean that specifies that dampening is to be applied.
26
26
  attr_accessor :apply_dampening
27
27
 
28
- # A boolean that specifies that browser actions are created (used by the ActionFactory).
29
- attr_accessor :browser_actions
30
-
31
- # A string that namespaces action classes (used by the ActionFactory).
32
- attr_accessor :action_scope
33
-
34
28
  # A string that namespaces questions classes (used by the QuestionFactory).
35
29
  attr_accessor :question_scope
36
30
 
@@ -39,11 +33,9 @@ module Screengem
39
33
 
40
34
  def initialize
41
35
  self.apply_dampening = false
42
- self.browser_actions = false
43
36
 
44
37
  self.dampen_configuration_root = "default"
45
38
 
46
- self.action_scope = "Actions"
47
39
  self.question_scope = "Questions"
48
40
  self.task_scope = "Tasks"
49
41
  end
@@ -52,10 +44,6 @@ module Screengem
52
44
  apply_dampening
53
45
  end
54
46
 
55
- def browser_actions?
56
- browser_actions
57
- end
58
-
59
47
  def dampen_configuration_sample_filename
60
48
  "#{dampen_configuration_filename}.sample"
61
49
  end
@@ -6,7 +6,7 @@ module Screengem
6
6
  class QuestionFactory < BasicObject
7
7
  include ::Singleton
8
8
 
9
- def method_missing(question_name, *args) # rubocop:disable Style/MethodMissingSuper
9
+ def method_missing(question_name, *args)
10
10
  question_class_name = "#{question_name}_question".camelize
11
11
  question_class = "#{question_scope}::#{question_class_name}".constantize
12
12
 
@@ -6,7 +6,7 @@ module Screengem
6
6
  class TaskFactory < BasicObject
7
7
  include ::Singleton
8
8
 
9
- def method_missing(task_name, *args) # rubocop:disable Style/MethodMissingSuper
9
+ def method_missing(task_name, *args)
10
10
  task_class_name = "#{task_name}_task".camelize
11
11
  task_class = "#{task_scope}::#{task_class_name}".constantize
12
12
 
@@ -22,11 +22,10 @@ module Screengem
22
22
  generated_method_names = []
23
23
 
24
24
  Screengem::ScreenElement.descendants.each do |screen_element_class|
25
- class_name = screen_element_class.name
26
-
27
25
  # Skip any anonymous classes. We can't do anything with them. Probably they're from testing.
28
- next if class_name.blank?
26
+ next if screen_element_class.anonymous?
29
27
 
28
+ class_name = screen_element_class.name
30
29
  method_name = class_name.demodulize.underscore
31
30
 
32
31
  # Create some safety by detecting and failing fast for duplicate creation method names.
@@ -5,7 +5,6 @@ module Screengem
5
5
  class Task
6
6
  include RSpec::Matchers
7
7
 
8
- include Screengem::Actionable
9
8
  include Screengem::Configurable
10
9
  include Screengem::Dampenable
11
10
  include Screengem::Executable
@@ -1,3 +1,3 @@
1
1
  module Screengem
2
- VERSION = "0.9.1"
2
+ VERSION = "0.13.0"
3
3
  end
data/screengem.gemspec CHANGED
@@ -27,16 +27,18 @@ Gem::Specification.new do |spec|
27
27
  spec.bindir = "exe"
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
+ spec.required_ruby_version = ">= 2.7"
30
31
 
31
- spec.add_runtime_dependency "activesupport", ">= 4.2", "< 6.1"
32
+ spec.add_runtime_dependency "activesupport", ">= 5.2", "< 6.2"
32
33
  spec.add_runtime_dependency "capybara", ">= 2.18", "< 4.0"
33
- spec.add_runtime_dependency "require_all", ">= 2.0", "< 4.0"
34
- spec.add_runtime_dependency "rspec-expectations", "~> 3.8"
35
- spec.add_runtime_dependency "thor", "~> 0.20"
34
+ spec.add_runtime_dependency "require_all", ">= 3.0", "< 4.0"
35
+ spec.add_runtime_dependency "rspec-expectations", "~> 3.10"
36
+ spec.add_runtime_dependency "thor", ">= 0.20", "< 1.2"
36
37
 
37
38
  spec.add_development_dependency "rake", "~> 13.0"
38
- spec.add_development_dependency "rspec", "~> 3.8"
39
- spec.add_development_dependency "rubocop", "~> 0.75"
40
- spec.add_development_dependency "rubocop-rspec", "~> 1.36"
41
- spec.add_development_dependency "simplecov", "~> 0.17"
39
+ spec.add_development_dependency "rspec", "~> 3.9"
40
+ spec.add_development_dependency "rubocop", "~> 1.8"
41
+ spec.add_development_dependency "rubocop-performance", "~> 1.9"
42
+ spec.add_development_dependency "rubocop-rspec", "~> 2.1"
43
+ spec.add_development_dependency "simplecov", "~> 0.21"
42
44
  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.9.1
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alistair McKinnell
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-22 00:00:00.000000000 Z
11
+ date: 2021-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.1'
22
+ version: '6.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.2'
29
+ version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.1'
32
+ version: '6.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: capybara
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -56,7 +56,7 @@ dependencies:
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: '2.0'
59
+ version: '3.0'
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '4.0'
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: '2.0'
69
+ version: '3.0'
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '4.0'
@@ -76,28 +76,34 @@ dependencies:
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: '3.8'
79
+ version: '3.10'
80
80
  type: :runtime
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - "~>"
85
85
  - !ruby/object:Gem::Version
86
- version: '3.8'
86
+ version: '3.10'
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: thor
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - "~>"
91
+ - - ">="
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0.20'
94
+ - - "<"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.2'
94
97
  type: :runtime
95
98
  prerelease: false
96
99
  version_requirements: !ruby/object:Gem::Requirement
97
100
  requirements:
98
- - - "~>"
101
+ - - ">="
99
102
  - !ruby/object:Gem::Version
100
103
  version: '0.20'
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: '1.2'
101
107
  - !ruby/object:Gem::Dependency
102
108
  name: rake
103
109
  requirement: !ruby/object:Gem::Requirement
@@ -118,57 +124,71 @@ dependencies:
118
124
  requirements:
119
125
  - - "~>"
120
126
  - !ruby/object:Gem::Version
121
- version: '3.8'
127
+ version: '3.9'
122
128
  type: :development
123
129
  prerelease: false
124
130
  version_requirements: !ruby/object:Gem::Requirement
125
131
  requirements:
126
132
  - - "~>"
127
133
  - !ruby/object:Gem::Version
128
- version: '3.8'
134
+ version: '3.9'
129
135
  - !ruby/object:Gem::Dependency
130
136
  name: rubocop
131
137
  requirement: !ruby/object:Gem::Requirement
132
138
  requirements:
133
139
  - - "~>"
134
140
  - !ruby/object:Gem::Version
135
- version: '0.75'
141
+ version: '1.8'
142
+ type: :development
143
+ prerelease: false
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - "~>"
147
+ - !ruby/object:Gem::Version
148
+ version: '1.8'
149
+ - !ruby/object:Gem::Dependency
150
+ name: rubocop-performance
151
+ requirement: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - "~>"
154
+ - !ruby/object:Gem::Version
155
+ version: '1.9'
136
156
  type: :development
137
157
  prerelease: false
138
158
  version_requirements: !ruby/object:Gem::Requirement
139
159
  requirements:
140
160
  - - "~>"
141
161
  - !ruby/object:Gem::Version
142
- version: '0.75'
162
+ version: '1.9'
143
163
  - !ruby/object:Gem::Dependency
144
164
  name: rubocop-rspec
145
165
  requirement: !ruby/object:Gem::Requirement
146
166
  requirements:
147
167
  - - "~>"
148
168
  - !ruby/object:Gem::Version
149
- version: '1.36'
169
+ version: '2.1'
150
170
  type: :development
151
171
  prerelease: false
152
172
  version_requirements: !ruby/object:Gem::Requirement
153
173
  requirements:
154
174
  - - "~>"
155
175
  - !ruby/object:Gem::Version
156
- version: '1.36'
176
+ version: '2.1'
157
177
  - !ruby/object:Gem::Dependency
158
178
  name: simplecov
159
179
  requirement: !ruby/object:Gem::Requirement
160
180
  requirements:
161
181
  - - "~>"
162
182
  - !ruby/object:Gem::Version
163
- version: '0.17'
183
+ version: '0.21'
164
184
  type: :development
165
185
  prerelease: false
166
186
  version_requirements: !ruby/object:Gem::Requirement
167
187
  requirements:
168
188
  - - "~>"
169
189
  - !ruby/object:Gem::Version
170
- version: '0.17'
171
- description:
190
+ version: '0.21'
191
+ description:
172
192
  email:
173
193
  - alistairm@nulogy.com
174
194
  executables:
@@ -193,13 +213,10 @@ files:
193
213
  - exe/screengem
194
214
  - images/ScreengemCore.png
195
215
  - lib/screengem.rb
196
- - lib/screengem/action.rb
197
216
  - lib/screengem/actor.rb
198
217
  - lib/screengem/actor_memory.rb
199
218
  - lib/screengem/automatic_visit.rb
200
- - lib/screengem/browser_action.rb
201
219
  - lib/screengem/cli.rb
202
- - lib/screengem/concerns/actionable.rb
203
220
  - lib/screengem/concerns/configurable.rb
204
221
  - lib/screengem/concerns/dampenable.rb
205
222
  - lib/screengem/concerns/executable.rb
@@ -207,13 +224,9 @@ files:
207
224
  - lib/screengem/dampen_configuration.rb
208
225
  - lib/screengem/dampen_configuration_generator.rb
209
226
  - lib/screengem/dsl.rb
210
- - lib/screengem/factories/action_factory.rb
211
- - lib/screengem/factories/browser_action_factory.rb
212
227
  - lib/screengem/factories/factory_creation_error.rb
213
228
  - lib/screengem/factories/question_factory.rb
214
- - lib/screengem/factories/standard_action_factory.rb
215
229
  - lib/screengem/factories/task_factory.rb
216
- - lib/screengem/incorrect_answer.rb
217
230
  - lib/screengem/primitive_key.rb
218
231
  - lib/screengem/question.rb
219
232
  - lib/screengem/rails_routes.rb
@@ -231,7 +244,7 @@ metadata:
231
244
  changelog_uri: https://github.com/nulogy/screengem/blob/master/CHANGELOG.md
232
245
  source_code_uri: https://github.com/nulogy/screengem
233
246
  bug_tracker_uri: https://github.com/nulogy/screengem/issues
234
- post_install_message:
247
+ post_install_message:
235
248
  rdoc_options: []
236
249
  require_paths:
237
250
  - lib
@@ -239,15 +252,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
239
252
  requirements:
240
253
  - - ">="
241
254
  - !ruby/object:Gem::Version
242
- version: '0'
255
+ version: '2.7'
243
256
  required_rubygems_version: !ruby/object:Gem::Requirement
244
257
  requirements:
245
258
  - - ">="
246
259
  - !ruby/object:Gem::Version
247
260
  version: '0'
248
261
  requirements: []
249
- rubygems_version: 3.0.6
250
- signing_key:
262
+ rubygems_version: 3.1.6
263
+ signing_key:
251
264
  specification_version: 4
252
265
  summary: Ruby implementation of the Screengem Pattern.
253
266
  test_files: []
@@ -1,11 +0,0 @@
1
- module Screengem
2
- #
3
- # Base class for all actions.
4
- #
5
- class Action
6
- include RSpec::Matchers
7
-
8
- include Screengem::Configurable
9
- include Screengem::Executable
10
- end
11
- end
@@ -1,7 +0,0 @@
1
- module Screengem
2
- #
3
- # Base class for all browser actions.
4
- #
5
- class BrowserAction < Screengem::Action
6
- end
7
- end
@@ -1,29 +0,0 @@
1
- module Screengem
2
- #
3
- # Concern that adds the ability to create actions.
4
- #
5
- module Actionable
6
- extend ActiveSupport::Concern
7
-
8
- def action
9
- @action ||= action_factory
10
- end
11
-
12
- private
13
-
14
- #
15
- # Choose the specified action factory. Default to the standard action factory.
16
- #
17
- def action_factory
18
- if browser_factory?
19
- Screengem::Factories::BrowserActionFactory.instance
20
- else
21
- Screengem::Factories::StandardActionFactory.instance
22
- end
23
- end
24
-
25
- def browser_factory?
26
- Screengem.configuration.browser_actions?
27
- end
28
- end
29
- end
@@ -1,34 +0,0 @@
1
- module Screengem
2
- module Factories
3
- #
4
- # Makes actions available to tasks.
5
- #
6
- class ActionFactory < BasicObject
7
- def method_missing(action_name, *args) # rubocop:disable Style/MethodMissingSuper
8
- action_class_name = raw_action_class_name(action_name).camelize
9
- action_class = "#{action_scope}::#{action_class_name}".constantize
10
-
11
- action_class.new(*args)
12
- rescue => e
13
- ActionError.new(<<~MSG)
14
- Unable to create action: '#{action_class_name}'.
15
- Details: #{e.message}
16
- MSG
17
- end
18
-
19
- def respond_to_missing?(_action_name, *)
20
- true
21
- end
22
-
23
- class ActionError < ::Screengem::Action
24
- include FactoryCreationError
25
- end
26
-
27
- private
28
-
29
- def action_scope
30
- @action_scope ||= ::Screengem.configuration.action_scope
31
- end
32
- end
33
- end
34
- end
@@ -1,14 +0,0 @@
1
- module Screengem
2
- module Factories
3
- #
4
- # Makes browser actions available.
5
- #
6
- class BrowserActionFactory < Screengem::Factories::ActionFactory
7
- include ::Singleton
8
-
9
- def raw_action_class_name(action_name)
10
- "#{action_name}_action_browser"
11
- end
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module Screengem
2
- module Factories
3
- #
4
- # Makes standard actions available.
5
- #
6
- class StandardActionFactory < Screengem::Factories::ActionFactory
7
- include ::Singleton
8
-
9
- def raw_action_class_name(action_name)
10
- "#{action_name}_action"
11
- end
12
- end
13
- end
14
- end
@@ -1,23 +0,0 @@
1
- module Screengem
2
- #
3
- # Common error to signal a question that was answered incorrectly.
4
- #
5
- class IncorrectAnswer < RuntimeError
6
- def initialize(question)
7
- super(extract_question_text(question))
8
- end
9
-
10
- private
11
-
12
- #
13
- # Transforms question class name into a text message.
14
- #
15
- # Example:
16
- #
17
- # Questions::SignatureCapturedQuestion is transformed to 'Signature captured?'.
18
- #
19
- def extract_question_text(question)
20
- question.class.name.demodulize.underscore.humanize.gsub(" question", "?")
21
- end
22
- end
23
- end