chemlab 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +6 -0
  3. data/bin/chemlab +10 -0
  4. data/bin/chemlab-suite +1 -0
  5. data/bin/chemlab-test +1 -0
  6. data/lib/chemlab.rb +11 -13
  7. data/lib/chemlab/attributable.rb +16 -10
  8. data/lib/chemlab/cli/fixtures/new_library/.gitignore +63 -0
  9. data/lib/chemlab/cli/fixtures/new_library/Gemfile +5 -0
  10. data/lib/chemlab/cli/fixtures/new_library/README.md.erb +1 -0
  11. data/lib/chemlab/cli/fixtures/new_library/lib/new_library.rb.erb +7 -0
  12. data/lib/chemlab/cli/fixtures/new_library/lib/page/sample.rb.erb +9 -0
  13. data/lib/chemlab/cli/fixtures/new_library/new_library.gemspec.erb +23 -0
  14. data/lib/chemlab/cli/fixtures/new_library/spec/integration/page/sample_spec.rb.erb +17 -0
  15. data/lib/chemlab/cli/fixtures/new_library/spec/unit/page/sample_spec.rb.erb +19 -0
  16. data/lib/chemlab/cli/generator.rb +46 -0
  17. data/lib/chemlab/cli/generator/templates/page.erb +3 -0
  18. data/lib/chemlab/cli/new_library.rb +62 -0
  19. data/lib/chemlab/cli/stub.erb +65 -0
  20. data/lib/chemlab/cli/stubber.rb +74 -0
  21. data/lib/chemlab/component.rb +78 -8
  22. data/lib/chemlab/configuration.rb +60 -12
  23. data/lib/chemlab/element.rb +4 -0
  24. data/lib/chemlab/page.rb +19 -1
  25. data/lib/chemlab/runtime/browser.rb +13 -17
  26. data/lib/chemlab/runtime/env.rb +13 -9
  27. data/lib/chemlab/runtime/logger.rb +16 -13
  28. data/lib/chemlab/version.rb +1 -1
  29. data/lib/tasks/generate.rake +22 -0
  30. data/lib/tasks/generate_stubs.rake +20 -0
  31. data/lib/tasks/help.rake +24 -0
  32. data/lib/tasks/new.rake +19 -0
  33. data/lib/tasks/version.rake +8 -0
  34. metadata +87 -49
  35. data/lib/chemlab/api_fabricator.rb +0 -134
  36. data/lib/chemlab/resource.rb +0 -169
  37. data/lib/chemlab/runtime/api_client.rb +0 -18
  38. data/lib/chemlab/support/api.rb +0 -71
  39. data/lib/chemlab/support/logging.rb +0 -176
  40. data/lib/chemlab/support/repeater.rb +0 -65
  41. data/lib/chemlab/support/waiter.rb +0 -39
@@ -1,23 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
4
- require 'forwardable'
5
-
6
3
  module Chemlab
7
4
  module Runtime
5
+ # Logger module
8
6
  module Logger
9
- extend SingleForwardable
10
-
11
- def_delegators :logger, :debug, :info, :warn, :error, :fatal, :unknown
7
+ # Log something to a stream
8
+ # @param [Any] obj Any object that responds to #to_s
9
+ # @param [Symbol] type The type of message logged
10
+ # @param [Hash] args Any additional arguments
11
+ # @example
12
+ # log('something', :info) #=> logs INFO :: something, to $stdout
13
+ # log('error', :err) #=> logs ERR :: error, to $stderr
14
+ # log('important', :important, stream: $stderr) #=> logs IMPO :: important, to $stderr
15
+ # log('to file', :info, stream: File.open('file.txt', 'w')) #=> logs INFO :: to file, to the file.txt file
16
+ def log(obj, type = :info, **args)
17
+ raise ArgumentError, "Cannot log #{obj} as it does not respond to to_s!" unless obj.respond_to?(:to_s)
12
18
 
13
- singleton_class.module_eval do
14
- attr_writer :logger
19
+ args[:stream] = type.match?(/(err(or)?|warn(ing)?)/) ? $stderr : $stdout
15
20
 
16
- def logger
17
- @logger ||= ::Logger.new(Runtime::Env.log_destination).tap do |logger|
18
- logger.level = Runtime::Env.debug? ? ::Logger::DEBUG : ::Logger::ERROR
19
- end
20
- end
21
+ prefix = Time.now.strftime('%Y-%m-%d %H:%M:%S / ')
22
+ prefix << type[0..3].upcase << "\t:: " # we only want the prefix to be four chars long
23
+ args[:stream].puts(prefix << obj.to_s)
21
24
  end
22
25
  end
23
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chemlab
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ desc <<-DESCRIPTION
4
+ Generate something
5
+
6
+ Arguments: WHAT NAME [ARGS]
7
+ Examples:
8
+ - generate page Login path=/users/sign_in
9
+ Generates a page library
10
+ Notes:
11
+ - [ARGS] will be in form key=value separated by `=`
12
+ DESCRIPTION
13
+ task :generate do |_, args|
14
+ require_relative '../chemlab/cli/generator'
15
+
16
+ raise ArgumentError, 'Please specify what to generate and the name' if args.size < 2
17
+
18
+ what = args.shift
19
+ name = args.shift
20
+
21
+ Chemlab::CLI::Generator.generate(what, name, args)
22
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :generate do
4
+ desc <<-DESCRIPTION
5
+ Generate page library stubs
6
+
7
+ Arguments: PATH
8
+ Examples:
9
+ - generate:stubs qa/page/login.rb
10
+ Generate stubs for a specific page library
11
+ - generate:stubs qa/page
12
+ Generates stubs for all page libraries in `qa/page`
13
+ DESCRIPTION
14
+ task :stubs do |_, path|
15
+ puts "Doin some stubbin in #{path}"
16
+
17
+ require_relative '../chemlab/cli/stubber'
18
+ Chemlab::CLI::Stubber.stub_all(path)
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'colorize'
4
+
5
+ desc 'Show the help'
6
+ task '--help' do
7
+ usage = +%(Usage: #{$PROGRAM_NAME} TASK\n)
8
+
9
+ Rake.application.tasks.each do |task|
10
+ usage += %(#{task.name.bold}: #{task.comment}\n)
11
+
12
+ next unless task.full_comment && task.full_comment != task.comment
13
+
14
+ # standardize and colorize the description
15
+ full_comment = task.full_comment.gsub(/(Arguments|Examples|Notes):/, '\1:'.underline)
16
+
17
+ # remove the short description and the newlines
18
+ full_comment = full_comment[task.comment.size + 2..]
19
+
20
+ usage += %(#{full_comment}\n\n)
21
+ end
22
+
23
+ $stdout.puts usage
24
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ desc <<-DESCRIPTION
4
+ Scaffold a new Chemlab Library
5
+
6
+ Arguments: PATH
7
+ Examples:
8
+ - new my-library
9
+ Scaffolds a new Chemlab Library in the `my-library` directory.
10
+ This will fail if the PATH already exists
11
+ DESCRIPTION
12
+ task 'new' do |_, args|
13
+ require_relative '../chemlab/cli/new_library'
14
+
15
+ library = args.first
16
+
17
+ warn "NOTE: Only creating #{library}" if args.size > 1
18
+ Chemlab::CLI::NewLibrary.scaffold(library)
19
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ desc 'Shows the version'
4
+ task '--version' do
5
+ require_relative '../chemlab/version'
6
+
7
+ $stdout.puts %(#{$PROGRAM_NAME} version #{Chemlab::VERSION})
8
+ end
metadata CHANGED
@@ -1,161 +1,183 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chemlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab Quality
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-28 00:00:00.000000000 Z
11
+ date: 2021-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: debase
14
+ name: climate_control
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.4.1
19
+ version: 1.0.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: 0.2.4.1
26
+ version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: faker
28
+ name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 1.6.6
33
+ version: 1.10.9
37
34
  type: :development
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: '1.6'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 1.6.6
40
+ version: 1.10.9
47
41
  - !ruby/object:Gem::Dependency
48
- name: pry-byebug
42
+ name: pry
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: 3.5.1
47
+ version: 0.14.1
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: 3.5.1
54
+ version: 0.14.1
61
55
  - !ruby/object:Gem::Dependency
62
- name: ruby-debug-ide
56
+ name: rspec
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
59
  - - "~>"
66
60
  - !ruby/object:Gem::Version
67
- version: 0.7.0
61
+ version: '3.7'
68
62
  type: :development
69
63
  prerelease: false
70
64
  version_requirements: !ruby/object:Gem::Requirement
71
65
  requirements:
72
66
  - - "~>"
73
67
  - !ruby/object:Gem::Version
74
- version: 0.7.0
68
+ version: '3.7'
75
69
  - !ruby/object:Gem::Dependency
76
- name: timecop
70
+ name: rspec-parameterized
77
71
  requirement: !ruby/object:Gem::Requirement
78
72
  requirements:
79
73
  - - "~>"
80
74
  - !ruby/object:Gem::Version
81
- version: 0.9.1
75
+ version: 0.4.2
82
76
  type: :development
83
77
  prerelease: false
84
78
  version_requirements: !ruby/object:Gem::Requirement
85
79
  requirements:
86
80
  - - "~>"
87
81
  - !ruby/object:Gem::Version
88
- version: 0.9.1
82
+ version: 0.4.2
89
83
  - !ruby/object:Gem::Dependency
90
- name: rspec
84
+ name: rubocop
91
85
  requirement: !ruby/object:Gem::Requirement
92
86
  requirements:
93
87
  - - "~>"
94
88
  - !ruby/object:Gem::Version
95
- version: '3.7'
89
+ version: 1.14.0
96
90
  type: :development
97
91
  prerelease: false
98
92
  version_requirements: !ruby/object:Gem::Requirement
99
93
  requirements:
100
94
  - - "~>"
101
95
  - !ruby/object:Gem::Version
102
- version: '3.7'
96
+ version: 1.14.0
103
97
  - !ruby/object:Gem::Dependency
104
- name: rspec-retry
98
+ name: rubocop-rspec
105
99
  requirement: !ruby/object:Gem::Requirement
106
100
  requirements:
107
101
  - - "~>"
108
102
  - !ruby/object:Gem::Version
109
- version: 0.6.1
103
+ version: 2.3.0
110
104
  type: :development
111
105
  prerelease: false
112
106
  version_requirements: !ruby/object:Gem::Requirement
113
107
  requirements:
114
108
  - - "~>"
115
109
  - !ruby/object:Gem::Version
116
- version: 0.6.1
110
+ version: 2.3.0
117
111
  - !ruby/object:Gem::Dependency
118
- name: rspec_junit_formatter
112
+ name: yard
119
113
  requirement: !ruby/object:Gem::Requirement
120
114
  requirements:
121
115
  - - "~>"
122
116
  - !ruby/object:Gem::Version
123
- version: 0.4.1
117
+ version: 0.9.26
124
118
  type: :development
125
119
  prerelease: false
126
120
  version_requirements: !ruby/object:Gem::Requirement
127
121
  requirements:
128
122
  - - "~>"
129
123
  - !ruby/object:Gem::Version
130
- version: 0.4.1
124
+ version: 0.9.26
131
125
  - !ruby/object:Gem::Dependency
132
- name: nokogiri
126
+ name: activesupport-inflector
133
127
  requirement: !ruby/object:Gem::Requirement
134
128
  requirements:
135
129
  - - "~>"
136
130
  - !ruby/object:Gem::Version
137
- version: 1.10.9
138
- type: :development
131
+ version: 0.1.0
132
+ type: :runtime
139
133
  prerelease: false
140
134
  version_requirements: !ruby/object:Gem::Requirement
141
135
  requirements:
142
136
  - - "~>"
143
137
  - !ruby/object:Gem::Version
144
- version: 1.10.9
138
+ version: 0.1.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: colorize
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.8.1
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.8.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: i18n
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 1.8.10
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 1.8.10
145
167
  - !ruby/object:Gem::Dependency
146
168
  name: rake
147
169
  requirement: !ruby/object:Gem::Requirement
148
170
  requirements:
149
171
  - - "~>"
150
172
  - !ruby/object:Gem::Version
151
- version: 12.3.0
173
+ version: 13.0.3
152
174
  type: :runtime
153
175
  prerelease: false
154
176
  version_requirements: !ruby/object:Gem::Requirement
155
177
  requirements:
156
178
  - - "~>"
157
179
  - !ruby/object:Gem::Version
158
- version: 12.3.0
180
+ version: 13.0.3
159
181
  - !ruby/object:Gem::Dependency
160
182
  name: selenium-webdriver
161
183
  requirement: !ruby/object:Gem::Requirement
@@ -187,28 +209,44 @@ dependencies:
187
209
  description:
188
210
  email:
189
211
  - quality@gitlab.com
190
- executables: []
212
+ executables:
213
+ - chemlab
191
214
  extensions: []
192
215
  extra_rdoc_files: []
193
216
  files:
217
+ - Rakefile
218
+ - bin/chemlab
219
+ - bin/chemlab-suite
220
+ - bin/chemlab-test
194
221
  - lib/chemlab.rb
195
- - lib/chemlab/api_fabricator.rb
196
222
  - lib/chemlab/attributable.rb
223
+ - lib/chemlab/cli/fixtures/new_library/.gitignore
224
+ - lib/chemlab/cli/fixtures/new_library/Gemfile
225
+ - lib/chemlab/cli/fixtures/new_library/README.md.erb
226
+ - lib/chemlab/cli/fixtures/new_library/lib/new_library.rb.erb
227
+ - lib/chemlab/cli/fixtures/new_library/lib/page/sample.rb.erb
228
+ - lib/chemlab/cli/fixtures/new_library/new_library.gemspec.erb
229
+ - lib/chemlab/cli/fixtures/new_library/spec/integration/page/sample_spec.rb.erb
230
+ - lib/chemlab/cli/fixtures/new_library/spec/unit/page/sample_spec.rb.erb
231
+ - lib/chemlab/cli/generator.rb
232
+ - lib/chemlab/cli/generator/templates/page.erb
233
+ - lib/chemlab/cli/new_library.rb
234
+ - lib/chemlab/cli/stub.erb
235
+ - lib/chemlab/cli/stubber.rb
197
236
  - lib/chemlab/component.rb
198
237
  - lib/chemlab/configuration.rb
199
238
  - lib/chemlab/element.rb
200
239
  - lib/chemlab/page.rb
201
- - lib/chemlab/resource.rb
202
- - lib/chemlab/runtime/api_client.rb
203
240
  - lib/chemlab/runtime/browser.rb
204
241
  - lib/chemlab/runtime/env.rb
205
242
  - lib/chemlab/runtime/logger.rb
206
- - lib/chemlab/support/api.rb
207
- - lib/chemlab/support/logging.rb
208
- - lib/chemlab/support/repeater.rb
209
- - lib/chemlab/support/waiter.rb
210
243
  - lib/chemlab/version.rb
211
- homepage: https://about.gitlab.com
244
+ - lib/tasks/generate.rake
245
+ - lib/tasks/generate_stubs.rake
246
+ - lib/tasks/help.rake
247
+ - lib/tasks/new.rake
248
+ - lib/tasks/version.rake
249
+ homepage: https://about.gitlab.com/
212
250
  licenses:
213
251
  - MIT
214
252
  metadata: {}
@@ -220,14 +258,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
258
  requirements:
221
259
  - - ">="
222
260
  - !ruby/object:Gem::Version
223
- version: '0'
261
+ version: 2.7.2
224
262
  required_rubygems_version: !ruby/object:Gem::Requirement
225
263
  requirements:
226
264
  - - ">="
227
265
  - !ruby/object:Gem::Version
228
266
  version: '0'
229
267
  requirements: []
230
- rubygems_version: 3.0.6
268
+ rubygems_version: 3.1.4
231
269
  signing_key:
232
270
  specification_version: 4
233
271
  summary: Automation framework built by GitLab, for the world.
@@ -1,134 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/core_ext/object/deep_dup'
4
-
5
- module Chemlab
6
- # API Fabricator
7
- module ApiFabricator
8
- ResourceFabricationFailedError = Class.new(RuntimeError)
9
- ResourceNotDeletedError = Class.new(RuntimeError)
10
- ResourceNotFoundError = Class.new(RuntimeError)
11
- ResourceQueryError = Class.new(RuntimeError)
12
- ResourceUpdateFailedError = Class.new(RuntimeError)
13
- ResourceURLMissingError = Class.new(RuntimeError)
14
- InternalServerError = Class.new(RuntimeError)
15
-
16
- attr_reader :api_resource, :api_response
17
- attr_writer :api_client
18
- attr_accessor :user
19
-
20
- def api_support?
21
- respond_to?(:api_get_path) &&
22
- (respond_to?(:api_post_path) && respond_to?(:api_post_body)) ||
23
- (respond_to?(:api_put_path) && respond_to?(:api_put_body))
24
- end
25
-
26
- def fabricate_via_api!
27
- unless api_support?
28
- raise NotImplementedError, "Resource #{self.class.name} does not support fabrication via the API!"
29
- end
30
-
31
- resource_web_url(api_post)
32
- end
33
-
34
- def reload!
35
- api_get
36
-
37
- self
38
- end
39
-
40
- def remove_via_api!
41
- api_delete
42
- end
43
-
44
- def eager_load_api_client!
45
- return unless api_client.nil?
46
-
47
- api_client.tap do |client|
48
- # Eager-load the API client so that the personal token creation isn't
49
- # taken in account in the actual resource creation timing.
50
- client.user = user
51
- client.personal_access_token
52
- end
53
- end
54
-
55
- include Support::API
56
-
57
- attr_writer :api_resource, :api_response
58
-
59
- def api_put(body = api_put_body)
60
- response = put(
61
- Runtime::API::Request.new(api_client, api_put_path).url,
62
- body)
63
-
64
- unless response.code == HTTP_STATUS_OK
65
- raise ResourceFabricationFailedError, "Updating #{self.class.name} using the API failed (#{response.code}) with `#{response}`."
66
- end
67
-
68
- process_api_response(parse_body(response))
69
- end
70
-
71
- private
72
-
73
- def resource_web_url(resource)
74
- resource.fetch(:web_url) do
75
- raise ResourceURLMissingError, "API resource for #{self.class.name} does not expose a `web_url` property: `#{resource}`."
76
- end
77
- end
78
-
79
- def api_get
80
- process_api_response(parse_body(api_get_from(api_get_path)))
81
- end
82
-
83
- def api_get_from(get_path)
84
- url = Runtime::API::Request.new(api_client, get_path).url
85
- response = get(url)
86
-
87
- if response.code == HTTP_STATUS_SERVER_ERROR
88
- raise InternalServerError, "Failed to GET #{url} - (#{response.code}): `#{response}`."
89
- elsif response.code != HTTP_STATUS_OK
90
- raise ResourceNotFoundError, "Resource at #{url} could not be found (#{response.code}): `#{response}`."
91
- end
92
-
93
- response
94
- end
95
-
96
- def api_post
97
- response = post(
98
- Runtime::API::Request.new(api_client, api_post_path).url,
99
- api_post_body)
100
-
101
- unless response.code == HTTP_STATUS_CREATED
102
- raise ResourceFabricationFailedError, "Fabrication of #{self.class.name} using the API failed (#{response.code}) with `#{response}`."
103
- end
104
-
105
- process_api_response(parse_body(response))
106
- end
107
-
108
- def api_delete
109
- url = Runtime::API::Request.new(api_client, api_delete_path).url
110
- response = delete(url)
111
-
112
- unless [HTTP_STATUS_NO_CONTENT, HTTP_STATUS_ACCEPTED].include? response.code
113
- raise ResourceNotDeletedError, "Resource at #{url} could not be deleted (#{response.code}): `#{response}`."
114
- end
115
-
116
- response
117
- end
118
-
119
- def api_client
120
- @api_client ||= begin
121
- Runtime::API::Client.new(:gitlab, is_new_session: !current_url.start_with?('http'), user: user)
122
- end
123
- end
124
-
125
- def process_api_response(parsed_response)
126
- self.api_response = parsed_response
127
- self.api_resource = transform_api_resource(parsed_response.deep_dup)
128
- end
129
-
130
- def transform_api_resource(api_resource)
131
- api_resource
132
- end
133
- end
134
- end