Module: Metasploit::Model::Spec::TemporaryPathname

Included in:
Metasploit::Model::Spec
Defined in:
lib/metasploit/model/spec/temporary_pathname.rb

Overview

Examples:

Temporary pathname creation and removal


# spec/spec_helper.rb
RSpec.config do |config|
  config.before(:suite) do
    Metasploit::Model::Spec.temporary_pathname = MyApp.root.join('spec', 'tmp')
    # Clean up any left over files from a previously aborted suite
    Metasploit::Model::Spec.remove_temporary_pathname
  end

  config.after(:each) do
    Metasploit::Model::Spec.remove_temporary_pathname
  end
end

Instance Method Summary collapse

Instance Method Details

#remove_temporary_pathnamevoid

This method returns an undefined value.

Removes #temporary_pathname from disk if it's been set and exists on disk.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/metasploit/model/spec/temporary_pathname.rb', line 19

def remove_temporary_pathname
  begin
    removal_pathname = temporary_pathname
  rescue Metasploit::Model::Spec::Error
    removal_pathname = nil
  end

  if removal_pathname and removal_pathname.exist?
    removal_pathname.rmtree
  end
end

#temporary_pathnamePathname

Pathname to hold temporary files for metasploit-model factories and sequence. The directory must be be safely writable and removable for specs that need to use the file system.

Returns:

  • (Pathname)

Raises:



36
37
38
39
40
41
42
# File 'lib/metasploit/model/spec/temporary_pathname.rb', line 36

def temporary_pathname
  unless instance_variable_defined?(:@temporary_pathname)
    raise Metasploit::Model::Spec::Error, 'Metasploit::Model::Spec.temporary_pathname not set prior to use'
  end

  @temporary_pathname
end

#temporary_pathname=(pathname) ⇒ Pathname

Sets the pathname to use for temporary directories and files used in metasploit_data_models factories and sequences.

Parameters:

  • pathname (Pathname)

    path to a directory. It does not need to exist, but need to be in a writable parent directory so it can be removed by #remove_temporary_pathname.

Returns:

  • (Pathname)

    pathname



50
51
52
# File 'lib/metasploit/model/spec/temporary_pathname.rb', line 50

def temporary_pathname=(pathname)
  @temporary_pathname = pathname
end