chemlab 0.2.1 → 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 +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 +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 +61 -13
  23. data/lib/chemlab/element.rb +5 -0
  24. data/lib/chemlab/page.rb +20 -2
  25. data/lib/chemlab/runtime/browser.rb +19 -25
  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 +68 -58
  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: f305b335e4ac4d9cb5a7b1f2612c96153e9cb906d1ad98e7be247558d81f7251
4
- data.tar.gz: eb673f9889acce43fe66ba1dfe814b4c9f90505af5f134c71c08a1f97ce8b928
3
+ metadata.gz: 915c01df3e022bd6da7158493e4da0cab8df087854f696ee048ab4ca6ed32d50
4
+ data.tar.gz: ff042d7a35caca43a932a3802ed765ba988b9f983f8a6ffe11905564876c674a
5
5
  SHA512:
6
- metadata.gz: b8fce1e263ecad19b51f441c3974a5198ad906ae5b87222b798c675f13da8fa60a84b33850754c3d87f84cc00bb397d3a4e265810e1f8279904a844b50997b9d
7
- data.tar.gz: ce4ab6bdd2e3aa714a81ed39ecc49dc12eb5219f8b35e1f7643f44ab95f293fbb5a96c19c3418f851b2a8a70c93fbcb324aa0f573b1639a91dfeaa2c53d02bf2
6
+ metadata.gz: 48967c413bc7c0f0650439c7c3d11aa3ef46cb5b0235d40bc80de82ae0b273838e4f35b8c3f2a4f8a5335307904f6447ffaec16607ce8f59cd31881b01461bb9
7
+ data.tar.gz: eb7b262ca50286d81bc86658e6e4f422ce19c9988e69cb6cbf9d52276d66adf0fb245575310b3ec6308959f59e0c7a9441a994857e24d0cb4a8431fae93b1ea0
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # enable metadata. this is required for --help
4
+ Rake::TaskManager.record_task_metadata = true
5
+
6
+ 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,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") %>