class Zapata::Revolutionist
Attributes
analysis[RW]
analysis_as_array[RW]
Public Class Methods
generate(filename:, single: false)
click to toggle source
# File lib/zapata.rb, line 32 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
generate_with_friendly_output(filename:, single: false)
click to toggle source
# File lib/zapata.rb, line 27 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
init_analysis_as_array()
click to toggle source
# File lib/zapata.rb, line 38 def init_analysis_as_array @analysis_as_array = analysis.values.flatten end
new(file_list)
click to toggle source
# File lib/zapata.rb, line 53 def initialize(file_list) Core::Loader.load_spec_helper self.class.analysis = analyze_multiple(file_list) end
spec_filename(filename)
click to toggle source
# File lib/zapata.rb, line 42 def spec_filename(filename) filename.gsub('app/', 'spec/').gsub('.rb', '_spec.rb') end
Private Class Methods
single?(opts, args)
click to toggle source
# File lib/zapata.rb, line 48 def single?(opts, args) opts.single? || args.include?('-s') || args.include?('--single') end
Public Instance Methods
adjusted_current(index, total)
click to toggle source
# File lib/zapata.rb, line 67 def adjusted_current(index, total) (index + 1).to_s.rjust(total.size) end
analyze_multiple(files)
click to toggle source
# File lib/zapata.rb, line 58 def analyze_multiple(files) total = files.size.to_s files.each_with_object({}).with_index do |(filename, obj), i| puts "[#{adjusted_current(i, total)}/#{total}] Analyzing: #{filename}" obj[filename] = Analyst.analyze(filename) end end
generate_rspec_for(filename, spec_filename)
click to toggle source
# File lib/zapata.rb, line 71 def generate_rspec_for(filename, spec_filename) unless self.class.analysis[filename] self.class.analysis[filename] = Analyst.analyze(filename) end self.class.init_analysis_as_array code = Core::Reader.parse(filename) global_analysis = Revolutionist.analysis_as_array # first run Tempfile.open('spec') do |tempfile| RZpec::Writer.new(tempfile.path, code, self.class.analysis[filename], global_analysis) save_spec_file(tempfile.path, spec_filename) spec_analysis = RZpec::Runner.new(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
save_spec_file(tmp_spec_filename, spec_filename)
click to toggle source
# File lib/zapata.rb, line 94 def save_spec_file(tmp_spec_filename, spec_filename) spec_path = "#{Dir.pwd}/#{spec_filename}" spec_dir = spec_path.split('/')[0...-1].join('/') FileUtils.mkdir_p(spec_dir) FileUtils.cp(tmp_spec_filename, spec_path) spec_filename end