chemlab 0.7.1 → 0.8.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: b5adc75f1131d78970aa177e504bd9054b1bf07aab8c7bb2cbf0056fb81fa889
4
- data.tar.gz: e1089e0141e142684cb6eac2dfac48a4383cd043d32902362f7c26b45c8b52a3
3
+ metadata.gz: 22938ab6275dea5d261c7499696a054b8858d978ca599894cbf38f21c38760eb
4
+ data.tar.gz: 839a5a65657bdd878de6b3a77f2ee76299f046e64dc916d9c38b04b6b3864c55
5
5
  SHA512:
6
- metadata.gz: bdcad6b56b68d707a83cf9d932eb290d272e48b2c67c24ee0c5f2e4fe2e158b3bff80268652780d344da0e4b7f922634549b9a02601a19adcc0c73c1019913ab
7
- data.tar.gz: f0856ad93ae0b5f18f9b0590f1ba897418d9e0ba2557da225fcea29f448c868d528eb4e04b5d09753a3f7572a859711aaf1ad59bc3344665637703ebf7b3fd78
6
+ metadata.gz: d9b1e6d51ecfe17edc783f3d02897dfc19339e84f45b4ff4c2228224ef0857ee7668e53d6762aa9282fbb943bcd38339308effb5221e1b29a46be3fc6ecf9aae
7
+ data.tar.gz: 572de2ab4941bbe65c49817f4da6d818d811f643ab2a7899294eb2d8a137442c78aa11b47833d91183bf211a279c8ce457c15a17c92204e838791c351be0808b
@@ -16,7 +16,7 @@ module Chemlab
16
16
  raise %(Cannot create new library `#{library_name}` as the directory "#{library_name}" already exists)
17
17
  end
18
18
 
19
- require 'active_support/core_ext/string/inflections'
19
+ require 'chemlab/core_ext/string/inflections'
20
20
 
21
21
  @library = {
22
22
  name: library_name,
@@ -53,7 +53,7 @@ module Chemlab
53
53
 
54
54
  library = Stubber.libraries.last # last appended library is this Page Library
55
55
 
56
- require 'active_support/core_ext/string/inflections'
56
+ require 'chemlab/core_ext/string/inflections'
57
57
 
58
58
  stub_path = @path.gsub(@path[@path.rindex('.')..], '.stub.rb')
59
59
  File.open(stub_path, 'w') do |stub|
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Start monkey patch of Object::String
4
+ class String
5
+ # Classify a string
6
+ # @example
7
+ # 'test_class'.classify #=> TestClass
8
+ # @example
9
+ # 'testclass'.classify #=> Testclass
10
+ def classify
11
+ split('_').map(&:capitalize).join
12
+ end
13
+
14
+ # Underscore a multi-worded string
15
+ # @example
16
+ # 'TestClass'.underscore #=> 'test_class'
17
+ # @example
18
+ # 'Class'.underscore #=> 'class'
19
+ def underscore
20
+ chars.each_with_object(+'') do |c, str|
21
+ str << '_' if c.match?(/[A-Z]/) && !str.size.zero?
22
+ str << c.downcase
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Start monkey patch of String
4
+ class String
5
+ # Find the root module (parent module) of a class or module
6
+ # @example
7
+ # 'A::B::C'.root_module #=> A
8
+ # 'A::B'.root_module => A
9
+ # @return [Module] the root module
10
+ def root_module
11
+ Object.const_get(split('::').first)
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Chemlab
4
+ # Application Library Definition
5
+ # Provides accessors for +:base_url+, +:base_url=+
6
+ # +base_url+ will default to Chemlab's configured base_url
7
+ module Library
8
+ def self.included(base)
9
+ base.module_eval do
10
+ class << self
11
+ # The Base URL where this library / application exists
12
+ # If you have multiple applications that Chemlab will target,
13
+ # this is useful for having separate base_urls.
14
+ #
15
+ # @return [String] the base_url. +Chemlab.configuration.base_url+ by default if not set
16
+ #
17
+ # @example
18
+ # Chemlab.configure do |chemlab|
19
+ # A.base_url = 'https://first_app'
20
+ # B.base_url = 'https://second_app'
21
+ # chemlab.base_url = 'https://main_app'
22
+ #
23
+ # chemlab.libraries = [A, B, C]
24
+ #
25
+ # C.base_url #=> https://main_app
26
+ # end
27
+ attr_writer :base_url
28
+
29
+ def base_url
30
+ @base_url ||= Chemlab.configuration.base_url
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable'
4
+ require 'chemlab/core_ext/string/root_module'
4
5
 
5
6
  module Chemlab
6
7
  module Runtime
@@ -17,13 +18,56 @@ module Chemlab
17
18
  @session = Session.new(browser_options)
18
19
  end
19
20
 
21
+ # Navigate to a given Page library
22
+ # @param [Class<Chemlab::Page>] page_class the class of the Page to navigate to
23
+ # @example
24
+ # Given:
25
+ # module TheLibrary
26
+ # def self.base_url
27
+ # 'https://example.com'
28
+ # end
29
+ # class ThePage < Chemlab::Page
30
+ # path '/path'
31
+ # end
32
+ # end
33
+ #
34
+ # Chemlab::Runtime::Browser.navigate_to(TheLibrary::ThePage) #=> Navigates to https://example.com/path
35
+ #
36
+ # @example
37
+ # Given:
38
+ # Chemlab.configure do |chemlab|
39
+ # chemlab.base_url = 'https://example.com'
40
+ # end
41
+ #
42
+ # class ThePage < Chemlab::Page
43
+ # path '/'
44
+ # end
45
+ #
46
+ # Chemlab::Runtime::Browser.navigate_to(ThePage) #=> Navigates to https://example.com/path
20
47
  def self.navigate_to(page_class)
21
- Chemlab.configuration.browser.navigate_to(page_class.path)
48
+ unless page_class&.name.respond_to?(:root_module) && page_class.name.root_module.respond_to?(:base_url)
49
+ return Chemlab.configuration.browser.navigate_to(Chemlab.configuration.base_url + page_class.path)
50
+ end
51
+
52
+ # workaround for file:// protocol. URI.join() does not work with URI.join('file:///Users', '/user')
53
+ uri = if URI(page_class.name.root_module.base_url).scheme == 'file'
54
+ URI(File.join(page_class.name.root_module.base_url, page_class.path))
55
+ else
56
+ URI.join(page_class.name.root_module.base_url, page_class.path)
57
+ end
58
+
59
+ Chemlab.configuration.browser.navigate_to(uri)
22
60
  end
23
61
 
24
- def navigate_to(path)
62
+ # Navigate to a URI or Path
63
+ # @param [URI,String] uri_or_path the URI or path
64
+ # @return [URI,String] the URI or Path that was navigated to
65
+ # @example
66
+ # Chemlab.configuration.browser.navigate_to('/path') #=> /path
67
+ # Chemlab.configuration.browser.navigate_to(URI('https://example.com/path')) #=> URI('https://example.com/path')
68
+ def navigate_to(uri_or_path)
25
69
  @session ||= Chemlab.configuration.browser.session
26
- @session.engine.goto(Chemlab.configuration.base_url + path)
70
+ @session.engine.goto(uri_or_path.to_s)
27
71
  end
28
72
 
29
73
  # The options used to create the browser session
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chemlab
4
- VERSION = '0.7.1'
4
+ VERSION = '0.8.1'
5
5
  end
data/lib/chemlab.rb CHANGED
@@ -34,6 +34,7 @@ module Chemlab
34
34
  autoload :Element, 'chemlab/element'
35
35
  autoload :Component, 'chemlab/component'
36
36
  autoload :Page, 'chemlab/page'
37
+ autoload :Library, 'chemlab/library'
37
38
 
38
39
  # Runtime modules
39
40
  module Runtime
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chemlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.1
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-07-07 00:00:00.000000000 Z
11
+ date: 2021-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: climate_control
@@ -122,20 +122,6 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.9.26
125
- - !ruby/object:Gem::Dependency
126
- name: activesupport-inflector
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '0.1'
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '0.1'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: colorize
141
127
  requirement: !ruby/object:Gem::Requirement
@@ -253,7 +239,10 @@ files:
253
239
  - lib/chemlab/cli/stubber.rb
254
240
  - lib/chemlab/component.rb
255
241
  - lib/chemlab/configuration.rb
242
+ - lib/chemlab/core_ext/string/inflections.rb
243
+ - lib/chemlab/core_ext/string/root_module.rb
256
244
  - lib/chemlab/element.rb
245
+ - lib/chemlab/library.rb
257
246
  - lib/chemlab/page.rb
258
247
  - lib/chemlab/runtime/browser.rb
259
248
  - lib/chemlab/runtime/env.rb
@@ -276,7 +265,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
276
265
  requirements:
277
266
  - - ">="
278
267
  - !ruby/object:Gem::Version
279
- version: 2.7.2
268
+ version: '2.5'
280
269
  required_rubygems_version: !ruby/object:Gem::Requirement
281
270
  requirements:
282
271
  - - ">="