chemlab 0.4.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +8 -0
- data/bin/chemlab +10 -0
- data/bin/chemlab-suite +1 -0
- data/bin/chemlab-test +1 -0
- data/lib/chemlab.rb +27 -17
- data/lib/chemlab/attributable.rb +16 -10
- data/lib/chemlab/cli/fixtures/new_library/.gitignore +63 -0
- data/lib/chemlab/cli/fixtures/new_library/Gemfile +5 -0
- data/lib/chemlab/cli/fixtures/new_library/README.md.erb +1 -0
- data/lib/chemlab/cli/fixtures/new_library/lib/new_library.rb.erb +7 -0
- data/lib/chemlab/cli/fixtures/new_library/lib/page/sample.rb.erb +9 -0
- data/lib/chemlab/cli/fixtures/new_library/new_library.gemspec.erb +23 -0
- data/lib/chemlab/cli/fixtures/new_library/spec/integration/page/sample_spec.rb.erb +17 -0
- data/lib/chemlab/cli/fixtures/new_library/spec/unit/page/sample_spec.rb.erb +19 -0
- data/lib/chemlab/cli/generator.rb +46 -0
- data/lib/chemlab/cli/generator/templates/page.erb +3 -0
- data/lib/chemlab/cli/new_library.rb +62 -0
- data/lib/chemlab/cli/stub.erb +66 -0
- data/lib/chemlab/cli/stubber.rb +74 -0
- data/lib/chemlab/component.rb +78 -8
- data/lib/chemlab/configuration.rb +60 -12
- data/lib/chemlab/core_ext/string/inflections.rb +25 -0
- data/lib/chemlab/element.rb +4 -0
- data/lib/chemlab/page.rb +19 -1
- data/lib/chemlab/runtime/browser.rb +13 -17
- data/lib/chemlab/runtime/env.rb +13 -9
- data/lib/chemlab/runtime/logger.rb +16 -13
- data/lib/chemlab/version.rb +1 -1
- data/lib/tasks/generate.rake +22 -0
- data/lib/tasks/generate_stubs.rake +20 -0
- data/lib/tasks/help.rake +24 -0
- data/lib/tasks/new.rake +19 -0
- data/lib/tasks/version.rake +8 -0
- metadata +101 -58
- data/lib/chemlab/api_fabricator.rb +0 -134
- data/lib/chemlab/resource.rb +0 -169
- data/lib/chemlab/runtime/api_client.rb +0 -18
- data/lib/chemlab/support/api.rb +0 -71
- data/lib/chemlab/support/logging.rb +0 -176
- data/lib/chemlab/support/repeater.rb +0 -65
- data/lib/chemlab/support/waiter.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d84958e53d93ed46c4a4f93d1c236ae724b7f328ed010b0432ceef6c1ba23d21
|
4
|
+
data.tar.gz: 78df858369ff4a789f328bfb75f6ef550a594456b2ab57b0dcf44dd294c2772e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2da525ce9135405cf917410515943d1542db46c4270f25ec5bbaa910b93f1d7a4fac83c8defa51ec9513e826c681bb22db2bd8721fe4561584d5588ae6019a02
|
7
|
+
data.tar.gz: 99086cec60d34d42b25ea7415fdf464259e4742085d77e438fe9553692a176e4d5ad819f466c25e3c07841adeb4d17f1cff2a1f78d23f72632ab5dc1c395207f
|
data/Rakefile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks' # load bundler gem tasks such as `build`, `release` to help maintain Chemlab Libraries
|
4
|
+
|
5
|
+
# enable metadata. this is required for --help
|
6
|
+
Rake::TaskManager.record_task_metadata = true
|
7
|
+
|
8
|
+
Dir[File.expand_path('lib/tasks/**/*.rake', __dir__)].each { |f| Rake.load_rakefile(f) }
|
data/bin/chemlab
ADDED
data/bin/chemlab-suite
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
bin/chemlab
|
data/bin/chemlab-test
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
bin/chemlab
|
data/lib/chemlab.rb
CHANGED
@@ -2,19 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'watir'
|
4
4
|
|
5
|
-
require 'chemlab/configuration'
|
6
|
-
require 'chemlab/attributable'
|
7
|
-
require 'chemlab/runtime/env'
|
8
|
-
require 'chemlab/runtime/browser'
|
9
|
-
require 'chemlab/element'
|
10
|
-
require 'chemlab/component'
|
11
|
-
require 'chemlab/page'
|
12
|
-
require 'chemlab/support/api'
|
13
|
-
require 'chemlab/api_fabricator'
|
14
|
-
require 'chemlab/resource'
|
15
|
-
|
16
5
|
# Chemlaboratory
|
17
6
|
module Chemlab
|
7
|
+
autoload :Version, 'chemlab/version'
|
18
8
|
|
19
9
|
# Yields the global configuration to a block.
|
20
10
|
# @yield [Configuration] global configuration
|
@@ -23,18 +13,38 @@ module Chemlab
|
|
23
13
|
# Chemlab.configure do |config|
|
24
14
|
# config.base_url = 'https://example.com'
|
25
15
|
# end
|
26
|
-
def self.configure
|
27
|
-
yield configuration if block_given?
|
16
|
+
def self.configure(&block)
|
17
|
+
yield configuration(&block) if block_given?
|
28
18
|
end
|
29
19
|
|
30
|
-
# Returns the global [Configuration]
|
20
|
+
# Returns the global [Chemlab::Configuration] object. While
|
31
21
|
# you _can_ use this method to access the configuration, the more common
|
32
22
|
# convention is to use Chemlab.configure.
|
33
23
|
#
|
34
24
|
# @example
|
35
|
-
# Chemlab.configuration.
|
25
|
+
# Chemlab.configuration.something = 1234
|
36
26
|
# @see Chemlab.configure
|
37
|
-
def self.configuration
|
38
|
-
@configuration ||= Chemlab::Configuration.new
|
27
|
+
def self.configuration(&block)
|
28
|
+
@configuration ||= Chemlab::Configuration.new(&block)
|
29
|
+
end
|
30
|
+
|
31
|
+
autoload :Configuration, 'chemlab/configuration'
|
32
|
+
autoload :Attributable, 'chemlab/attributable'
|
33
|
+
|
34
|
+
autoload :Element, 'chemlab/element'
|
35
|
+
autoload :Component, 'chemlab/component'
|
36
|
+
autoload :Page, 'chemlab/page'
|
37
|
+
|
38
|
+
# Runtime modules
|
39
|
+
module Runtime
|
40
|
+
autoload :Env, 'chemlab/runtime/env'
|
41
|
+
autoload :Browser, 'chemlab/runtime/browser'
|
42
|
+
autoload :Logger, 'chemlab/runtime/logger'
|
43
|
+
end
|
44
|
+
|
45
|
+
module CLI
|
46
|
+
autoload :Generator, 'chemlab/cli/generator'
|
47
|
+
autoload :Stubber, 'chemlab/cli/stubber'
|
48
|
+
autoload :NewLibrary, 'chemlab/cli/new_library'
|
39
49
|
end
|
40
50
|
end
|
data/lib/chemlab/attributable.rb
CHANGED
@@ -7,18 +7,24 @@ module Chemlab
|
|
7
7
|
# include Attributable
|
8
8
|
# attribute :url
|
9
9
|
# attribute :id
|
10
|
-
# attribute :name
|
10
|
+
# attribute :name do
|
11
|
+
# 'test'
|
12
|
+
# end
|
11
13
|
module Attributable
|
12
|
-
def
|
13
|
-
|
14
|
-
|
14
|
+
def self.included(base)
|
15
|
+
base.class_eval do
|
16
|
+
def self.attribute(name)
|
17
|
+
default_value = nil
|
18
|
+
default_value = yield if block_given?
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
define_method(name) do
|
21
|
+
instance_variable_get("@#{name}") ||
|
22
|
+
instance_variable_set(
|
23
|
+
"@#{name}",
|
24
|
+
default_value
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
|
2
|
+
# Created by https://www.toptal.com/developers/gitignore/api/ruby
|
3
|
+
# Edit at https://www.toptal.com/developers/gitignore?templates=ruby
|
4
|
+
|
5
|
+
### Ruby ###
|
6
|
+
*.gem
|
7
|
+
*.rbc
|
8
|
+
/.config
|
9
|
+
/coverage/
|
10
|
+
/InstalledFiles
|
11
|
+
/pkg/
|
12
|
+
/spec/reports/
|
13
|
+
/spec/examples.txt
|
14
|
+
/test/tmp/
|
15
|
+
/test/version_tmp/
|
16
|
+
/tmp/
|
17
|
+
|
18
|
+
# Used by dotenv library to load environment variables.
|
19
|
+
# .env
|
20
|
+
|
21
|
+
# Ignore Byebug command history file.
|
22
|
+
.byebug_history
|
23
|
+
|
24
|
+
## Specific to RubyMotion:
|
25
|
+
.dat*
|
26
|
+
.repl_history
|
27
|
+
build/
|
28
|
+
*.bridgesupport
|
29
|
+
build-iPhoneOS/
|
30
|
+
build-iPhoneSimulator/
|
31
|
+
|
32
|
+
## Specific to RubyMotion (use of CocoaPods):
|
33
|
+
#
|
34
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
35
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
36
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
37
|
+
# vendor/Pods/
|
38
|
+
|
39
|
+
## Documentation cache and generated files:
|
40
|
+
/.yardoc/
|
41
|
+
/_yardoc/
|
42
|
+
/doc/
|
43
|
+
/rdoc/
|
44
|
+
|
45
|
+
## Environment normalization:
|
46
|
+
/.bundle/
|
47
|
+
/vendor/bundle
|
48
|
+
/lib/bundler/man/
|
49
|
+
|
50
|
+
# for a library or gem, you might want to ignore these files since the code is
|
51
|
+
# intended to run in multiple environments; otherwise, check them in:
|
52
|
+
# Gemfile.lock
|
53
|
+
# .ruby-version
|
54
|
+
# .ruby-gemset
|
55
|
+
|
56
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
57
|
+
.rvmrc
|
58
|
+
|
59
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
60
|
+
# .rubocop-https?--*
|
61
|
+
|
62
|
+
# End of https://www.toptal.com/developers/gitignore/api/ruby
|
63
|
+
.idea/
|
@@ -0,0 +1 @@
|
|
1
|
+
# <%= library[:name] %> Library for Chemlab
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = '<%= library[:name] %>'
|
8
|
+
spec.version = '0.0.1'
|
9
|
+
spec.authors = ['Me <me@example.com>']
|
10
|
+
spec.email = []
|
11
|
+
|
12
|
+
spec.summary = 'Page Libraries for <%= library[:name] %>'
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = ''
|
15
|
+
|
16
|
+
spec.files = `git ls-files -- lib/*`.split("\n")
|
17
|
+
|
18
|
+
spec.require_paths = %w[lib]
|
19
|
+
|
20
|
+
spec.add_development_dependency 'rspec'
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'chemlab'
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true %>
|
2
|
+
|
3
|
+
module <%= library[:classified_name] %>
|
4
|
+
module Page
|
5
|
+
RSpec.describe '<%= library[:classified_name] %>' do
|
6
|
+
before do
|
7
|
+
Page::Sample.perform(&:visit)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should have all elements upon navigation' do
|
11
|
+
Page::Sample.perform do |sample|
|
12
|
+
expect(sample).to be_visible
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true %>
|
2
|
+
|
3
|
+
module <%= library[:classified_name] %>
|
4
|
+
module Page
|
5
|
+
RSpec.describe Sample do
|
6
|
+
describe '.path' do
|
7
|
+
it 'should have the correct path' do
|
8
|
+
expect(described_class.path).to eq('/sample')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'elements' do
|
13
|
+
it 'should have elements defined' do
|
14
|
+
expect(described_class.public_elements).not_to be_empty
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module Chemlab
|
6
|
+
module CLI
|
7
|
+
# Base Chemlab class generator ($ chemlab generate ...)
|
8
|
+
module Generator
|
9
|
+
extend self
|
10
|
+
|
11
|
+
INVALID_GENERATOR_ERROR = <<~ERR
|
12
|
+
Cannot generate `%s` as the generator does not exist.
|
13
|
+
Possible options are %s.
|
14
|
+
ERR
|
15
|
+
|
16
|
+
def generate(what, name, args)
|
17
|
+
raise ArgumentError, 'Please specify what to generate' unless what
|
18
|
+
raise ArgumentError, 'Please specify a name' unless name
|
19
|
+
|
20
|
+
unless possible_generators.has_key?(what)
|
21
|
+
raise ArgumentError, INVALID_GENERATOR_ERROR % what,
|
22
|
+
possible_generators.keys.join(',')
|
23
|
+
end
|
24
|
+
|
25
|
+
data = args.each_with_object({}) do |arg, h|
|
26
|
+
k, v = arg.split('=')
|
27
|
+
h[k] = v
|
28
|
+
end
|
29
|
+
|
30
|
+
# render the erb
|
31
|
+
$stdout.puts ERB.new(File.read(possible_generators[what]),
|
32
|
+
trim_mode: '%<>').result_with_hash({ data: data, name: name })
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# List the possible generators
|
38
|
+
# @return [Hash] { 'generator' => 'templates/generator.erb' }
|
39
|
+
def possible_generators
|
40
|
+
Dir[File.expand_path('./generator/templates/*.erb', __dir__)].each_with_object({}) do |generator, generators|
|
41
|
+
generators[File.basename(generator)[0..-5]] = generator
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
require 'tmpdir'
|
5
|
+
|
6
|
+
module Chemlab
|
7
|
+
module CLI
|
8
|
+
# New Library generator module
|
9
|
+
module NewLibrary
|
10
|
+
module_function
|
11
|
+
|
12
|
+
# Scaffold a library by name
|
13
|
+
# @param [String] library_name the name of the library to scaffold
|
14
|
+
def scaffold(library_name)
|
15
|
+
if Dir.exist?(library_name)
|
16
|
+
raise %(Cannot create new library `#{library_name}` as the directory "#{library_name}" already exists)
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'chemlab/core_ext/string/inflections'
|
20
|
+
|
21
|
+
@library = {
|
22
|
+
name: library_name,
|
23
|
+
classified_name: library_name.tr('-', '_').classify,
|
24
|
+
underscored_name: library_name.underscore
|
25
|
+
}
|
26
|
+
|
27
|
+
$stdout.print %(Scaffolding new library in "#{library_name}/"...)
|
28
|
+
|
29
|
+
Dir.mktmpdir(library_name) do |dir|
|
30
|
+
# copy the fixture folder into the tmp folder and name the directory #{library_name}
|
31
|
+
root_dir = File.join(dir, library_name)
|
32
|
+
FileUtils.copy_entry(File.expand_path('./fixtures/new_library', __dir__), root_dir)
|
33
|
+
|
34
|
+
# rename all `new_library` references to #{library_name}
|
35
|
+
Dir.glob(File.join(root_dir, '**', 'new_library*')) do |file|
|
36
|
+
FileUtils.move(file, file.gsub('new_library', library_name))
|
37
|
+
end
|
38
|
+
|
39
|
+
Dir["#{root_dir}/**/*.erb"].each do |template|
|
40
|
+
File.open(template[0..-5], 'w') do |file|
|
41
|
+
file.puts ERB.new(File.read(template), trim_mode: '%<>').result_with_hash({ library: @library })
|
42
|
+
File.delete(template)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
FileUtils.move(File.join(dir, library_name), library_name)
|
47
|
+
end
|
48
|
+
|
49
|
+
$stdout.print " Done\n"
|
50
|
+
end
|
51
|
+
|
52
|
+
# Render a given file
|
53
|
+
# @param [File] source the source file
|
54
|
+
# @note This method will replace `new_library` with the library
|
55
|
+
# @return [String] the destination
|
56
|
+
def render_file(source)
|
57
|
+
puts "Rendering: #{source}"
|
58
|
+
# Dir.mkdir(@tmp_destination)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
<% generation_message = '# This is a stub, used for indexing. The method is dynamically generated' %>
|
4
|
+
<% modules = library.to_s.split('::') %>
|
5
|
+
<% root = (' ' * modules.size) %>
|
6
|
+
<% modules.each_with_index do |mod, indent| %>
|
7
|
+
<%= (' ' * indent) %><%= "module #{mod}\n" %>
|
8
|
+
<% end %>
|
9
|
+
<% library.public_elements.each do |element| %>
|
10
|
+
|
11
|
+
<% if Chemlab::Element::CLICKABLES.include?(element[:type]) %>
|
12
|
+
<%= root %># @note Defined as +<%= "#{element[:type]} :#{element[:name]}" %>+
|
13
|
+
<%= root %># Clicks +<%= element[:name] %>+
|
14
|
+
<%= root %>def <%= element[:name] %>
|
15
|
+
|
16
|
+
<%= root %> <%= generation_message %>.
|
17
|
+
<%= root %>end
|
18
|
+
|
19
|
+
<% else %>
|
20
|
+
<%= root %># @note Defined as +<%= "#{element[:type]} :#{element[:name]}" %>+
|
21
|
+
<%= root %># @return [String] The text content or value of +<%= element[:name] %>+
|
22
|
+
<%= root %>def <%= element[:name] %>
|
23
|
+
|
24
|
+
<%= root %> <%= generation_message %>.
|
25
|
+
<%= root %>end
|
26
|
+
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
<% if Chemlab::Element::INPUTS.include?(element[:type]) %>
|
30
|
+
<%= root %># Set the value of <%= element[:name] %>
|
31
|
+
|
32
|
+
<%= root %># @example
|
33
|
+
<%= root %># <%= library.to_s %>.perform do |<%= modules.last.underscore %>|
|
34
|
+
<%= root %># <%= modules.last.underscore %>.<%= element[:name] %> = 'value'
|
35
|
+
<%= root %># end
|
36
|
+
<%= root %># @param value [String] The value to set.
|
37
|
+
<%= root %>def <%= element[:name] %>=(value)
|
38
|
+
<%= root %> <%= generation_message %>.
|
39
|
+
<%= root %>end
|
40
|
+
<% end %>
|
41
|
+
|
42
|
+
<%= root %># @example
|
43
|
+
<%= root %># <%= library.to_s %>.perform do |<%= modules.last.underscore %>|
|
44
|
+
<%= root %># expect(<%= modules.last.underscore %>.<%= element[:name] %>_element).to exist
|
45
|
+
<%= root %># end
|
46
|
+
<%= root %># @return [Watir::<%= element[:type].to_s.classify %>] The raw +<%= element[:type].to_s.classify %>+ element
|
47
|
+
<%= root %>def <%= element[:name] %>_element
|
48
|
+
<%= root %> <%= generation_message %>.
|
49
|
+
<%= root %>end
|
50
|
+
|
51
|
+
<%= root %># @example
|
52
|
+
<%= root %># <%= library.to_s %>.perform do |<%= modules.last.underscore %>|
|
53
|
+
<%= root %># expect(<%= modules.last.underscore %>).to be_<%= element[:name] %>
|
54
|
+
|
55
|
+
<%= root %># end
|
56
|
+
<%= root %># @return [Boolean] true if the +<%= element[:name] %>+ element is present on the page
|
57
|
+
<%= root %>def <%= element[:name] %>?
|
58
|
+
<%= root %> <%= generation_message %>.
|
59
|
+
<%= root %>end
|
60
|
+
|
61
|
+
<% end %>
|
62
|
+
<% endings = [] %>
|
63
|
+
<% modules.size.times do |indent| %>
|
64
|
+
<% endings << "#{(' ' * indent)}end" %>
|
65
|
+
<% end %>
|
66
|
+
<%= endings.reverse.join("\n") %>
|