chemlab 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +6 -0
- data/bin/chemlab +10 -0
- data/bin/chemlab-suite +1 -0
- data/bin/chemlab-test +1 -0
- data/lib/chemlab.rb +11 -13
- 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 +65 -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/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 +87 -49
- 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: 915c01df3e022bd6da7158493e4da0cab8df087854f696ee048ab4ca6ed32d50
|
4
|
+
data.tar.gz: ff042d7a35caca43a932a3802ed765ba988b9f983f8a6ffe11905564876c674a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48967c413bc7c0f0650439c7c3d11aa3ef46cb5b0235d40bc80de82ae0b273838e4f35b8c3f2a4f8a5335307904f6447ffaec16607ce8f59cd31881b01461bb9
|
7
|
+
data.tar.gz: eb7b262ca50286d81bc86658e6e4f422ce19c9988e69cb6cbf9d52276d66adf0fb245575310b3ec6308959f59e0c7a9441a994857e24d0cb4a8431fae93b1ea0
|
data/Rakefile
ADDED
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
@@ -4,7 +4,6 @@ require 'watir'
|
|
4
4
|
|
5
5
|
# Chemlaboratory
|
6
6
|
module Chemlab
|
7
|
-
|
8
7
|
autoload :Version, 'chemlab/version'
|
9
8
|
|
10
9
|
# Yields the global configuration to a block.
|
@@ -14,19 +13,19 @@ module Chemlab
|
|
14
13
|
# Chemlab.configure do |config|
|
15
14
|
# config.base_url = 'https://example.com'
|
16
15
|
# end
|
17
|
-
def self.configure
|
18
|
-
yield configuration if block_given?
|
16
|
+
def self.configure(&block)
|
17
|
+
yield configuration(&block) if block_given?
|
19
18
|
end
|
20
19
|
|
21
|
-
# Returns the global [Configuration]
|
20
|
+
# Returns the global [Chemlab::Configuration] object. While
|
22
21
|
# you _can_ use this method to access the configuration, the more common
|
23
22
|
# convention is to use Chemlab.configure.
|
24
23
|
#
|
25
24
|
# @example
|
26
|
-
# Chemlab.configuration.
|
25
|
+
# Chemlab.configuration.something = 1234
|
27
26
|
# @see Chemlab.configure
|
28
|
-
def self.configuration
|
29
|
-
@configuration ||= Chemlab::Configuration.new
|
27
|
+
def self.configuration(&block)
|
28
|
+
@configuration ||= Chemlab::Configuration.new(&block)
|
30
29
|
end
|
31
30
|
|
32
31
|
autoload :Configuration, 'chemlab/configuration'
|
@@ -36,17 +35,16 @@ module Chemlab
|
|
36
35
|
autoload :Component, 'chemlab/component'
|
37
36
|
autoload :Page, 'chemlab/page'
|
38
37
|
|
39
|
-
autoload :ApiFabricator, 'chemlab/api_fabricator'
|
40
|
-
autoload :Resource, 'chemlab/resource'
|
41
|
-
|
42
38
|
# Runtime modules
|
43
39
|
module Runtime
|
44
40
|
autoload :Env, 'chemlab/runtime/env'
|
45
41
|
autoload :Browser, 'chemlab/runtime/browser'
|
42
|
+
autoload :Logger, 'chemlab/runtime/logger'
|
46
43
|
end
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
autoload :
|
45
|
+
module CLI
|
46
|
+
autoload :Generator, 'chemlab/cli/generator'
|
47
|
+
autoload :Stubber, 'chemlab/cli/stubber'
|
48
|
+
autoload :NewLibrary, 'chemlab/cli/new_library'
|
51
49
|
end
|
52
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 'active_support/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,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
<% modules = library.to_s.split('::') %>
|
4
|
+
<% root = (' ' * modules.size) %>
|
5
|
+
<% modules.each_with_index do |mod, indent| %>
|
6
|
+
<%= (' ' * indent) %><%= "module #{mod}\n" %>
|
7
|
+
<% end %>
|
8
|
+
<% library.public_elements.each do |element| %>
|
9
|
+
|
10
|
+
<% if Chemlab::Element::CLICKABLES.include?(element[:type]) %>
|
11
|
+
<%= root %># @note Defined as +<%= "#{element[:type]} :#{element[:name]}" %>+
|
12
|
+
<%= root %># Clicks +<%= element[:name] %>+
|
13
|
+
<%= root %>def <%= element[:name] %>
|
14
|
+
|
15
|
+
<%= root %> # This is a stub, used for indexing
|
16
|
+
<%= root %>end
|
17
|
+
|
18
|
+
<% else %>
|
19
|
+
<%= root %># @note Defined as +<%= "#{element[:type]} :#{element[:name]}" %>+
|
20
|
+
<%= root %># @return [String] The text content or value of +<%= element[:name] %>+
|
21
|
+
<%= root %>def <%= element[:name] %>
|
22
|
+
|
23
|
+
<%= root %> # This is a stub, used for indexing
|
24
|
+
<%= root %>end
|
25
|
+
|
26
|
+
<% end %>
|
27
|
+
|
28
|
+
<% if Chemlab::Element::INPUTS.include?(element[:type]) %>
|
29
|
+
<%= root %># Set the value of <%= element[:name] %>
|
30
|
+
|
31
|
+
<%= root %># @example
|
32
|
+
<%= root %># <%= library.to_s %>.perform do |<%= modules.last.underscore %>|
|
33
|
+
<%= root %># <%= modules.last.underscore %>.<%= element[:name] %> = 'value'
|
34
|
+
<%= root %># end
|
35
|
+
<%= root %># @param value [String] The value to set.
|
36
|
+
<%= root %>def <%= element[:name] %>=(value)
|
37
|
+
<%= root %> # This is a stub, used for indexing
|
38
|
+
<%= root %>end
|
39
|
+
<% end %>
|
40
|
+
|
41
|
+
<%= root %># @example
|
42
|
+
<%= root %># <%= library.to_s %>.perform do |<%= modules.last.underscore %>|
|
43
|
+
<%= root %># expect(<%= modules.last.underscore %>.<%= element[:name] %>_element).to exist
|
44
|
+
<%= root %># end
|
45
|
+
<%= root %># @return [Watir::<%= element[:type].to_s.classify %>] The raw +<%= element[:type].to_s.classify %>+ element
|
46
|
+
<%= root %>def <%= element[:name] %>_element
|
47
|
+
<%= root %> # This is a stub, used for indexing
|
48
|
+
<%= root %>end
|
49
|
+
|
50
|
+
<%= root %># @example
|
51
|
+
<%= root %># <%= library.to_s %>.perform do |<%= modules.last.underscore %>|
|
52
|
+
<%= root %># expect(<%= modules.last.underscore %>).to be_<%= element[:name] %>
|
53
|
+
|
54
|
+
<%= root %># end
|
55
|
+
<%= root %># @return [Boolean] true if the +<%= element[:name] %>+ element is present on the page
|
56
|
+
<%= root %>def <%= element[:name] %>?
|
57
|
+
<%= root %> # This is a stub, used for indexing
|
58
|
+
<%= root %>end
|
59
|
+
|
60
|
+
<% end %>
|
61
|
+
<% endings = [] %>
|
62
|
+
<% modules.size.times do |indent| %>
|
63
|
+
<% endings << "#{(' ' * indent)}end" %>
|
64
|
+
<% end %>
|
65
|
+
<%= endings.reverse.join("\n") %>
|