zapata 0.1.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +7 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +35 -0
  5. data/.travis.yml +13 -19
  6. data/Appraisals +11 -0
  7. data/Gemfile +2 -0
  8. data/README.md +1 -2
  9. data/Rakefile +2 -1
  10. data/bin/zapata +6 -29
  11. data/gemfiles/5.2.gemfile +14 -0
  12. data/gemfiles/6.0.gemfile +14 -0
  13. data/lib/zapata.rb +22 -22
  14. data/lib/zapata/analyst.rb +2 -0
  15. data/lib/zapata/cli.rb +23 -0
  16. data/lib/zapata/core.rb +11 -0
  17. data/lib/zapata/core/collector.rb +2 -0
  18. data/lib/zapata/core/loader.rb +6 -4
  19. data/lib/zapata/core/reader.rb +2 -0
  20. data/lib/zapata/core/writer.rb +2 -0
  21. data/lib/zapata/db.rb +2 -0
  22. data/lib/zapata/diver.rb +32 -28
  23. data/lib/zapata/predictor.rb +10 -0
  24. data/lib/zapata/predictor/args.rb +2 -0
  25. data/lib/zapata/predictor/chooser.rb +2 -0
  26. data/lib/zapata/predictor/value.rb +7 -3
  27. data/lib/zapata/primitive.rb +28 -0
  28. data/lib/zapata/primitive/arg.rb +2 -0
  29. data/lib/zapata/primitive/array.rb +2 -0
  30. data/lib/zapata/primitive/base.rb +6 -4
  31. data/lib/zapata/primitive/basic.rb +2 -0
  32. data/lib/zapata/primitive/casgn.rb +2 -0
  33. data/lib/zapata/primitive/const.rb +2 -0
  34. data/lib/zapata/primitive/const_send.rb +2 -0
  35. data/lib/zapata/primitive/def.rb +2 -0
  36. data/lib/zapata/primitive/defs.rb +3 -1
  37. data/lib/zapata/primitive/hash.rb +2 -0
  38. data/lib/zapata/primitive/ivar.rb +2 -0
  39. data/lib/zapata/primitive/klass.rb +4 -2
  40. data/lib/zapata/primitive/lvar.rb +2 -0
  41. data/lib/zapata/primitive/missing.rb +2 -0
  42. data/lib/zapata/primitive/modul.rb +2 -0
  43. data/lib/zapata/primitive/nil.rb +2 -0
  44. data/lib/zapata/primitive/optarg.rb +2 -0
  45. data/lib/zapata/primitive/raw.rb +2 -0
  46. data/lib/zapata/primitive/send.rb +4 -1
  47. data/lib/zapata/primitive/sklass.rb +3 -1
  48. data/lib/zapata/primitive/var.rb +2 -0
  49. data/lib/zapata/printer.rb +2 -1
  50. data/lib/zapata/rzpec/runner.rb +3 -1
  51. data/lib/zapata/rzpec/writer.rb +5 -3
  52. data/lib/zapata/version.rb +3 -1
  53. data/spec/array_spec.rb +6 -6
  54. data/spec/definition_spec.rb +5 -5
  55. data/spec/generation_spec.rb +2 -36
  56. data/spec/hash_spec.rb +8 -8
  57. data/spec/klass_types_spec.rb +6 -6
  58. data/spec/send_spec.rb +6 -6
  59. data/spec/simple_types_spec.rb +6 -6
  60. data/spec/spec_helper.rb +18 -76
  61. data/spec/support/rails_test_app/app/assets/config/manifest.js +3 -0
  62. data/spec/support/rails_test_app/app/models/robot_to_test.rb +4 -4
  63. data/spec/support/rails_test_app/app/models/test_send.rb +1 -1
  64. data/spec/support/rails_test_app/config.ru +1 -1
  65. data/spec/support/rails_test_app/config/initializers/cookies_serializer.rb +1 -1
  66. data/spec/support/rails_test_app/spec/models/robot_to_test_spec.rb +2 -2
  67. data/spec/support/rails_test_app/spec/models/test_hash_spec.rb +1 -1
  68. data/spec/support/rails_test_app/spec/rails_helper.rb +3 -3
  69. data/spec/support/rails_test_app/spec/spec_helper.rb +58 -60
  70. data/zapata.gemspec +18 -18
  71. metadata +58 -101
  72. data/spec/support/rails_test_app/.gitignore +0 -16
  73. data/spec/support/rails_test_app/.rspec +0 -3
  74. data/spec/support/rails_test_app/Gemfile +0 -49
  75. data/spec/support/rails_test_app/test/controllers/.keep +0 -0
  76. data/spec/support/rails_test_app/test/fixtures/.keep +0 -0
  77. data/spec/support/rails_test_app/test/helpers/.keep +0 -0
  78. data/spec/support/rails_test_app/test/integration/.keep +0 -0
  79. data/spec/support/rails_test_app/test/mailers/.keep +0 -0
  80. data/spec/support/rails_test_app/test/models/.keep +0 -0
  81. data/spec/support/rails_test_app/test/test_helper.rb +0 -13
  82. data/spec/support/rails_test_app/vendor/assets/javascripts/.keep +0 -0
  83. data/spec/support/rails_test_app/vendor/assets/stylesheets/.keep +0 -0
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'predictor/args'
4
+ require_relative 'predictor/chooser'
5
+ require_relative 'predictor/value'
6
+
7
+ module Zapata
8
+ module Predictor
9
+ end
10
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Predictor
3
5
  class Args
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Predictor
3
5
  class Chooser
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Predictor
3
5
  class Value
@@ -10,19 +12,21 @@ module Zapata
10
12
 
11
13
  def choose
12
14
  return Primitive::Raw.new(:nil, nil) if @name.nil?
13
- return @finder if @finder and FINAL_TYPES.include?(@finder.type)
15
+ return @finder if @finder && FINAL_TYPES.include?(@finder.type)
14
16
  return Primitive::Raw.new(:super, @name) if possible_values.empty?
17
+
15
18
  Chooser.new(possible_values).by_probability
16
19
  end
17
20
 
18
21
  def a_finder?(primitive)
19
22
  return false unless @finder
20
- primitive.class == @finder.class and primitive.name == @finder.name
23
+
24
+ primitive.class == @finder.class && primitive.name == @finder.name
21
25
  end
22
26
 
23
27
  def possible_values
24
28
  Revolutionist.analysis_as_array.select do |element|
25
- !a_finder?(element) and element.name == @name
29
+ !a_finder?(element) && element.name == @name
26
30
  end
27
31
  end
28
32
  memoize :possible_values
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'primitive/base'
4
+ require_relative 'primitive/arg'
5
+ require_relative 'primitive/array'
6
+ require_relative 'primitive/basic'
7
+ require_relative 'primitive/casgn'
8
+ require_relative 'primitive/const'
9
+ require_relative 'primitive/const_send'
10
+ require_relative 'primitive/def'
11
+ require_relative 'primitive/defs'
12
+ require_relative 'primitive/hash'
13
+ require_relative 'primitive/ivar'
14
+ require_relative 'primitive/klass'
15
+ require_relative 'primitive/lvar'
16
+ require_relative 'primitive/missing'
17
+ require_relative 'primitive/modul'
18
+ require_relative 'primitive/nil'
19
+ require_relative 'primitive/optarg'
20
+ require_relative 'primitive/raw'
21
+ require_relative 'primitive/send'
22
+ require_relative 'primitive/sklass'
23
+ require_relative 'primitive/var'
24
+
25
+ module Zapata
26
+ module Primitive
27
+ end
28
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Arg < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Array < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Base
@@ -13,10 +15,10 @@ module Zapata
13
15
  end
14
16
 
15
17
  def dive_deeper
16
- unless RETURN_TYPES.include?(node.type)
17
- Diver.dive(node.args)
18
- Diver.dive(node.body)
19
- end
18
+ return if RETURN_TYPES.include?(node.type)
19
+
20
+ Diver.dive(node.args)
21
+ Diver.dive(node.body)
20
22
  end
21
23
 
22
24
  def to_raw
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Basic < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Casgn < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Const < Basic
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class ConstSend
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Def < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Defs < Base
@@ -19,7 +21,7 @@ module Zapata
19
21
  end
20
22
 
21
23
  def node
22
- receiver, name, args, body = @code.to_a
24
+ _, name, args, body = @code.to_a
23
25
  type = @code.type
24
26
  OpenStruct.new(type: type, name: name, args: args, body: body)
25
27
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Hash < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Ivar < Basic
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Klass < Base
@@ -11,11 +13,11 @@ module Zapata
11
13
  end
12
14
 
13
15
  def parent_modul_names
14
- @moduls.map { |mod| mod and mod.name }.compact
16
+ @moduls.map { |mod| mod&.name }.compact
15
17
  end
16
18
 
17
19
  def node
18
- const, inherited_from_klass, body = @code.to_a
20
+ const, _, body = @code.to_a
19
21
  immediate_modul, klass = const.to_a
20
22
  chain = parent_modul_names + [immediate_modul, klass]
21
23
  name = chain.compact.join('::')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Lvar < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Missing
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Modul < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Nil < Basic
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Optarg < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Raw
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Send < Base
@@ -25,11 +27,12 @@ module Zapata
25
27
 
26
28
  def raw_receiver
27
29
  return unless node.receiver
30
+
28
31
  Diver.dive(node.receiver).to_raw
29
32
  end
30
33
 
31
34
  def to_raw
32
- if raw_receiver and raw_receiver.type == :const
35
+ if raw_receiver && raw_receiver.type == :const
33
36
  ConstSend.new(raw_receiver, node.name, node.args).to_raw
34
37
  else
35
38
  missing_name = if node.receiver
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Sklass < Base
@@ -10,7 +12,7 @@ module Zapata
10
12
  end
11
13
 
12
14
  def node
13
- receiver_self, body = @code.to_a
15
+ _, body = @code.to_a
14
16
  type = @code.type
15
17
 
16
18
  OpenStruct.new(type: type, body: body)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Primitive
3
5
  class Var < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  class Printer
3
5
  class << self
@@ -86,7 +88,6 @@ module Zapata
86
88
  values = unnested.map do |key, val|
87
89
  print_hash_pair(key, val, all_keys_symbols?(unnested))
88
90
  end
89
-
90
91
  "{ #{values.join(', ')} }"
91
92
  end
92
93
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module RZpec
3
5
  class Runner
@@ -43,7 +45,7 @@ module Zapata
43
45
  Printer.print(Diver.dive(Parser::CurrentRuby.parse(clean_expected_line)).to_raw)
44
46
  end
45
47
  else
46
- "'Exception in RSpec'"
48
+ "'Exception in RSpec'"
47
49
  end
48
50
  end
49
51
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module RZpec
3
5
  class Writer
@@ -9,7 +11,7 @@ module Zapata
9
11
  end
10
12
  end
11
13
 
12
- def initialize(file, code, subject_analysis, whole_analysis, spec_analysis = nil)
14
+ def initialize(file, _code, subject_analysis, whole_analysis, spec_analysis = nil)
13
15
  self.class.reset_ivars
14
16
  @subject_analysis = subject_analysis
15
17
  @whole_analysis = whole_analysis
@@ -36,8 +38,8 @@ module Zapata
36
38
 
37
39
  def klass_defs(klass)
38
40
  @subject_analysis.select do |method|
39
- [Primitive::Def, Primitive::Defs].include?(method.class) and
40
- method.public? and method.klass.name == klass.name
41
+ [Primitive::Def, Primitive::Defs].include?(method.class) &&
42
+ method.public? && method.klass.name == klass.name
41
43
  end
42
44
  end
43
45
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
- VERSION = '0.1.6'
4
+ VERSION = '1.0.0'
3
5
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe Zapata::Revolutionist do
4
4
  before(:all) do
@@ -6,31 +6,31 @@ describe Zapata::Revolutionist do
6
6
  end
7
7
 
8
8
  it '#test_in_arg' do
9
- has_block('#test_in_arg', %Q{
9
+ has_block('#test_in_arg', %{
10
10
  expect(test_array.test_in_arg([2, 7.1, 8])).to eq([2, 7.1, 8])
11
11
  })
12
12
  end
13
13
 
14
14
  it '#test_nested_one_level' do
15
- has_block('#test_nested_one_level', %Q{
15
+ has_block('#test_nested_one_level', %{
16
16
  expect(test_array.test_nested_one_level([[2, 7.1, 8], :mexico])).to eq([[2, 7.1, 8], :mexico])
17
17
  })
18
18
  end
19
19
 
20
20
  it '#test_nested_two_levels' do
21
- has_block('#test_nested_two_levels', %Q{
21
+ has_block('#test_nested_two_levels', %{
22
22
  expect(test_array.test_nested_two_levels([[[2, 7.1, 8], :mexico], [2, 7.1, 8], :mexico])).to eq([[[2, 7.1, 8], :mexico], [2, 7.1, 8], :mexico])
23
23
  })
24
24
  end
25
25
 
26
26
  it '#test_nested_three_levels' do
27
- has_block('#test_nested_three_levels', %Q{
27
+ has_block('#test_nested_three_levels', %{
28
28
  expect(test_array.test_nested_three_levels([[[[2, 7.1, 8], :mexico], [2, 7.1, 8], :mexico], [[2, 7.1, 8], :mexico], [2, 7.1, 8], :mexico])).to eq([[[[2, 7.1, 8], :mexico], [2, 7.1, 8], :mexico], [[2, 7.1, 8], :mexico], [2, 7.1, 8], :mexico])
29
29
  })
30
30
  end
31
31
 
32
32
  it '#test_hash_nested' do
33
- has_block('#test_hash_nested', %Q{
33
+ has_block('#test_hash_nested', %{
34
34
  expect(test_array.test_hash_nested([{ emiliano: [2, 7.1, 8] }])).to eq([{ emiliano: [2, 7.1, 8] }])
35
35
  })
36
36
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe Zapata::Revolutionist do
4
4
  before(:all) do
@@ -6,13 +6,13 @@ describe Zapata::Revolutionist do
6
6
  end
7
7
 
8
8
  it '#in_optional_args' do
9
- has_block('#in_optional_args', %Q{
9
+ has_block('#in_optional_args', %{
10
10
  expect(test_definition.in_optional_args(:audioslave)).to eq(:audioslave)
11
11
  })
12
12
  end
13
13
 
14
14
  it '#use_optional' do
15
- has_block('#use_optional', %Q{
15
+ has_block('#use_optional', %{
16
16
  expect(test_definition.use_optional(:audioslave)).to eq(:audioslave)
17
17
  })
18
18
  end
@@ -30,13 +30,13 @@ describe Zapata::Revolutionist do
30
30
  # end
31
31
 
32
32
  it '#call_method_result_in_optional_args' do
33
- has_block('#call_method_result_in_optional_args', %Q{
33
+ has_block('#call_method_result_in_optional_args', %{
34
34
  expect(test_definition.call_method_result_in_optional_args('Missing "fall_meth.first"')).to eq('Missing "fall_meth.first"')
35
35
  })
36
36
  end
37
37
 
38
38
  it '#resursive_method' do
39
- has_block('#recursive_method', %Q{
39
+ has_block('#recursive_method', %{
40
40
  expect(test_definition.recursive_method).to eq('Exception in RSpec')
41
41
  })
42
42
  end
@@ -1,10 +1,10 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe Zapata::Revolutionist do
4
4
  describe '#generate_with_friendly_output' do
5
5
  let(:file_name) { 'app/models/test_array.rb' }
6
6
 
7
- context "with the generate command" do
7
+ context 'with the generate command' do
8
8
  context 'with single specified' do
9
9
  it 'returns a single file generation message' do
10
10
  output = execution_output("cd #{RAILS_TEST_APP_DIR} && bundle exec zapata generate #{file_name} -s")
@@ -20,39 +20,5 @@ describe Zapata::Revolutionist do
20
20
  end
21
21
  end
22
22
  end
23
-
24
- context "without the generate command" do
25
- context 'with single (-s) specified' do
26
- it 'returns a single file generation message' do
27
- output = execution_output("cd #{RAILS_TEST_APP_DIR} && bundle exec zapata #{file_name} -s")
28
- expect(output.count).to eq 1
29
- expect(output.first).to eq "Its done, comrades. File spec/models/test_array_spec.rb was generated.\n"
30
- end
31
- end
32
-
33
- context 'with single (--single) specified' do
34
- it 'returns a single file generation message' do
35
- output = execution_output("cd #{RAILS_TEST_APP_DIR} && bundle exec zapata #{file_name} --single")
36
- expect(output.count).to eq 1
37
- expect(output.first).to eq "Its done, comrades. File spec/models/test_array_spec.rb was generated.\n"
38
- end
39
- end
40
-
41
- context 'with no single specified' do
42
- it 'returns multiple file generation messages' do
43
- output = execution_output("cd #{RAILS_TEST_APP_DIR} && bundle exec zapata #{file_name}")
44
- expect(output.count).to be > 1
45
- end
46
- end
47
- end
48
-
49
- def execution_output(command)
50
- stdout = Bundler.with_clean_env do
51
- Open3.pipeline_r(
52
- command
53
- )
54
- end
55
- stdout.first.readlines
56
- end
57
23
  end
58
24
  end