Module: Cheffish::RSpec::ChefRunSupport::ChefRunSupportInstanceMethods

Defined in:
lib/cheffish/rspec/chef_run_support.rb

Instance Method Summary collapse

Instance Method Details

#basic_chef_clientObject



83
84
85
# File 'lib/cheffish/rspec/chef_run_support.rb', line 83

def basic_chef_client
  chef_client.client
end

#chef_clientObject



70
71
72
# File 'lib/cheffish/rspec/chef_run_support.rb', line 70

def chef_client
  @chef_client ||= ChefRunWrapper.new(chef_config)
end

#chef_configObject



58
59
60
# File 'lib/cheffish/rspec/chef_run_support.rb', line 58

def chef_config
  {}
end

#chef_runObject



74
75
76
77
# File 'lib/cheffish/rspec/chef_run_support.rb', line 74

def chef_run
  converge if !chef_client.converged?
  event_sink.events
end

#convergeObject



101
102
103
104
105
106
# File 'lib/cheffish/rspec/chef_run_support.rb', line 101

def converge
  if chef_client.converged?
    raise "Already converged! Cannot converge twice, that's bad mojo."
  end
  chef_client.converge
end

#event_sinkObject



79
80
81
# File 'lib/cheffish/rspec/chef_run_support.rb', line 79

def event_sink
  chef_client.event_sink
end

#expect_recipe(&recipe) ⇒ Object



62
63
64
# File 'lib/cheffish/rspec/chef_run_support.rb', line 62

def expect_recipe(&recipe)
  expect(recipe(&recipe))
end

#get(path, *args) ⇒ Object



51
52
53
54
55
56
# File 'lib/cheffish/rspec/chef_run_support.rb', line 51

def get(path, *args)
  if path[0] == '/'
    path = URI.join(rest.url, path)
  end
  rest.get(path, *args)
end

#load_recipe(&recipe) ⇒ Object



87
88
89
# File 'lib/cheffish/rspec/chef_run_support.rb', line 87

def load_recipe(&recipe)
  chef_client.client.load_block(&recipe)
end

#recipe(&recipe) ⇒ Object



66
67
68
# File 'lib/cheffish/rspec/chef_run_support.rb', line 66

def recipe(&recipe)
  RecipeRunWrapper.new(chef_config, &recipe)
end

#reset_chef_clientObject



96
97
98
99
# File 'lib/cheffish/rspec/chef_run_support.rb', line 96

def reset_chef_client
  @event_sink = nil
  @basic_chef_client = nil
end

#restObject



47
48
49
# File 'lib/cheffish/rspec/chef_run_support.rb', line 47

def rest
  ::Chef::ServerAPI.new
end

#run_recipe(&recipe) ⇒ Object



91
92
93
94
# File 'lib/cheffish/rspec/chef_run_support.rb', line 91

def run_recipe(&recipe)
  load_recipe(&recipe)
  converge
end