working on tests

This commit is contained in:
David Dollar
2010-05-20 00:04:48 -04:00
parent 0221c2305c
commit 53eb08be4f
14 changed files with 244 additions and 19 deletions
+77
View File
@@ -0,0 +1,77 @@
require "spec_helper"
require "foreman/cli"
describe "Foreman::CLI" do
subject { Foreman::CLI.new }
describe "start" do
#let(:engine) { stub_engine }
describe "with a non-existent Procifile" do
it "prints an error" do
mock_error(subject, "Procfile does not exist.") do
dont_allow.instance_of(Foreman::Engine).start
subject.start
end
end
end
describe "with a Procfile" do
before(:each) { write_procfile }
it "runs successfully" do
dont_allow(subject).error
mock.instance_of(Foreman::Engine).start
subject.start
end
end
end
describe "export" do
describe "with a non-existent Procifile" do
it "prints an error" do
mock_error(subject, "Procfile does not exist.") do
dont_allow.instance_of(Foreman::Engine).export
subject.export("testapp")
end
end
end
describe "with a Procfile" do
before(:each) { write_procfile }
describe "with an invalid formatter" do
it "prints an error" do
mock_error(subject, "Unknown export format: invalidformatter.") do
subject.export("testapp", "Procfile", "invalidformatter")
end
end
end
describe "with a valid config" do
before(:each) { write_foreman_config("testapp") }
it "runs successfully" do
dont_allow(subject).error
subject.export("testapp")
end
end
end
end
describe "scale" do
describe "without an existing configuration" do
# TODO
end
describe "with an existing configuration" do
before(:each) { write_foreman_config("testapp") }
it "scales the specified process" do
mock.instance_of(Foreman::Configuration).scale("testprocess", "2")
subject.scale("testapp", "testprocess", "2")
end
end
end
end
+2
View File
@@ -0,0 +1,2 @@
require "spec_helper"
require "foreman/configuration"
+2
View File
@@ -0,0 +1,2 @@
require "spec_helper"
require "foreman/engine"
+2
View File
@@ -0,0 +1,2 @@
require "spec_helper"
require "foreman/export/upstart"
+2
View File
@@ -0,0 +1,2 @@
require "spec_helper"
require "foreman/export"
+2
View File
@@ -0,0 +1,2 @@
require "spec_helper"
require "foreman/process"
+11
View File
@@ -0,0 +1,11 @@
require "spec_helper"
require "foreman"
describe Foreman do
describe "VERSION" do
subject { Foreman::VERSION }
it { should be_a String }
end
end
+55
View File
@@ -0,0 +1,55 @@
require "fakefs/spec_helpers"
require "rspec"
$:.unshift "lib"
# def stub_configuration
# config = mock(Foreman::Configuration)
# Foreman::Configuration.stub(:new).and_return(config)
# config
# end
#
#
# def stub_export_upstart
# upstart = mock(Foreman::Export::Upstart)
# Foreman::Export::Upstart.stub(:new).and_return(upstart)
# upstart
# end
def mock_error(subject, message)
mock_exit do
mock(subject).puts("ERROR: #{message}")
yield
end
end
def mock_exit(&block)
block.should raise_error(SystemExit)
end
# def stub_engine
# engine = mock(Foreman::Engine)
# stub(Foreman::Engine).new { engine }
# engine
# end
#
def write_foreman_config(app)
File.open("/etc/foreman/#{app}.conf", "w") do |file|
file.puts %{#{app}_processes="alpha bravo"}
file.puts %{#{app}_alpha="1"}
file.puts %{#{app}_bravo="2"}
end
end
def write_procfile(procfile="Procfile")
File.open(procfile, "w") do |file|
file.puts "alpha ./alpha"
file.puts "bravo ./bravo"
end
end
Rspec.configure do |config|
config.color_enabled = true
config.include FakeFS::SpecHelpers
config.mock_with :rr
end