zapata 0.1.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/.rubocop.yml +35 -0
- data/.travis.yml +13 -19
- data/Appraisals +11 -0
- data/Gemfile +2 -0
- data/README.md +1 -2
- data/Rakefile +2 -1
- data/bin/zapata +6 -29
- data/gemfiles/5.2.gemfile +14 -0
- data/gemfiles/6.0.gemfile +14 -0
- data/lib/zapata.rb +22 -22
- data/lib/zapata/analyst.rb +2 -0
- data/lib/zapata/cli.rb +23 -0
- data/lib/zapata/core.rb +11 -0
- data/lib/zapata/core/collector.rb +2 -0
- data/lib/zapata/core/loader.rb +6 -4
- data/lib/zapata/core/reader.rb +2 -0
- data/lib/zapata/core/writer.rb +2 -0
- data/lib/zapata/db.rb +2 -0
- data/lib/zapata/diver.rb +32 -28
- data/lib/zapata/predictor.rb +10 -0
- data/lib/zapata/predictor/args.rb +2 -0
- data/lib/zapata/predictor/chooser.rb +2 -0
- data/lib/zapata/predictor/value.rb +7 -3
- data/lib/zapata/primitive.rb +28 -0
- data/lib/zapata/primitive/arg.rb +2 -0
- data/lib/zapata/primitive/array.rb +2 -0
- data/lib/zapata/primitive/base.rb +6 -4
- data/lib/zapata/primitive/basic.rb +2 -0
- data/lib/zapata/primitive/casgn.rb +2 -0
- data/lib/zapata/primitive/const.rb +2 -0
- data/lib/zapata/primitive/const_send.rb +2 -0
- data/lib/zapata/primitive/def.rb +2 -0
- data/lib/zapata/primitive/defs.rb +3 -1
- data/lib/zapata/primitive/hash.rb +2 -0
- data/lib/zapata/primitive/ivar.rb +2 -0
- data/lib/zapata/primitive/klass.rb +4 -2
- data/lib/zapata/primitive/lvar.rb +2 -0
- data/lib/zapata/primitive/missing.rb +2 -0
- data/lib/zapata/primitive/modul.rb +2 -0
- data/lib/zapata/primitive/nil.rb +2 -0
- data/lib/zapata/primitive/optarg.rb +2 -0
- data/lib/zapata/primitive/raw.rb +2 -0
- data/lib/zapata/primitive/send.rb +4 -1
- data/lib/zapata/primitive/sklass.rb +3 -1
- data/lib/zapata/primitive/var.rb +2 -0
- data/lib/zapata/printer.rb +2 -1
- data/lib/zapata/rzpec/runner.rb +3 -1
- data/lib/zapata/rzpec/writer.rb +5 -3
- data/lib/zapata/version.rb +3 -1
- data/spec/array_spec.rb +6 -6
- data/spec/definition_spec.rb +5 -5
- data/spec/generation_spec.rb +2 -36
- data/spec/hash_spec.rb +8 -8
- data/spec/klass_types_spec.rb +6 -6
- data/spec/send_spec.rb +6 -6
- data/spec/simple_types_spec.rb +6 -6
- data/spec/spec_helper.rb +18 -76
- data/spec/support/rails_test_app/app/assets/config/manifest.js +3 -0
- data/spec/support/rails_test_app/app/models/robot_to_test.rb +4 -4
- data/spec/support/rails_test_app/app/models/test_send.rb +1 -1
- data/spec/support/rails_test_app/config.ru +1 -1
- data/spec/support/rails_test_app/config/initializers/cookies_serializer.rb +1 -1
- data/spec/support/rails_test_app/spec/models/robot_to_test_spec.rb +2 -2
- data/spec/support/rails_test_app/spec/models/test_hash_spec.rb +1 -1
- data/spec/support/rails_test_app/spec/rails_helper.rb +3 -3
- data/spec/support/rails_test_app/spec/spec_helper.rb +58 -60
- data/zapata.gemspec +18 -18
- metadata +58 -101
- data/spec/support/rails_test_app/.gitignore +0 -16
- data/spec/support/rails_test_app/.rspec +0 -3
- data/spec/support/rails_test_app/Gemfile +0 -49
- data/spec/support/rails_test_app/test/controllers/.keep +0 -0
- data/spec/support/rails_test_app/test/fixtures/.keep +0 -0
- data/spec/support/rails_test_app/test/helpers/.keep +0 -0
- data/spec/support/rails_test_app/test/integration/.keep +0 -0
- data/spec/support/rails_test_app/test/mailers/.keep +0 -0
- data/spec/support/rails_test_app/test/models/.keep +0 -0
- data/spec/support/rails_test_app/test/test_helper.rb +0 -13
- data/spec/support/rails_test_app/vendor/assets/javascripts/.keep +0 -0
- data/spec/support/rails_test_app/vendor/assets/stylesheets/.keep +0 -0
@@ -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
|
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
|
-
|
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)
|
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
|
data/lib/zapata/primitive/arg.rb
CHANGED
@@ -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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
data/lib/zapata/primitive/def.rb
CHANGED
@@ -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
|
-
|
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 Klass < Base
|
@@ -11,11 +13,11 @@ module Zapata
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def parent_modul_names
|
14
|
-
@moduls.map { |mod| mod
|
16
|
+
@moduls.map { |mod| mod&.name }.compact
|
15
17
|
end
|
16
18
|
|
17
19
|
def node
|
18
|
-
const,
|
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('::')
|
data/lib/zapata/primitive/nil.rb
CHANGED
data/lib/zapata/primitive/raw.rb
CHANGED
@@ -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
|
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
|
-
|
15
|
+
_, body = @code.to_a
|
14
16
|
type = @code.type
|
15
17
|
|
16
18
|
OpenStruct.new(type: type, body: body)
|
data/lib/zapata/primitive/var.rb
CHANGED
data/lib/zapata/printer.rb
CHANGED
@@ -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
|
|
data/lib/zapata/rzpec/runner.rb
CHANGED
@@ -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
|
-
|
48
|
+
"'Exception in RSpec'"
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
data/lib/zapata/rzpec/writer.rb
CHANGED
@@ -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,
|
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)
|
40
|
-
method.public?
|
41
|
+
[Primitive::Def, Primitive::Defs].include?(method.class) &&
|
42
|
+
method.public? && method.klass.name == klass.name
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
data/lib/zapata/version.rb
CHANGED
data/spec/array_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
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', %
|
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', %
|
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', %
|
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', %
|
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', %
|
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
|
data/spec/definition_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
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', %
|
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', %
|
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', %
|
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', %
|
39
|
+
has_block('#recursive_method', %{
|
40
40
|
expect(test_definition.recursive_method).to eq('Exception in RSpec')
|
41
41
|
})
|
42
42
|
end
|
data/spec/generation_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
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
|
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
|