0

I have multiple specs, wish to create separate log files per spec with the spec file name. I need to know which spec file is currently loaded in spec_helper.rb.

I have to create logger object in spec helper

RSpec.configure do |config|
  config.before(:all) do |example_group|
    loaded_files = config.instance_variable_get("@files_to_run")
    # after getting the current spec file name
    # will create log file here
  end
end

loaded_files have an array of all the spec files that I chose for execution. I need to know which is currently loaded?

I do not want to put a before(:each) block, it will increase the run time and i just need the filename, not a good solution to use before(:each) block.

1 Answers1

-1

I hope the following code can help.

RSpec.configure do |config|
  config.before(:all) do |example_group|
    path = example.metadata[:example_group][:file_path]
    curr_path = config.instance_variable_get(:@curr_file_path)
    if (curr_path.nil? || path != curr_path)
      config.instance_variable_set(:@curr_file_path, path)
      puts path
    end
  end
end

Reference

fidato
  • 719
  • 5
  • 22