Class: Transpec::DynamicAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/transpec/dynamic_analyzer.rb,
lib/transpec/dynamic_analyzer/rewriter.rb,
lib/transpec/dynamic_analyzer/node_util.rb,
lib/transpec/dynamic_analyzer/runtime_data.rb

Defined Under Namespace

Modules: NodeUtil Classes: AnalysisError, Rewriter, RuntimeData

Constant Summary collapse

ANALYSIS_METHOD =
'transpec_analyze'
HELPER_TEMPLATE_FILE =
'transpec_analysis_helper.rb.erb'
RESULT_FILE =
'transpec_analysis_result.json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DynamicAnalyzer

Returns a new instance of DynamicAnalyzer.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/transpec/dynamic_analyzer.rb', line 24

def initialize(options = {})
  @project = options[:project] || Project.new
  @rspec_command = options[:rspec_command] || default_rspec_command
  @silent = options[:silent] || false

  if block_given?
    in_copied_project do
      yield self
    end
  end
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



21
22
23
# File 'lib/transpec/dynamic_analyzer.rb', line 21

def project
  @project
end

#rspec_commandObject (readonly)

Returns the value of attribute rspec_command.



21
22
23
# File 'lib/transpec/dynamic_analyzer.rb', line 21

def rspec_command
  @rspec_command
end

#silentObject (readonly) Also known as: silent?

Returns the value of attribute silent.



21
22
23
# File 'lib/transpec/dynamic_analyzer.rb', line 21

def silent
  @silent
end

Instance Method Details

#analyze(paths = []) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/transpec/dynamic_analyzer.rb', line 44

def analyze(paths = [])
  in_copied_project do
    rewrite_specs(paths)
    put_analysis_helper
    modify_dot_rspec
    run_rspec(paths)

    begin
      File.open(RESULT_FILE) do |file|
        RuntimeData.load(file)
      end
    rescue
      raise AnalysisError
    end
  end
end

#copy_recursively(source_root, destination_root) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/transpec/dynamic_analyzer.rb', line 61

def copy_recursively(source_root, destination_root)
  source_root = File.expand_path(source_root)
  source_root_pathname = Pathname.new(source_root)

  destination_root = File.expand_path(destination_root)
  if File.directory?(destination_root)
    destination_root = File.join(destination_root, File.basename(source_root))
  end

  Find.find(source_root) do |source_path|
    relative_path = Pathname.new(source_path).relative_path_from(source_root_pathname).to_s
    destination_path = File.join(destination_root, relative_path)
    copy(source_path, destination_path)
  end
end

#default_rspec_commandObject



36
37
38
39
40
41
42
# File 'lib/transpec/dynamic_analyzer.rb', line 36

def default_rspec_command
  if project.require_bundler?
    'bundle exec rspec'
  else
    'rspec'
  end
end