zapata 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/CONTRIBUTING.md +5 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +152 -0
- data/Rakefile +2 -0
- data/bin/zapata +20 -0
- data/lib/zapata.rb +91 -0
- data/lib/zapata/analyst.rb +34 -0
- data/lib/zapata/core/collector.rb +9 -0
- data/lib/zapata/core/loader.rb +38 -0
- data/lib/zapata/core/reader.rb +10 -0
- data/lib/zapata/core/writer.rb +33 -0
- data/lib/zapata/db.rb +32 -0
- data/lib/zapata/diver.rb +81 -0
- data/lib/zapata/predictor/args.rb +94 -0
- data/lib/zapata/predictor/chooser.rb +27 -0
- data/lib/zapata/primitive/arg.rb +24 -0
- data/lib/zapata/primitive/array.rb +39 -0
- data/lib/zapata/primitive/base.rb +28 -0
- data/lib/zapata/primitive/basic.rb +22 -0
- data/lib/zapata/primitive/casgn.rb +15 -0
- data/lib/zapata/primitive/const.rb +15 -0
- data/lib/zapata/primitive/def.rb +33 -0
- data/lib/zapata/primitive/defs.rb +32 -0
- data/lib/zapata/primitive/hash.rb +31 -0
- data/lib/zapata/primitive/ivar.rb +6 -0
- data/lib/zapata/primitive/klass.rb +34 -0
- data/lib/zapata/primitive/lvar.rb +24 -0
- data/lib/zapata/primitive/missing.rb +17 -0
- data/lib/zapata/primitive/modul.rb +20 -0
- data/lib/zapata/primitive/nil.rb +16 -0
- data/lib/zapata/primitive/optarg.rb +18 -0
- data/lib/zapata/primitive/raw.rb +16 -0
- data/lib/zapata/primitive/send.rb +48 -0
- data/lib/zapata/primitive/sklass.rb +20 -0
- data/lib/zapata/primitive/var.rb +25 -0
- data/lib/zapata/printer.rb +93 -0
- data/lib/zapata/rzpec/runner.rb +67 -0
- data/lib/zapata/rzpec/writer.rb +115 -0
- data/lib/zapata/version.rb +3 -0
- data/spec/array_spec.rb +37 -0
- data/spec/definition_spec.rb +43 -0
- data/spec/hash_spec.rb +43 -0
- data/spec/klass_types_spec.rb +55 -0
- data/spec/send_spec.rb +31 -0
- data/spec/simple_types_spec.rb +90 -0
- data/spec/spec_helper.rb +124 -0
- data/spec/support/rails_test_app/.gitignore +16 -0
- data/spec/support/rails_test_app/.rspec +3 -0
- data/spec/support/rails_test_app/Gemfile +45 -0
- data/spec/support/rails_test_app/Gemfile.lock +200 -0
- data/spec/support/rails_test_app/README.md +3 -0
- data/spec/support/rails_test_app/Rakefile +6 -0
- data/spec/support/rails_test_app/app/assets/images/.keep +0 -0
- data/spec/support/rails_test_app/app/assets/javascripts/application.js +16 -0
- data/spec/support/rails_test_app/app/assets/stylesheets/application.css +15 -0
- data/spec/support/rails_test_app/app/controllers/application_controller.rb +5 -0
- data/spec/support/rails_test_app/app/controllers/concerns/.keep +0 -0
- data/spec/support/rails_test_app/app/helpers/application_helper.rb +2 -0
- data/spec/support/rails_test_app/app/mailers/.keep +0 -0
- data/spec/support/rails_test_app/app/models/.keep +0 -0
- data/spec/support/rails_test_app/app/models/concerns/.keep +0 -0
- data/spec/support/rails_test_app/app/models/robot_to_test.rb +49 -0
- data/spec/support/rails_test_app/app/models/test_array.rb +34 -0
- data/spec/support/rails_test_app/app/models/test_const.rb +14 -0
- data/spec/support/rails_test_app/app/models/test_definition.rb +38 -0
- data/spec/support/rails_test_app/app/models/test_float.rb +14 -0
- data/spec/support/rails_test_app/app/models/test_hash.rb +39 -0
- data/spec/support/rails_test_app/app/models/test_int.rb +14 -0
- data/spec/support/rails_test_app/app/models/test_send.rb +75 -0
- data/spec/support/rails_test_app/app/models/test_str.rb +14 -0
- data/spec/support/rails_test_app/app/models/test_sym.rb +14 -0
- data/spec/support/rails_test_app/app/models/testing_module/bare.rb +6 -0
- data/spec/support/rails_test_app/app/models/testing_module/klass_methods.rb +47 -0
- data/spec/support/rails_test_app/app/models/testing_module/nested/inside.rb +8 -0
- data/spec/support/rails_test_app/app/views/layouts/application.html.erb +14 -0
- data/spec/support/rails_test_app/config.ru +4 -0
- data/spec/support/rails_test_app/config/application.rb +23 -0
- data/spec/support/rails_test_app/config/boot.rb +4 -0
- data/spec/support/rails_test_app/config/database.yml +25 -0
- data/spec/support/rails_test_app/config/environment.rb +5 -0
- data/spec/support/rails_test_app/config/environments/development.rb +37 -0
- data/spec/support/rails_test_app/config/environments/production.rb +83 -0
- data/spec/support/rails_test_app/config/environments/test.rb +39 -0
- data/spec/support/rails_test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/rails_test_app/config/initializers/cookies_serializer.rb +3 -0
- data/spec/support/rails_test_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/support/rails_test_app/config/initializers/inflections.rb +16 -0
- data/spec/support/rails_test_app/config/initializers/mime_types.rb +4 -0
- data/spec/support/rails_test_app/config/initializers/session_store.rb +3 -0
- data/spec/support/rails_test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/support/rails_test_app/config/locales/en.yml +23 -0
- data/spec/support/rails_test_app/config/routes.rb +56 -0
- data/spec/support/rails_test_app/config/secrets.yml +22 -0
- data/spec/support/rails_test_app/db/seeds.rb +7 -0
- data/spec/support/rails_test_app/lib/assets/.keep +0 -0
- data/spec/support/rails_test_app/lib/tasks/.keep +0 -0
- data/spec/support/rails_test_app/log/.keep +0 -0
- data/spec/support/rails_test_app/public/404.html +67 -0
- data/spec/support/rails_test_app/public/422.html +67 -0
- data/spec/support/rails_test_app/public/500.html +66 -0
- data/spec/support/rails_test_app/public/favicon.ico +0 -0
- data/spec/support/rails_test_app/public/robots.txt +5 -0
- data/spec/support/rails_test_app/spec/models/robot_to_test_spec.rb +33 -0
- data/spec/support/rails_test_app/spec/models/test_array_spec.rb +27 -0
- data/spec/support/rails_test_app/spec/models/test_const_spec.rb +11 -0
- data/spec/support/rails_test_app/spec/models/test_definition_spec.rb +31 -0
- data/spec/support/rails_test_app/spec/models/test_float_spec.rb +11 -0
- data/spec/support/rails_test_app/spec/models/test_hash_spec.rb +31 -0
- data/spec/support/rails_test_app/spec/models/test_int_spec.rb +11 -0
- data/spec/support/rails_test_app/spec/models/test_send_spec.rb +53 -0
- data/spec/support/rails_test_app/spec/models/test_str_spec.rb +11 -0
- data/spec/support/rails_test_app/spec/models/test_sym_spec.rb +11 -0
- data/spec/support/rails_test_app/spec/models/testing_module/bare_spec.rb +7 -0
- data/spec/support/rails_test_app/spec/models/testing_module/klass_methods_spec.rb +19 -0
- data/spec/support/rails_test_app/spec/models/testing_module/nested/inside_spec.rb +7 -0
- data/spec/support/rails_test_app/spec/rails_helper.rb +43 -0
- data/spec/support/rails_test_app/spec/spec_helper.rb +78 -0
- 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 +13 -0
- data/spec/support/rails_test_app/vendor/assets/javascripts/.keep +0 -0
- data/spec/support/rails_test_app/vendor/assets/stylesheets/.keep +0 -0
- data/zapata.gemspec +34 -0
- metadata +446 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
module Zapata
|
2
|
+
module RZpec
|
3
|
+
class Writer
|
4
|
+
class << self
|
5
|
+
attr_accessor :ivars
|
6
|
+
|
7
|
+
def reset_ivars
|
8
|
+
@ivars = []
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(file, code, subject_analysis, whole_analysis, spec_analysis = nil)
|
13
|
+
self.class.reset_ivars
|
14
|
+
@subject_analysis = subject_analysis
|
15
|
+
@whole_analysis = whole_analysis
|
16
|
+
@spec_analysis = spec_analysis
|
17
|
+
@writer = Core::Writer.new(file)
|
18
|
+
@result = {}
|
19
|
+
|
20
|
+
write_require
|
21
|
+
|
22
|
+
klasses.each do |klass|
|
23
|
+
write_class(klass)
|
24
|
+
end
|
25
|
+
|
26
|
+
self.class.reset_ivars
|
27
|
+
end
|
28
|
+
|
29
|
+
def write_require
|
30
|
+
@writer.append_line("require '#{Core::Loader.helper_name}'")
|
31
|
+
end
|
32
|
+
|
33
|
+
def klasses
|
34
|
+
@subject_analysis.select { |obj| obj.is_a?(Primitive::Klass) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def klass_defs(klass)
|
38
|
+
@subject_analysis.select do |method|
|
39
|
+
[Primitive::Def, Primitive::Defs].include?(method.class) and
|
40
|
+
method.public? and method.klass.name == klass.name
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize_def(klass)
|
45
|
+
klass_defs(klass).detect { |method| method.name == :initialize }
|
46
|
+
end
|
47
|
+
|
48
|
+
def write_class(klass)
|
49
|
+
@writer.append_line
|
50
|
+
@writer.append_line("describe #{klass.name} do")
|
51
|
+
|
52
|
+
write_instance_let(klass)
|
53
|
+
|
54
|
+
klass_defs(klass).each do |primitive_def|
|
55
|
+
write_method(primitive_def)
|
56
|
+
end
|
57
|
+
|
58
|
+
self.class.ivars.each do |ivar|
|
59
|
+
predicted_value = Predictor::Args.choose_value(ivar.value, ivar)
|
60
|
+
literal_predicted_value = Printer.print(predicted_value.to_raw)
|
61
|
+
write_let(ivar.value, literal_predicted_value)
|
62
|
+
end
|
63
|
+
|
64
|
+
@writer.append_line('end')
|
65
|
+
end
|
66
|
+
|
67
|
+
def write_instance_let(klass)
|
68
|
+
if initialize_def = initialize_def(klass)
|
69
|
+
write_let_from_initialize(initialize_def)
|
70
|
+
else
|
71
|
+
write_let(klass.name, "#{klass.name}.new")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def write_let(name, block)
|
76
|
+
@writer.append_line("let(:#{Printer.to_var_name(name)}) do")
|
77
|
+
@writer.append_line(block)
|
78
|
+
@writer.append_line('end')
|
79
|
+
end
|
80
|
+
|
81
|
+
def write_let_from_initialize(initialize_def)
|
82
|
+
block = "#{initialize_def.klass.name}.new#{initialize_def.literal_predicted_args}"
|
83
|
+
write_let(initialize_def.klass.name, block)
|
84
|
+
end
|
85
|
+
|
86
|
+
def write_method(primitive_def)
|
87
|
+
return unless primitive_def.node.body
|
88
|
+
return if primitive_def.name == :initialize
|
89
|
+
|
90
|
+
@writer.append_line
|
91
|
+
@writer.append_line("it '##{primitive_def.name}' do")
|
92
|
+
|
93
|
+
receiver = if primitive_def.self?
|
94
|
+
primitive_def.klass.name
|
95
|
+
else
|
96
|
+
Printer.to_var_name(primitive_def.klass.name)
|
97
|
+
end
|
98
|
+
|
99
|
+
@writer.append_line(
|
100
|
+
"expect(#{receiver}.#{primitive_def.name}#{primitive_def.literal_predicted_args}).to eq(#{write_equal(primitive_def.name)})"
|
101
|
+
)
|
102
|
+
|
103
|
+
@writer.append_line('end')
|
104
|
+
end
|
105
|
+
|
106
|
+
def write_equal(method_name)
|
107
|
+
if @spec_analysis
|
108
|
+
Printer.print(Primitive::Raw.new(:literal, @spec_analysis.expected(method_name)))
|
109
|
+
else
|
110
|
+
Printer.print(Primitive::Raw.new(:str, 'Fill this in by hand'))
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/spec/array_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zapata::Revolutionist do
|
4
|
+
before(:all) do
|
5
|
+
@generated = exec_generation('app/models/test_array.rb')
|
6
|
+
end
|
7
|
+
|
8
|
+
it '#test_in_arg' do
|
9
|
+
has_block('#test_in_arg', %Q{
|
10
|
+
expect(test_array.test_in_arg([2, 7.1, 8])).to eq([2, 7.1, 8])
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
it '#test_nested_one_level' do
|
15
|
+
has_block('#test_nested_one_level', %Q{
|
16
|
+
expect(test_array.test_nested_one_level([[2, 7.1, 8], :mexico])).to eq([[2, 7.1, 8], :mexico])
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#test_nested_two_levels' do
|
21
|
+
has_block('#test_nested_two_levels', %Q{
|
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
|
+
})
|
24
|
+
end
|
25
|
+
|
26
|
+
it '#test_nested_three_levels' do
|
27
|
+
has_block('#test_nested_three_levels', %Q{
|
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
|
+
})
|
30
|
+
end
|
31
|
+
|
32
|
+
it '#test_hash_nested' do
|
33
|
+
has_block('#test_hash_nested', %Q{
|
34
|
+
expect(test_array.test_hash_nested([{ emiliano: [2, 7.1, 8] }])).to eq([{ emiliano: [2, 7.1, 8] }])
|
35
|
+
})
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zapata::Revolutionist do
|
4
|
+
before(:all) do
|
5
|
+
@generated = exec_generation('app/models/test_definition.rb')
|
6
|
+
end
|
7
|
+
|
8
|
+
it '#in_optional_args' do
|
9
|
+
has_block('#in_optional_args', %Q{
|
10
|
+
expect(test_definition.in_optional_args(:audioslave)).to eq(:audioslave)
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
it '#use_optional' do
|
15
|
+
has_block('#use_optional', %Q{
|
16
|
+
expect(test_definition.use_optional(:audioslave)).to eq(:audioslave)
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#var_in_optional_args' do
|
21
|
+
has_block('#var_in_optional_args', %Q{
|
22
|
+
expect(test_definition.var_in_optional_args('Chuck')).to eq('Chuck')
|
23
|
+
})
|
24
|
+
end
|
25
|
+
|
26
|
+
it '#method_in_optional_args' do
|
27
|
+
has_block('#method_in_optional_args', %Q{
|
28
|
+
expect(test_definition.method_in_optional_args('I am falling')).to eq('I am falling')
|
29
|
+
})
|
30
|
+
end
|
31
|
+
|
32
|
+
it '#call_method_result_in_optional_args' do
|
33
|
+
has_block('#call_method_result_in_optional_args', %Q{
|
34
|
+
expect(test_definition.call_method_result_in_optional_args('Missing "complex_method"')).to eq('Missing "complex_method"')
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
it '#resursive_method' do
|
39
|
+
has_block('#recursive_method', %Q{
|
40
|
+
expect(test_definition.recursive_method).to eq('Exception in RSpec')
|
41
|
+
})
|
42
|
+
end
|
43
|
+
end
|
data/spec/hash_spec.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zapata::Revolutionist do
|
4
|
+
before(:all) do
|
5
|
+
@generated = exec_generation('app/models/test_hash.rb')
|
6
|
+
end
|
7
|
+
|
8
|
+
it '#test_in_arg' do
|
9
|
+
has_block('#test_in_arg', %Q{
|
10
|
+
expect(test_hash.test_in_arg({ 1 => :one, TestHash => 2.718 })).to eq({ 1 => :one, TestHash => 2.718 })
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
it '#test_nested_one_level' do
|
15
|
+
has_block('#test_nested_one_level', %Q{
|
16
|
+
expect(test_hash.test_nested_one_level({ first_level: { 1 => :one, TestHash => 2.718 } })).to eq({ first_level: { 1 => :one, TestHash => 2.718 } })
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#test_nested_two_levels' do
|
21
|
+
has_block('#test_nested_two_levels', %Q{
|
22
|
+
expect(test_hash.test_nested_two_levels({ second_level: { first_level: { 1 => :one, TestHash => 2.718 } } })).to eq({ second_level: { first_level: { 1 => :one, TestHash => 2.718 } } })
|
23
|
+
})
|
24
|
+
end
|
25
|
+
|
26
|
+
it '#test_nested_three_levels' do
|
27
|
+
has_block('#test_nested_three_levels', %Q{
|
28
|
+
expect(test_hash.test_nested_three_levels({ third_level: { second_level: { first_level: { 1 => :one, TestHash => 2.718 } } } })).to eq({ third_level: { second_level: { first_level: { 1 => :one, TestHash => 2.718 } } } })
|
29
|
+
})
|
30
|
+
end
|
31
|
+
|
32
|
+
it '#test_key_as_another_hash' do
|
33
|
+
has_block('#test_key_as_another_hash', %Q{
|
34
|
+
expect(test_hash.test_key_as_another_hash({ { 1 => :one, TestHash => 2.718 } => :ratm })).to eq({ { 1 => :one, TestHash => 2.718 } => :ratm })
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
it '#test_keys_are_symbols' do
|
39
|
+
has_block('#test_keys_are_symbols', %Q{
|
40
|
+
expect(test_hash.test_keys_are_symbols({ this: 'should', be: 'pretty' })).to eq({ this: 'should', be: 'pretty' })
|
41
|
+
})
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zapata::Revolutionist do
|
4
|
+
context 'it should work with' do
|
5
|
+
it 'bare module' do
|
6
|
+
generated = exec_generation('app/models/testing_module/bare.rb')
|
7
|
+
expected = expected(%Q{require 'rails_helper'
|
8
|
+
|
9
|
+
describe TestingModule::Bare do
|
10
|
+
let(:bare) do
|
11
|
+
TestingModule::Bare.new
|
12
|
+
end
|
13
|
+
end})
|
14
|
+
|
15
|
+
expect(generated).to eq(expected)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'nested module' do
|
19
|
+
generated = exec_generation('app/models/testing_module/nested/inside.rb')
|
20
|
+
expected = expected(%Q{require 'rails_helper'
|
21
|
+
|
22
|
+
describe TestingModule::Nested::Inside do
|
23
|
+
let(:inside) do
|
24
|
+
TestingModule::Nested::Inside.new
|
25
|
+
end
|
26
|
+
end})
|
27
|
+
|
28
|
+
expect(generated).to eq(expected)
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'klass methods' do
|
32
|
+
before(:all) do
|
33
|
+
@generated = exec_generation('app/models/testing_module/klass_methods.rb')
|
34
|
+
end
|
35
|
+
|
36
|
+
it '#defined_with_self' do
|
37
|
+
has_block('#defined_with_self', %Q{
|
38
|
+
expect(TestingModule::KlassMethods.defined_with_self(5)).to eq(5)
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
42
|
+
it '#defined_with_back_back_self' do
|
43
|
+
has_block('#defined_with_back_back_self', %Q{
|
44
|
+
expect(TestingModule::KlassMethods.defined_with_back_back_self(5)).to eq(5)
|
45
|
+
})
|
46
|
+
end
|
47
|
+
|
48
|
+
it '#back_to_public_defined_with_self' do
|
49
|
+
has_block('#back_to_public_defined_with_self', %Q{
|
50
|
+
expect(TestingModule::KlassMethods.back_to_public_defined_with_self(5)).to eq(5)
|
51
|
+
})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/send_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zapata::Revolutionist do
|
4
|
+
before(:all) do
|
5
|
+
@generated = exec_generation('app/models/test_send.rb')
|
6
|
+
end
|
7
|
+
|
8
|
+
it '#another_method_as_arg' do
|
9
|
+
has_block('#another_method_as_arg', %Q{
|
10
|
+
expect(test_send.another_method_as_arg('Help method')).to eq('Help method')
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
it '#second_level_method_chain' do
|
15
|
+
has_block('#second_level_method_chain', %Q{
|
16
|
+
expect(test_send.second_level_method_chain('Help method')).to eq('Help method')
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#third_level_method_chain' do
|
21
|
+
has_block('#third_level_method_chain', %Q{
|
22
|
+
expect(test_send.third_level_method_chain('Help method')).to eq('Help method')
|
23
|
+
})
|
24
|
+
end
|
25
|
+
|
26
|
+
it '#method_with_calculated_value' do
|
27
|
+
has_block('#method_with_calculated_value', %Q{
|
28
|
+
expect(test_send.method_with_calculated_value('Missing "calculated_value"')).to eq('Missing "calculated_value"')
|
29
|
+
})
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zapata::Revolutionist do
|
4
|
+
context 'it should work with' do
|
5
|
+
it 'ints' do
|
6
|
+
generated = exec_generation('app/models/test_int.rb')
|
7
|
+
expected = expected(%Q{require 'rails_helper'
|
8
|
+
|
9
|
+
describe TestInt do
|
10
|
+
let(:test_int) do
|
11
|
+
TestInt.new
|
12
|
+
end
|
13
|
+
|
14
|
+
it '#test_int_in_arg' do
|
15
|
+
expect(test_int.test_int_in_arg(1)).to eq(1)
|
16
|
+
end
|
17
|
+
end})
|
18
|
+
|
19
|
+
expect(generated).to eq(expected)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'symbols' do
|
23
|
+
generated = exec_generation('app/models/test_sym.rb')
|
24
|
+
expected = expected(%Q{require 'rails_helper'
|
25
|
+
|
26
|
+
describe TestSym do
|
27
|
+
let(:test_sym) do
|
28
|
+
TestSym.new
|
29
|
+
end
|
30
|
+
|
31
|
+
it '#test_sym_in_arg' do
|
32
|
+
expect(test_sym.test_sym_in_arg(:rock)).to eq(:rock)
|
33
|
+
end
|
34
|
+
end})
|
35
|
+
|
36
|
+
expect(generated).to eq(expected)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'strings' do
|
40
|
+
generated = exec_generation('app/models/test_str.rb')
|
41
|
+
expected = expected(%Q{require 'rails_helper'
|
42
|
+
|
43
|
+
describe TestStr do
|
44
|
+
let(:test_str) do
|
45
|
+
TestStr.new
|
46
|
+
end
|
47
|
+
|
48
|
+
it '#test_str_in_arg' do
|
49
|
+
expect(test_str.test_str_in_arg('audioslave')).to eq('audioslave')
|
50
|
+
end
|
51
|
+
end})
|
52
|
+
|
53
|
+
expect(generated).to eq(expected)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'floats' do
|
57
|
+
generated = exec_generation('app/models/test_float.rb')
|
58
|
+
expected = expected(%Q{require 'rails_helper'
|
59
|
+
|
60
|
+
describe TestFloat do
|
61
|
+
let(:test_float) do
|
62
|
+
TestFloat.new
|
63
|
+
end
|
64
|
+
|
65
|
+
it '#test_float_in_arg' do
|
66
|
+
expect(test_float.test_float_in_arg(2.718)).to eq(2.718)
|
67
|
+
end
|
68
|
+
end})
|
69
|
+
|
70
|
+
expect(generated).to eq(expected)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'consts' do
|
74
|
+
generated = exec_generation('app/models/test_const.rb')
|
75
|
+
expected = expected(%Q{require 'rails_helper'
|
76
|
+
|
77
|
+
describe TestConst do
|
78
|
+
let(:test_const) do
|
79
|
+
TestConst.new
|
80
|
+
end
|
81
|
+
|
82
|
+
it '#test_const_in_arg' do
|
83
|
+
expect(test_const.test_const_in_arg(TestConst)).to eq(TestConst)
|
84
|
+
end
|
85
|
+
end})
|
86
|
+
|
87
|
+
expect(generated).to eq(expected)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'zapata'
|
2
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
3
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
5
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, make a
|
11
|
+
# separate helper file that requires this one and then use it only in the specs
|
12
|
+
# that actually need it.
|
13
|
+
#
|
14
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
15
|
+
# users commonly want.
|
16
|
+
#
|
17
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
18
|
+
RSpec.configure do |config|
|
19
|
+
# The settings below are suggested to provide a good initial experience
|
20
|
+
# with RSpec, but feel free to customize to your heart's content.
|
21
|
+
=begin
|
22
|
+
# These two settings work together to allow you to limit a spec run
|
23
|
+
# to individual examples or groups you care about by tagging them with
|
24
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
25
|
+
# get run.
|
26
|
+
config.filter_run :focus
|
27
|
+
config.run_all_when_everything_filtered = true
|
28
|
+
|
29
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
30
|
+
# file, and it's useful to allow more verbose output when running an
|
31
|
+
# individual spec file.
|
32
|
+
if config.files_to_run.one?
|
33
|
+
# Use the documentation formatter for detailed output,
|
34
|
+
# unless a formatter has already been configured
|
35
|
+
# (e.g. via a command-line flag).
|
36
|
+
config.default_formatter = 'doc'
|
37
|
+
end
|
38
|
+
|
39
|
+
# Print the 10 slowest examples and example groups at the
|
40
|
+
# end of the spec run, to help surface which specs are running
|
41
|
+
# particularly slow.
|
42
|
+
config.profile_examples = 10
|
43
|
+
|
44
|
+
# Run specs in random order to surface order dependencies. If you find an
|
45
|
+
# order dependency and want to debug it, you can fix the order by providing
|
46
|
+
# the seed, which is printed after each run.
|
47
|
+
# --seed 1234
|
48
|
+
config.order = :random
|
49
|
+
|
50
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
51
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
52
|
+
# test failures related to randomization by passing the same `--seed` value
|
53
|
+
# as the one that triggered the failure.
|
54
|
+
Kernel.srand config.seed
|
55
|
+
|
56
|
+
# rspec-expectations config goes here. You can use an alternate
|
57
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
58
|
+
# assertions if you prefer.
|
59
|
+
config.expect_with :rspec do |expectations|
|
60
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
61
|
+
# For more details, see:
|
62
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
63
|
+
expectations.syntax = :expect
|
64
|
+
end
|
65
|
+
|
66
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
67
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
68
|
+
config.mock_with :rspec do |mocks|
|
69
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
70
|
+
# For more details, see:
|
71
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
72
|
+
mocks.syntax = :expect
|
73
|
+
|
74
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
75
|
+
# a real object. This is generally recommended.
|
76
|
+
mocks.verify_partial_doubles = true
|
77
|
+
end
|
78
|
+
=end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Helper methods
|
82
|
+
RAILS_TEST_APP_DIR = "#{Dir.pwd}/spec/support/rails_test_app"
|
83
|
+
|
84
|
+
def clean(string)
|
85
|
+
string.split(/\n/).map(&:strip).join("\n")
|
86
|
+
end
|
87
|
+
|
88
|
+
def expected(code)
|
89
|
+
clean(
|
90
|
+
<<-EXPECTED
|
91
|
+
#{code}
|
92
|
+
EXPECTED
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
def exec_generation(generate_for)
|
97
|
+
stdin, stdout, stderr = Bundler.with_clean_env do
|
98
|
+
Open3.popen3(
|
99
|
+
"cd #{RAILS_TEST_APP_DIR} && bundle exec zapata generate #{generate_for}"
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
output = stdout.readlines
|
104
|
+
generated_filename = output.last.match(/File\ (.+)\ was/)[1]
|
105
|
+
spec_path = "#{RAILS_TEST_APP_DIR}/#{generated_filename}"
|
106
|
+
|
107
|
+
clean(
|
108
|
+
<<-ACTUAL
|
109
|
+
#{File.read(spec_path)}
|
110
|
+
ACTUAL
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
def has_block(name, expected_content)
|
115
|
+
generated_lines = @generated.split("\n")
|
116
|
+
it_starts = generated_lines.index { |line| line == "it '#{name}' do" }
|
117
|
+
raise 'No such block' unless it_starts
|
118
|
+
|
119
|
+
might_match_lines = generated_lines[it_starts..-1]
|
120
|
+
it_ends = might_match_lines.index { |line| line == 'end' }
|
121
|
+
|
122
|
+
block = might_match_lines[1...it_ends].first
|
123
|
+
expect(block).to eq(expected_content.strip)
|
124
|
+
end
|