This repository has been archived by the owner on Nov 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_spec.rb
60 lines (51 loc) · 2.04 KB
/
project_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'spec_helper'
describe Project do
context "The Project class" do
it 'returns a list of all projects' do
Dir.stubs(:[]).returns(["#{Configuration.root}/projects/opower"])
Project.all.should == [Project.new(:name => "opower")]
Dir.should have_received(:[]).with("#{Configuration.root}/projects/*")
end
end
context "An instance of the Project class" do
before :each do
@project = Project.new(:name => 'opower')
@project.stubs(:path).returns('/projects/opower')
end
it "knows if it is equal to another project" do
@project == @project.dup
end
it "knows which stages it can deploy to" do
Dir.stubs(:[]).returns(["/projects/opower/deploy/staging", "/projects/opower/deploy/production"])
@project.stages.should == ["staging", "production"]
Dir.should have_received(:[]).with("/projects/opower/deploy/*", ".rb")
end
it "has a deploy path" do
@project.deploy_path.should == '/projects/opower/deploy.rb'
end
it "has a deploy path for a stage" do
@project.deploy_path('staging').should == '/projects/opower/deploy/staging.rb'
end
it "deploys to a given stage" do
File.stubs(:open).yields(stub(:write))
@project.stubs(:stages).returns(["staging"])
@project.stubs(:`).returns("a log of data")
@project.deploy_to("staging")
@project.should have_received(:`).with("cap -S stage=staging -f Capfile -f /projects/opower/deploy.rb -f /projects/opower/deploy/staging.rb -n deploy 2>&1")
end
it "doesn't deploy to an unknown stage" do
@project.stubs(:stages).returns(["staging"])
@project.stubs(:`)
@project.deploy_to("production")
@project.should have_received(:`).never
end
it "writes the deploy log returned to a logfile" do
file = stub(:write)
File.stubs(:open).yields(file)
@project.stubs(:stages).returns(["staging"])
@project.stubs(:`).returns("log log log")
@project.deploy_to("staging")
file.should have_received(:write).with("log log log")
end
end
end