Class: MotherBrain::Test::Init

Inherits:
Base
  • Object
show all
Includes:
WebMock::API
Defined in:
lib/mb/test.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, mock!, #register_mocks, #type

Constructor Details

This class inherits a constructor from MotherBrain::Test::Base

Instance Method Details

#available_mocksObject



48
49
50
# File 'lib/mb/test.rb', line 48

def available_mocks
  [:env, :cookbook, :bootstrap, :template, :template_url]
end

#bootstrap(x) ⇒ Object



74
75
76
77
78
79
80
# 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) ⇒ Object



67
68
69
70
71
72
# 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) ⇒ Object



62
63
64
65
# File 'lib/mb/test.rb', line 62

def env(name)
  ridley.should_receive(:get).with("environments/#{name}").
    and_return(double(:response, :body => {}))
end

#ridleyObject



52
53
54
55
56
57
58
59
60
# 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) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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) ⇒ Object



98
99
100
101
# 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