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

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

Instance Method Summary collapse

Instance Method Details

#chef_clientObject



77
78
79
# File 'lib/cheffish/rspec/chef_run_support.rb', line 77

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

#chef_configObject



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

def chef_config
  {}
end

#converge(str = nil, file = nil, line = nil, &recipe) ⇒ Object



71
72
73
74
75
# File 'lib/cheffish/rspec/chef_run_support.rb', line 71

def converge(str=nil, file=nil, line=nil, &recipe)
  r = recipe(str, file, line, &recipe)
  r.converge
  r
end

#expect_converge(str = nil, file = nil, line = nil, &recipe) ⇒ Object



56
57
58
# File 'lib/cheffish/rspec/chef_run_support.rb', line 56

def expect_converge(str=nil, file=nil, line=nil, &recipe)
  expect { converge(str, file, line, &recipe) }
end

#expect_recipe(str = nil, file = nil, line = nil, &recipe) ⇒ Object



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

def expect_recipe(str=nil, file=nil, line=nil, &recipe)
  r = recipe(str, file, line, &recipe)
  r.converge
  expect(r)
end

#get(path, *args) ⇒ Object



39
40
41
42
43
44
# File 'lib/cheffish/rspec/chef_run_support.rb', line 39

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

#recipe(str = nil, file = nil, line = nil, &recipe) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/cheffish/rspec/chef_run_support.rb', line 60

def recipe(str=nil, file=nil, line=nil, &recipe)
  if !recipe
    if file && line
      recipe = proc { eval(str, nil, file, line) }
    else
      recipe = proc { eval(str) }
    end
  end
  RecipeRunWrapper.new(chef_config, &recipe)
end

#restObject



35
36
37
# File 'lib/cheffish/rspec/chef_run_support.rb', line 35

def rest
  ::Chef::ServerAPI.new(Chef::Config.chef_server_url, api_version: "0")
end