Class: RspecStarter::RemoveTmpFolderStep

Inherits:
Step
  • Object
show all
Defined in:
lib/rspec_starter/legacy/steps/remove_tmp_folder_step.rb

Overview

The step that removes the tmp folder.

Instance Attribute Summary

Attributes inherited from Step

#relevant_options

Instance Method Summary collapse

Methods inherited from Step

#should_skip?

Constructor Details

#initialize(defaults, runner) ⇒ RemoveTmpFolderStep

Returns a new instance of RemoveTmpFolderStep.



4
5
6
7
8
9
10
11
12
# File 'lib/rspec_starter/legacy/steps/remove_tmp_folder_step.rb', line 4

def initialize(defaults, runner)
  super(runner)

  @remove_tmp_folder = defaults.fetch(:remove_tmp, true)
  @runner = runner
  @relevant_options << "--no-remove-tmp"
  @user_wants_to_skip_removal = ARGV.any? { |option| option.include?("--no-remove-tmp") }
  @success_or_skipped = nil # Will be updated once step executes
end

Instance Method Details

#executeObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rspec_starter/legacy/steps/remove_tmp_folder_step.rb', line 24

def execute
  return @success_or_skipped = true unless should_execute?

  existed_before = tmp_folder_exists?

  print "[#{@runner.step_num}] Removing #{'tmp'.colorize(:light_blue)} folder ... "
  system "rm -rf tmp/"

  if tmp_folder_exists?
    @succss_or_skipped = false
    puts "Failed (The tmp folder could not be removed.)".red
  else
    @success_or_skipped = true
    info = existed_before ? "" : " (the tmp folder didn't exist)"
    puts "Success!!#{info}".colorize(:green)
  end
end

#failed?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rspec_starter/legacy/steps/remove_tmp_folder_step.rb', line 14

def failed?
  !@success_or_skipped
end

#should_execute?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/rspec_starter/legacy/steps/remove_tmp_folder_step.rb', line 18

def should_execute?
  return false if @user_wants_to_skip_removal

  @remove_tmp_folder
end

#tmp_folder_exists?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rspec_starter/legacy/steps/remove_tmp_folder_step.rb', line 42

def tmp_folder_exists?
  File.exist?(File.join(Dir.pwd, "tmp"))
end