class MotherBrain::Test::Init

Public Instance Methods

available_mocks() click to toggle source
# File lib/mb/test.rb, line 48
def available_mocks
  [:env, :cookbook, :bootstrap, :template, :template_url]
end
bootstrap(x) click to toggle source
# File lib/mb/test.rb, line 74
def bootstrap(x)
  Application.bootstrap_manager.wrapped_object.should_receive(:bootstrap) do |job, environment, manifest, plugin, options|
    job.report_running
    job.report_success
    job.terminate if job.alive?
  end
end
cookbook(name, version = nil) click to toggle source
# File lib/mb/test.rb, line 67
def cookbook(name, version = nil)
  ridley.should_receive(:get).with("cookbooks").and_return(double(:response, :body => {}))
  ridley.should_receive(:get).with("cookbooks/#{name}").and_return(double(:response, :body => {}))
  plugin = MB::Application.plugin_manager.find(name, version)
  MB::Application.plugin_manager.should_receive(:for_environment).and_return(plugin)
end
env(name) click to toggle source
# File lib/mb/test.rb, line 62
def env(name)
  ridley.should_receive(:get).with("environments/#{name}").
    and_return(double(:response, :body => {}))
end
ridley() click to toggle source
# File lib/mb/test.rb, line 52
def ridley
  return @ridley if @ridley
  @ridley = double('ridley')
  Application.ridley.wrapped_object.should_receive(:connection).and_return(@ridley)
  @ridley.should_receive(:alive?).and_return(true)
  @ridley.should_receive(:terminate).and_return(true)
  @ridley.should_receive(:url_prefix).and_return("http://chef.example.com")
  @ridley
end
template(name) click to toggle source
# File lib/mb/test.rb, line 82
def template(name)
  ridley.should_receive(:get).with("nodes").and_return(double(:response, :body => []))
  node = double('node')
  Application.ridley.wrapped_object.should_receive(:node).and_return(node)
  ssh = double('ssh')
  node.should_receive(:bootstrap) do |hostnames, options|
    raise "Template not set!" unless options[:template]
    raise "Template not right!" unless options[:template] =~ /#{name}/
    [ssh]
  end
  node.should_receive(:all).and_return([])
  ssh.should_receive(:host).and_return("foo.example.com")
  ssh.should_receive(:error?).and_return(false)
  Application.node_querier.wrapped_object.should_receive(:node_name).and_return("foo.example.com")
end
template_url(name_and_url) click to toggle source
# File lib/mb/test.rb, line 98
def template_url(name_and_url)
  name, url = name_and_url.split("##")
  stub_request(:get, url).to_return(:body => name)
end