Class: ItamaeSpec::Task::LocalServerspecTask

Inherits:
BaseTask
  • Object
show all
Defined in:
lib/itamae-spec/task/local_serverspec_task.rb

Constant Summary collapse

ChangeTargetError =
Class.new(StandardError)
LoadSpecError =
Class.new(StandardError)

Constants inherited from BaseTask

BaseTask::EnvironmentsSetError, BaseTask::LoadAttributeError, BaseTask::LoadRecipeError

Instance Method Summary collapse

Methods inherited from BaseTask

#create_itamae_command, #create_tmp_nodes, #load_environments, #load_node_attributes, #load_recipe_attributes, #load_run_list, #merge_attributes, #runner_display

Instance Method Details

#create_spec_command(node_name, hash) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/itamae-spec/task/local_serverspec_task.rb', line 9

def create_spec_command(node_name, hash)
  ENV['TARGET_HOST'] = if hash[:environments][:local_ipv4].nil?
                         hash[:environments][:hostname]
                       else
                         hash[:environments][:local_ipv4]
                       end

  ENV['NODE_FILE'] = "tmp-nodes/#{node_name}.json"
  ENV['SUDO_PASSWORD'] = hash[:environments][:sudo_password]
  ENV['LOCAL_MODE'] = 'enable local mode'

  command = 'bundle exec rspec'
end

#list_recipe_filepath(run_list) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/itamae-spec/task/local_serverspec_task.rb', line 23

def list_recipe_filepath(run_list)
  recipes = []
  run_list.each do |recipe|
    target_list = Dir.glob("cookbooks/#{recipe.keys.join}/spec/#{recipe.values.join}_spec.rb")

    raise LoadSpecError, "#{recipe.to_a.join('::')} cookbook or spec does not exist." if target_list.empty?

    target_list.each do |target|
      recipes << " #{target}"
    end
  end

  recipes
end