topoisomerase 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: 824fa18b24c188d39f2e84ee5eec61098f0bdab0
4
- data.tar.gz: 7c7c69f744f18fd88d4b6c9952cbf99bcf26e8d4
3
+ metadata.gz: 3d6fbc0409b85e6fee55102846a9ac377c227aa6
4
+ data.tar.gz: 544470dcb10e26a5575207c38bbeb1e17b955976
5
5
  SHA512:
6
- metadata.gz: 6516b42b5be7580f4aa35b098ccc789fb47b5a9359f46b62626eec4257e408266c27c66f9dfd60b5b381a7c5e9356283b09cb8f3ba58c6f49008537dbffbe91c
7
- data.tar.gz: cccfb7c414f0a4a0bd08548cd9939fff6d828fadc520653aa625b1769f5569a0851e3d3c358cf12c25241a5f4a5bdd96da2521858868518749b64300130a232f
6
+ metadata.gz: 6a2499fe4dd9e2ebb2d406edd7781e325c83f35b1c9e360f7bbd6bcf79c06f6c2654192a853f2a919f31129c4da5265bdabe258abf181d63e307af745fed9fa4
7
+ data.tar.gz: dbb63522e85182c36dd0f79ff7bc40439348eb81dd35ea4ddd6c7b08362facb41a8caf2b02a97e0527561f2fbc34bd8f3689eee7cd71e10a10a0f1091b3eb30a
data/README.md CHANGED
@@ -34,6 +34,11 @@ Or install it yourself as:
34
34
 
35
35
  ## Usage
36
36
 
37
+ ### For one class
38
+
39
+ Before creating stubs, make sure that you require all the files that you want to create stubs for.
40
+ Otherwise it will not create stubs for anything.
41
+
37
42
  To create a stub file for a class, call the `create_stubs_for` passing that class.
38
43
 
39
44
  E.g:
@@ -58,6 +63,44 @@ Topoisomerase.create_stubs_for ParameterizedClass do
58
63
  end
59
64
  ```
60
65
 
66
+ ### For classes inheriting from another
67
+
68
+ To create stubs for all classes inheriting from a class or module use the `create_stubs_based_on` method.
69
+ If the instantiation of such objects require parameters pass a parameter in the block to represent each class
70
+ that is found inheriting from the base class.
71
+
72
+ Eg:
73
+
74
+ ```ruby
75
+ Topoisomerase.create_stubs_based_on PageObject do |inheriting_class|
76
+ inheriting_class.new(:config_1, 'config 2')
77
+ end
78
+ ```
79
+
80
+ ### Comments
81
+
82
+ If comments are used above a `define_method` method then they will be used as comments above the stub generated from it
83
+ by default.
84
+
85
+ Otherwise the `Topoisomerase::Comments` class can be used. The following shows hows to add comments when generating stubs
86
+ for all classes inheriting from / including the `PageObject` module. It adds
87
+
88
+ Eg:
89
+
90
+ ```ruby
91
+ #
92
+ Topoisomerase::Comments.add_for_class PageObject do
93
+ comment "Set the '<%= method_to_stub.to_s.gsub('?', '') %>' text field",
94
+ method_name: /=$/, source: /text_field_value_set/
95
+ end
96
+ ```
97
+
98
+ ### Notes
99
+
100
+ For efficiency and maintainability, it's recommended that the least needed to instantiate the class that will still
101
+ generate the methods you need be used. However it may be just as easy to reuse the code you use when creating the objects
102
+ themselves if it is generic enough.
103
+
61
104
  ## Development
62
105
 
63
106
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
File without changes
@@ -1,4 +1,4 @@
1
1
  module Topoisomerase
2
2
  # @return [String] Version of the gem
3
- VERSION = '0.1.2'.freeze
3
+ VERSION = '0.1.3'.freeze
4
4
  end
data/lib/topoisomerase.rb CHANGED
@@ -2,7 +2,7 @@ require 'topoisomerase/version'
2
2
  require 'method_source'
3
3
  require 'fileutils'
4
4
  require 'topoisomerase/core_ext/string'
5
- require 'topoisomerase/comment_adder'
5
+ require 'topoisomerase/comments'
6
6
 
7
7
  # Module for parsing and creating stubs for dynamic methods
8
8
  module Topoisomerase
@@ -54,7 +54,7 @@ module Topoisomerase
54
54
  method_data[:comment].strip.empty? ? '' : "Extracted comment #{method_data[:comment].strip}"
55
55
  end
56
56
 
57
- # @return [Boolean]
57
+ # @return [Boolean] Whether there is a match based on value and matcher
58
58
  def match?(value_to_test, matcher_value)
59
59
  value_to_test = value_to_test.to_s
60
60
  case matcher_value
@@ -70,6 +70,7 @@ module Topoisomerase
70
70
  def comment_for(method_to_stub, method_data)
71
71
  return extracted_comment(method_data) unless comments_added[@inheriting_class]
72
72
 
73
+ method_to_stub = method_to_stub.to_s
73
74
  comments_added[@inheriting_class].each do |comment_matcher|
74
75
  matchers = comment_matcher[:matchers]
75
76
  return ERB.new(comment_matcher[:message]).result(binding) if matchers.all? do |matcher_type, matcher_value|
@@ -90,19 +91,17 @@ module Topoisomerase
90
91
  def create_stubs_for(class_name, inner_folder = nil)
91
92
  template = File.join(File.dirname(__FILE__), 'topoisomerase', 'stub_template.rb.erb')
92
93
  @class_name = class_name
93
- @class_instance = if block_given?
94
- yield
95
- else
96
- class_name.new
97
- end
94
+ @class_instance = block_given? ? yield(class_name) : class_name.new
98
95
  @dynamic_methods = dynamic_instance_methods(class_name) do
99
96
  @class_instance
100
97
  end
101
98
  class_folder = inner_folder ? File.join(stub_folder, inner_folder) : stub_folder
102
- FileUtils.mkdir_p class_folder
103
99
  filename = File.join(class_folder, "#{class_name.to_s.snakecase}.rb")
100
+ puts "Creating stubs for #{class_name} at #{filename}"
101
+ FileUtils.mkdir_p File.dirname(filename)
104
102
  IO.write filename, ERB.new(File.read(template)).result(binding)
105
- `rubocop -a #{filename}`
103
+ require 'rubocop'
104
+ RuboCop::CLI.new.run(['-a', filename, '-f', 'q', '-o', 'stub_log'])
106
105
  end
107
106
 
108
107
  # Create stub files for each class that inherits from passed in class
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: topoisomerase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Garratt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-15 00:00:00.000000000 Z
11
+ date: 2019-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source
@@ -144,7 +144,7 @@ files:
144
144
  - bin/setup
145
145
  - exe/topoisomerase
146
146
  - lib/topoisomerase.rb
147
- - lib/topoisomerase/comment_adder.rb
147
+ - lib/topoisomerase/comments.rb
148
148
  - lib/topoisomerase/core_ext/string.rb
149
149
  - lib/topoisomerase/stub_template.rb.erb
150
150
  - lib/topoisomerase/template/page_object.rb