lib/zapata.rb in zapata-0.1.6 vs lib/zapata.rb in zapata-1.0.0
- old
+ new
@@ -1,19 +1,20 @@
+# frozen_string_literal: true
+
require 'parser/current'
require 'unparser'
+require 'tempfile'
require 'rails'
-require 'require_all'
-require 'file/temp'
require 'open3'
require 'rspec'
require 'memoist'
-require 'slop'
-require_rel 'zapata/core'
-require_rel 'zapata/predictor'
-require_rel 'zapata/primitive'
-require_rel 'zapata/rzpec'
+require_relative 'zapata/core'
+require_relative 'zapata/predictor'
+require_relative 'zapata/primitive'
+require_relative 'zapata/rzpec/runner'
+require_relative 'zapata/rzpec/writer'
require_relative 'zapata/analyst'
require_relative 'zapata/diver'
require_relative 'zapata/db'
require_relative 'zapata/printer'
require_relative 'zapata/version'
@@ -21,19 +22,17 @@
module Zapata
class Revolutionist
class << self
attr_accessor :analysis, :analysis_as_array
- def generate_with_friendly_output(args, opts)
- file = args.shift
- spec_filename = Zapata::Revolutionist.generate(file,
- single: single?(opts, args))
+ def generate_with_friendly_output(filename:, single: false)
+ spec_filename = Zapata::Revolutionist.generate(filename: filename, single: single)
puts "Its done, comrades. File #{spec_filename} was generated."
end
- def generate(filename, single: false)
- dirs = single ? [] : %w(app/models)
+ def generate(filename:, single: false)
+ dirs = single ? [] : %w[app/models]
file_list = Core::Collector.expand_dirs_to_files(dirs)
new(file_list).generate_rspec_for(filename, spec_filename(filename))
end
def init_analysis_as_array
@@ -63,12 +62,12 @@
puts "[#{adjusted_current(i, total)}/#{total}] Analyzing: #{filename}"
obj[filename] = Analyst.analyze(filename)
end
end
- def adjusted_current(i, total)
- "#{i + 1}".rjust(total.size)
+ def adjusted_current(index, total)
+ (index + 1).to_s.rjust(total.size)
end
def generate_rspec_for(filename, spec_filename)
unless self.class.analysis[filename]
self.class.analysis[filename] = Analyst.analyze(filename)
@@ -78,18 +77,19 @@
code = Core::Reader.parse(filename)
global_analysis = Revolutionist.analysis_as_array
# first run
- tmp_spec_filename = File::Temp.new(false).path
- RZpec::Writer.new(tmp_spec_filename, code, self.class.analysis[filename], global_analysis)
+ Tempfile.open('spec') do |tempfile|
+ RZpec::Writer.new(tempfile.path, code, self.class.analysis[filename], global_analysis)
- save_spec_file(tmp_spec_filename, spec_filename)
- spec_analysis = RZpec::Runner.new(spec_filename)
+ save_spec_file(tempfile.path, spec_filename)
+ spec_analysis = RZpec::Runner.new(spec_filename)
- # second run with RSpec results
- RZpec::Writer.new(tmp_spec_filename, code, self.class.analysis[filename], global_analysis, spec_analysis)
- save_spec_file(tmp_spec_filename, spec_filename)
+ # second run with RSpec results
+ RZpec::Writer.new(tempfile.path, code, self.class.analysis[filename], global_analysis, spec_analysis)
+ save_spec_file(tempfile.path, spec_filename)
+ end
end
def save_spec_file(tmp_spec_filename, spec_filename)
spec_path = "#{Dir.pwd}/#{spec_filename}"
spec_dir = spec_path.split('/')[0...-1].join('/')