screengem 0.9.0 → 0.12.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: accc4cf6330e69e04fb0c2ccf8aded873f0cdd6ca7f548f4d15a0acb3d4f1f7d
4
- data.tar.gz: 68c1c36c5b7763557719751f4e58f5890054e79c09d8fc9fe9cc6dc01fd3a45e
3
+ metadata.gz: d6e95abeb4fb13d09982bb3003eb07d2a54fca26982a895f0e758d95cba7d22f
4
+ data.tar.gz: 7f32e487331fd7221fca398ed025ac0ee81b4ca8a325470db9fc9ae709d0a223
5
5
  SHA512:
6
- metadata.gz: ca06a1fb1c48d88a12b93f56da624dc082535af69608be82b2547fe9da6f4799724cc2294a7fde8db9ef242ccc7374698c05e5f1c97aeeaf921d89ad2a03e245
7
- data.tar.gz: 6f9ac792ef8b6538a2e1d4829a6ff9d7ad43c33f8bfc45a70ec325f1a03cc1ec0a13ebbdca1820193e82f5512cb2d4fdaf41968756d5cfd926e4165828c28827
6
+ metadata.gz: 03a048b636ab93c43019c8c215e595a466a6e4cadc30570eef32fa289745256a2926421f12ae95cd30cb5e0ee4306d3fb6cc17f478da52ea9717ceb704dd7f7b
7
+ data.tar.gz: 4c0a8bccccc951536accac8f15694cc926886bc3f3db850364b295d9f99f88794610ab4242145ed33ff9be480ad068367f6f0e559cba9f8b55e15fc9ab9d13bf
@@ -1,5 +1,22 @@
1
1
  require: rubocop-rspec
2
2
 
3
+ AllCops:
4
+ TargetRubyVersion: 2.6
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
 
@@ -1 +1 @@
1
- 2.5.3
1
+ 2.6.6
@@ -2,6 +2,31 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.12.0 (2021-01-27)
6
+
7
+ * Relax the thor dependency
8
+ * Latest development dependencies
9
+
10
+ ## 0.11.0 (2020-04-26)
11
+
12
+ ### Breaking Changes
13
+
14
+ * Questions answer negatively by throwing an exception rather than returning false
15
+
16
+ ## 0.10.1 (2020-01-11)
17
+
18
+ * Relax the thor dependency
19
+
20
+ ## 0.10.0 (2020-01-11)
21
+
22
+ * Remove action abstraction
23
+ * Latest development dependencies
24
+
25
+ ## 0.9.1 (2019-10-22)
26
+
27
+ * Relax the require_all dependency
28
+ * Latest development dependencies
29
+
5
30
  ## 0.9.0 (2019-09-25)
6
31
 
7
32
  * Support for actor memory outside actor instances (support ParameterType actors)
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
@@ -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.0"
2
+ VERSION = "0.12.0"
3
3
  end
@@ -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.6"
30
31
 
31
- spec.add_runtime_dependency "activesupport", ">= 4.2", "< 6.1"
32
+ spec.add_runtime_dependency "activesupport", ">= 5.2", "< 6.1"
32
33
  spec.add_runtime_dependency "capybara", ">= 2.18", "< 4.0"
33
- spec.add_runtime_dependency "require_all", "~> 2.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
- spec.add_development_dependency "rake", "~> 12.0"
38
- spec.add_development_dependency "rspec", "~> 3.8"
39
- spec.add_development_dependency "rubocop", "~> 0.74"
40
- spec.add_development_dependency "rubocop-rspec", "~> 1.35"
41
- spec.add_development_dependency "simplecov", "~> 0.17"
38
+ spec.add_development_dependency "rake", "~> 13.0"
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.0
4
+ version: 0.12.0
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-09-27 00:00:00.000000000 Z
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,7 +16,7 @@ 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
22
  version: '6.1'
@@ -26,7 +26,7 @@ dependencies:
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
32
  version: '6.1'
@@ -54,114 +54,140 @@ dependencies:
54
54
  name: require_all
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - "~>"
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '3.0'
60
+ - - "<"
58
61
  - !ruby/object:Gem::Version
59
- version: '2.0'
62
+ version: '4.0'
60
63
  type: :runtime
61
64
  prerelease: false
62
65
  version_requirements: !ruby/object:Gem::Requirement
63
66
  requirements:
64
- - - "~>"
67
+ - - ">="
65
68
  - !ruby/object:Gem::Version
66
- version: '2.0'
69
+ version: '3.0'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '4.0'
67
73
  - !ruby/object:Gem::Dependency
68
74
  name: rspec-expectations
69
75
  requirement: !ruby/object:Gem::Requirement
70
76
  requirements:
71
77
  - - "~>"
72
78
  - !ruby/object:Gem::Version
73
- version: '3.8'
79
+ version: '3.10'
74
80
  type: :runtime
75
81
  prerelease: false
76
82
  version_requirements: !ruby/object:Gem::Requirement
77
83
  requirements:
78
84
  - - "~>"
79
85
  - !ruby/object:Gem::Version
80
- version: '3.8'
86
+ version: '3.10'
81
87
  - !ruby/object:Gem::Dependency
82
88
  name: thor
83
89
  requirement: !ruby/object:Gem::Requirement
84
90
  requirements:
85
- - - "~>"
91
+ - - ">="
86
92
  - !ruby/object:Gem::Version
87
93
  version: '0.20'
94
+ - - "<"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.2'
88
97
  type: :runtime
89
98
  prerelease: false
90
99
  version_requirements: !ruby/object:Gem::Requirement
91
100
  requirements:
92
- - - "~>"
101
+ - - ">="
93
102
  - !ruby/object:Gem::Version
94
103
  version: '0.20'
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: '1.2'
95
107
  - !ruby/object:Gem::Dependency
96
108
  name: rake
97
109
  requirement: !ruby/object:Gem::Requirement
98
110
  requirements:
99
111
  - - "~>"
100
112
  - !ruby/object:Gem::Version
101
- version: '12.0'
113
+ version: '13.0'
102
114
  type: :development
103
115
  prerelease: false
104
116
  version_requirements: !ruby/object:Gem::Requirement
105
117
  requirements:
106
118
  - - "~>"
107
119
  - !ruby/object:Gem::Version
108
- version: '12.0'
120
+ version: '13.0'
109
121
  - !ruby/object:Gem::Dependency
110
122
  name: rspec
111
123
  requirement: !ruby/object:Gem::Requirement
112
124
  requirements:
113
125
  - - "~>"
114
126
  - !ruby/object:Gem::Version
115
- version: '3.8'
127
+ version: '3.9'
116
128
  type: :development
117
129
  prerelease: false
118
130
  version_requirements: !ruby/object:Gem::Requirement
119
131
  requirements:
120
132
  - - "~>"
121
133
  - !ruby/object:Gem::Version
122
- version: '3.8'
134
+ version: '3.9'
123
135
  - !ruby/object:Gem::Dependency
124
136
  name: rubocop
125
137
  requirement: !ruby/object:Gem::Requirement
126
138
  requirements:
127
139
  - - "~>"
128
140
  - !ruby/object:Gem::Version
129
- version: '0.74'
141
+ version: '1.8'
130
142
  type: :development
131
143
  prerelease: false
132
144
  version_requirements: !ruby/object:Gem::Requirement
133
145
  requirements:
134
146
  - - "~>"
135
147
  - !ruby/object:Gem::Version
136
- version: '0.74'
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'
156
+ type: :development
157
+ prerelease: false
158
+ version_requirements: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - "~>"
161
+ - !ruby/object:Gem::Version
162
+ version: '1.9'
137
163
  - !ruby/object:Gem::Dependency
138
164
  name: rubocop-rspec
139
165
  requirement: !ruby/object:Gem::Requirement
140
166
  requirements:
141
167
  - - "~>"
142
168
  - !ruby/object:Gem::Version
143
- version: '1.35'
169
+ version: '2.1'
144
170
  type: :development
145
171
  prerelease: false
146
172
  version_requirements: !ruby/object:Gem::Requirement
147
173
  requirements:
148
174
  - - "~>"
149
175
  - !ruby/object:Gem::Version
150
- version: '1.35'
176
+ version: '2.1'
151
177
  - !ruby/object:Gem::Dependency
152
178
  name: simplecov
153
179
  requirement: !ruby/object:Gem::Requirement
154
180
  requirements:
155
181
  - - "~>"
156
182
  - !ruby/object:Gem::Version
157
- version: '0.17'
183
+ version: '0.21'
158
184
  type: :development
159
185
  prerelease: false
160
186
  version_requirements: !ruby/object:Gem::Requirement
161
187
  requirements:
162
188
  - - "~>"
163
189
  - !ruby/object:Gem::Version
164
- version: '0.17'
190
+ version: '0.21'
165
191
  description:
166
192
  email:
167
193
  - alistairm@nulogy.com
@@ -187,13 +213,10 @@ files:
187
213
  - exe/screengem
188
214
  - images/ScreengemCore.png
189
215
  - lib/screengem.rb
190
- - lib/screengem/action.rb
191
216
  - lib/screengem/actor.rb
192
217
  - lib/screengem/actor_memory.rb
193
218
  - lib/screengem/automatic_visit.rb
194
- - lib/screengem/browser_action.rb
195
219
  - lib/screengem/cli.rb
196
- - lib/screengem/concerns/actionable.rb
197
220
  - lib/screengem/concerns/configurable.rb
198
221
  - lib/screengem/concerns/dampenable.rb
199
222
  - lib/screengem/concerns/executable.rb
@@ -201,13 +224,9 @@ files:
201
224
  - lib/screengem/dampen_configuration.rb
202
225
  - lib/screengem/dampen_configuration_generator.rb
203
226
  - lib/screengem/dsl.rb
204
- - lib/screengem/factories/action_factory.rb
205
- - lib/screengem/factories/browser_action_factory.rb
206
227
  - lib/screengem/factories/factory_creation_error.rb
207
228
  - lib/screengem/factories/question_factory.rb
208
- - lib/screengem/factories/standard_action_factory.rb
209
229
  - lib/screengem/factories/task_factory.rb
210
- - lib/screengem/incorrect_answer.rb
211
230
  - lib/screengem/primitive_key.rb
212
231
  - lib/screengem/question.rb
213
232
  - lib/screengem/rails_routes.rb
@@ -233,14 +252,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
233
252
  requirements:
234
253
  - - ">="
235
254
  - !ruby/object:Gem::Version
236
- version: '0'
255
+ version: '2.6'
237
256
  required_rubygems_version: !ruby/object:Gem::Requirement
238
257
  requirements:
239
258
  - - ">="
240
259
  - !ruby/object:Gem::Version
241
260
  version: '0'
242
261
  requirements: []
243
- rubygems_version: 3.0.6
262
+ rubygems_version: 3.2.7
244
263
  signing_key:
245
264
  specification_version: 4
246
265
  summary: Ruby implementation of the Screengem Pattern.
@@ -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