Class: Transpec::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/transpec/cli.rb,
lib/transpec/cli/option_parser.rb

Defined Under Namespace

Classes: OptionParser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



22
23
24
25
26
# File 'lib/transpec/cli.rb', line 22

def initialize
  @project = Project.new
  @config = Config.new
  @report = Report.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



16
17
18
# File 'lib/transpec/cli.rb', line 16

def config
  @config
end

#projectObject (readonly)

Returns the value of attribute project.



16
17
18
# File 'lib/transpec/cli.rb', line 16

def project
  @project
end

#reportObject (readonly)

Returns the value of attribute report.



16
17
18
# File 'lib/transpec/cli.rb', line 16

def report
  @report
end

Class Method Details

.run(args = ARGV) ⇒ Object



18
19
20
# File 'lib/transpec/cli.rb', line 18

def self.run(args = ARGV)
  new.run(args)
end

Instance Method Details

#convert_spec(spec, spec_suite) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/transpec/cli.rb', line 83

def convert_spec(spec, spec_suite)
  puts "Converting #{spec.path}"

  converter = Converter.new(spec_suite, config)
  converter.convert_file!(spec)

  warn_annotations(converter.report)
  report << converter.report
rescue Parser::SyntaxError, EncodingError => error
  warn_file_error(error, spec.path)
  report.file_errors << error
end

#process(paths) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/transpec/cli.rb', line 51

def process(paths)
  unless config.skip_dynamic_analysis?
    runtime_data = run_dynamic_analysis(paths)
  end

  spec_suite = SpecSuite.new(project, paths, runtime_data)
  # Actually #analyze does not need to be invoked here, but doing this will avoid long freeze
  # while conversion of files.
  puts 'Gathering the spec suite data...'
  spec_suite.analyze
  puts

  spec_suite.specs.each do |spec|
    convert_spec(spec, spec_suite)
  end
end

#run(args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/transpec/cli.rb', line 28

def run(args)
  begin
    paths = OptionParser.new(config).parse(args)
    validate_project!
  rescue => error
    warn error.message
    return false
  end

  begin
    process(paths)
  rescue DynamicAnalyzer::AnalysisError => error
    warn "\n" + error.message.color(:red)
    return false
  end

  display_summary
  generate_commit_message
  display_final_guide

  true
end

#run_dynamic_analysis(paths) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/transpec/cli.rb', line 68

def run_dynamic_analysis(paths)
  runtime_data = nil

  puts 'Copying the project for dynamic analysis...'

  DynamicAnalyzer.new(project: project, rspec_command: config.rspec_command) do |analyzer|
    puts "Running dynamic analysis with command #{analyzer.rspec_command.inspect}..."
    runtime_data = analyzer.analyze(paths)
  end

  puts

  runtime_data
end