Module: RSpec::StackProf::FilenameHelpers

Included in:
RSpec::StackProf
Defined in:
lib/rspec/stackprof/filename_helpers.rb

Instance Method Summary collapse

Instance Method Details

#create_missing_dirsObject



39
40
41
42
# File 'lib/rspec/stackprof/filename_helpers.rb', line 39

def create_missing_dirs
  dirname = File.dirname(File.join(output_dir,output_file))
  FileUtils.mkdir_p(dirname)
end

#create_unique_file_nameObject



44
45
46
# File 'lib/rspec/stackprof/filename_helpers.rb', line 44

def create_unique_file_name 
  "#{file_basename}_#{uniqueness}#{file_extension}"
end

#file_basenameObject



19
20
21
# File 'lib/rspec/stackprof/filename_helpers.rb', line 19

def file_basename
  File.basename(RSpec::StackProf.configuration.out_file,".*")
end

#file_dirnameObject



23
24
25
# File 'lib/rspec/stackprof/filename_helpers.rb', line 23

def file_dirname
  File.dirname(RSpec::StackProf.configuration.out_file)
end

#file_extensionObject



13
14
15
16
17
# File 'lib/rspec/stackprof/filename_helpers.rb', line 13

def file_extension
  ext = File.extname(RSpec::StackProf.configuration.out_file)
  return  ".out" if ext.length == 0
  return ext
end

#filename_for(example) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rspec/stackprof/filename_helpers.rb', line 48

def filename_for example
  require 'pry'
  raise "No example specified" if example.nil? 
  path = path_for(example.[:example_group])
  line_number = example.[:line_number].to_s
  description = example.[:description]
  File.join(
    path,
    description
  ).gsub(/\s+/, '_') + ":" + line_number 
end

#output_dirObject



5
6
7
# File 'lib/rspec/stackprof/filename_helpers.rb', line 5

def output_dir
  RSpec::StackProf.configuration.out_dir
end

#output_fileObject



9
10
11
# File 'lib/rspec/stackprof/filename_helpers.rb', line 9

def output_file
  RSpec::StackProf.configuration.out_file
end

#path_for(metadata) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/rspec/stackprof/filename_helpers.rb', line 27

def path_for 
  if [:parent_example_group]
    File.join(path_for([:parent_example_group]), [:description])
  else
    [:description]
  end
end

#uniquenessObject



35
36
37
# File 'lib/rspec/stackprof/filename_helpers.rb', line 35

def uniqueness 
  "#{Process.pid}_#{Time.now.to_i}"
end