chemlab 0.4.0 → 0.7.1

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 +8 -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 +27 -17
  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 +66 -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 -18
  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 +113 -57
  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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07bc21e85bd30535258248b34722848feed23de49fea1217442efa6f5fe86f9b
4
- data.tar.gz: d38fbd55e058dfdc124d3d497fc45928bdea73c3eceaaf7f81c7330f18d793bb
3
+ metadata.gz: b5adc75f1131d78970aa177e504bd9054b1bf07aab8c7bb2cbf0056fb81fa889
4
+ data.tar.gz: e1089e0141e142684cb6eac2dfac48a4383cd043d32902362f7c26b45c8b52a3
5
5
  SHA512:
6
- metadata.gz: 2f621b4f87dbf07474a77fb2ad309b9cfbbb34cc9f1e5158bfc343d58e3005d5612ee38f8877410c444c44280031f2bb67a2516d078c08e22071a16f726dd1a1
7
- data.tar.gz: e837e155b3743c861e238de0da9f3306a5a2222c6df73d4fdb3d7655626ca05c2cefd89f8db5433023c8a65f2df3378190818aef1bee9d63564e7f6b4369a811
6
+ metadata.gz: bdcad6b56b68d707a83cf9d932eb290d272e48b2c67c24ee0c5f2e4fe2e158b3bff80268652780d344da0e4b7f922634549b9a02601a19adcc0c73c1019913ab
7
+ data.tar.gz: f0856ad93ae0b5f18f9b0590f1ba897418d9e0ba2557da225fcea29f448c868d528eb4e04b5d09753a3f7572a859711aaf1ad59bc3344665637703ebf7b3fd78
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
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rake'
5
+
6
+ Rake.load_rakefile(File.expand_path('../Rakefile', __dir__))
7
+
8
+ task = ARGV.shift
9
+
10
+ Rake::Task[task].execute(ARGV)
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](Configuration) object. While
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.drb_port = 1234
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
@@ -7,18 +7,24 @@ module Chemlab
7
7
  # include Attributable
8
8
  # attribute :url
9
9
  # attribute :id
10
- # attribute :name { 'test' }
10
+ # attribute :name do
11
+ # 'test'
12
+ # end
11
13
  module Attributable
12
- def attribute(name)
13
- default_value = nil
14
- default_value = yield if block_given?
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
- define_method(name) do
17
- instance_variable_get("@#{name}") ||
18
- instance_variable_set(
19
- "@#{name}",
20
- default_value
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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1 @@
1
+ # <%= library[:name] %> Library for Chemlab
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= library[:classified_name] %>
4
+ module Page
5
+ autoload :Sample, 'page/sample'
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= library[:classified_name] %>
4
+ module Page
5
+ class Sample < Chemlab::Page
6
+ path '/sample'
7
+ end
8
+ end
9
+ end
@@ -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,3 @@
1
+ class <%= name %> < Chemlab::Page
2
+ <%= props = +''; data.each_key { |k| props << " #{k} '#{data[k]}'\n" }; props %>
3
+ 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,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") %>