semaphoreapp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +105 -0
- data/Rakefile +6 -0
- data/lib/semaphoreapp/api.rb +75 -0
- data/lib/semaphoreapp/base.rb +28 -0
- data/lib/semaphoreapp/branch.rb +44 -0
- data/lib/semaphoreapp/branch_status.rb +14 -0
- data/lib/semaphoreapp/build.rb +13 -0
- data/lib/semaphoreapp/commit.rb +5 -0
- data/lib/semaphoreapp/json_api.rb +33 -0
- data/lib/semaphoreapp/project.rb +34 -0
- data/lib/semaphoreapp/version.rb +3 -0
- data/lib/semaphoreapp.rb +38 -0
- data/semaphoreapp.gemspec +24 -0
- data/spec/fixtures/branch_statuses.json +42 -0
- data/spec/fixtures/branches.json +14 -0
- data/spec/fixtures/builds.json +32 -0
- data/spec/fixtures/commit.json +8 -0
- data/spec/fixtures/projects.json +46 -0
- data/spec/semaphoreapp/api_spec.rb +153 -0
- data/spec/semaphoreapp/branch_spec.rb +135 -0
- data/spec/semaphoreapp/branch_status_spec.rb +78 -0
- data/spec/semaphoreapp/build_spec.rb +78 -0
- data/spec/semaphoreapp/commit_spec.rb +20 -0
- data/spec/semaphoreapp/json_api_spec.rb +25 -0
- data/spec/semaphoreapp/project_spec.rb +80 -0
- data/spec/spec_helper.rb +23 -0
- metadata +167 -0
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Semaphoreapp::Api do
|
4
|
+
subject{ Semaphoreapp::Api }
|
5
|
+
|
6
|
+
describe ".url_with_auth_token" do
|
7
|
+
before{ Semaphoreapp.stub(:auth_token).and_return('test_token') }
|
8
|
+
|
9
|
+
it "should append auth_token to the given URL" do
|
10
|
+
subject.url_with_auth_token('test_url').should == '/test_url?auth_token=test_token'
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with a page" do
|
14
|
+
it "should append page to the given URL" do
|
15
|
+
subject.url_with_auth_token('test_url', :page => ':page').should == '/test_url?auth_token=test_token&page=:page'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "URL generators" do
|
21
|
+
before{ Semaphoreapp.stub(:auth_token).and_return('test_token') }
|
22
|
+
before{ stub_const('Semaphoreapp::Api::API_URL', 'api_url') }
|
23
|
+
|
24
|
+
describe ".projects_url" do
|
25
|
+
subject{ Semaphoreapp::Api.projects_url }
|
26
|
+
it{ should start_with '/api_url/projects' }
|
27
|
+
it{ should end_with '?auth_token=test_token' }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".branches_url" do
|
31
|
+
subject{ Semaphoreapp::Api.branches_url(':hash_id') }
|
32
|
+
it{ should start_with '/api_url/projects/:hash_id/branches' }
|
33
|
+
it{ should end_with '?auth_token=test_token' }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".branch_history_url" do
|
37
|
+
subject{ Semaphoreapp::Api.branch_history_url(':hash_id', ':id') }
|
38
|
+
it{ should start_with '/api_url/projects/:hash_id/:id' }
|
39
|
+
it{ should end_with '?auth_token=test_token' }
|
40
|
+
|
41
|
+
context "with a page" do
|
42
|
+
subject{ Semaphoreapp::Api.branch_history_url(':hash_id', ':id', :page => ':page') }
|
43
|
+
it{ should include 'page=:page' }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".branch_status_url" do
|
48
|
+
subject{ Semaphoreapp::Api.branch_status_url(':hash_id', ':id') }
|
49
|
+
it{ should start_with '/api_url/projects/:hash_id/:id/status' }
|
50
|
+
it{ should end_with '?auth_token=test_token' }
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "getters" do
|
56
|
+
let(:response){ mock(:response, :body => '') }
|
57
|
+
before{ Semaphoreapp::Api.stub(:send_request).and_return(response) }
|
58
|
+
before{ Semaphoreapp.stub(:auth_token).and_return('test_token') }
|
59
|
+
|
60
|
+
describe ".get_projects" do
|
61
|
+
it "should send a request to projects_url" do
|
62
|
+
Semaphoreapp::Api.should_receive(:projects_url).and_return('projects_url')
|
63
|
+
Semaphoreapp::Api.should_receive(:send_request).with('projects_url').and_return(response)
|
64
|
+
|
65
|
+
Semaphoreapp::Api.get_projects
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should not overwrite the auth_token" do
|
69
|
+
Semaphoreapp::Api.should_receive(:set_auth_token).with({})
|
70
|
+
Semaphoreapp::Api.get_projects
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with auth_token" do
|
74
|
+
it "should set the auth_token" do
|
75
|
+
Semaphoreapp::Api.should_receive(:set_auth_token).with(hash_including(:auth_token => 'test_token'))
|
76
|
+
Semaphoreapp::Api.get_projects(:auth_token => 'test_token')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe ".get_branches" do
|
82
|
+
it "should send a request to branches_url" do
|
83
|
+
Semaphoreapp::Api.should_receive(:branches_url).with(':hash_id').and_return('branches_url')
|
84
|
+
Semaphoreapp::Api.should_receive(:send_request).with('branches_url').and_return(response)
|
85
|
+
|
86
|
+
Semaphoreapp::Api.get_branches(':hash_id')
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should not overwrite the auth_token" do
|
90
|
+
Semaphoreapp::Api.should_receive(:set_auth_token).with({})
|
91
|
+
Semaphoreapp::Api.get_branches(':hash_id')
|
92
|
+
end
|
93
|
+
|
94
|
+
context "with auth_token" do
|
95
|
+
it "should set the auth_token" do
|
96
|
+
Semaphoreapp::Api.should_receive(:set_auth_token).with(hash_including(:auth_token => 'test_token'))
|
97
|
+
Semaphoreapp::Api.get_branches(':hash_id', :auth_token => 'test_token')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe ".get_branch_history" do
|
103
|
+
it "should send a request to branch_history_url" do
|
104
|
+
Semaphoreapp::Api.should_receive(:branch_history_url).with(':hash_id', ':id', {}).and_return('branch_history_url')
|
105
|
+
Semaphoreapp::Api.should_receive(:send_request).with('branch_history_url').and_return(response)
|
106
|
+
|
107
|
+
Semaphoreapp::Api.get_branch_history(':hash_id', ':id')
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should not overwrite the auth_token" do
|
111
|
+
Semaphoreapp::Api.should_receive(:set_auth_token).with({})
|
112
|
+
Semaphoreapp::Api.get_branch_history(':hash_id', ':id')
|
113
|
+
end
|
114
|
+
|
115
|
+
context "with auth_token" do
|
116
|
+
it "should set the auth_token" do
|
117
|
+
Semaphoreapp::Api.should_receive(:set_auth_token).with(hash_including(:auth_token => 'test_token'))
|
118
|
+
Semaphoreapp::Api.get_branch_history(':hash_id', ':id', :auth_token => 'test_token')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "with page" do
|
123
|
+
it "should request the specified page" do
|
124
|
+
Semaphoreapp::Api.should_receive(:branch_history_url).with(':hash_id', ':id', :page => ':page').and_return('branch_history_url')
|
125
|
+
Semaphoreapp::Api.get_branch_history(':hash_id', ':id', :page => ':page')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe ".get_branch_status" do
|
131
|
+
it "should send a request to branch_status_url" do
|
132
|
+
Semaphoreapp::Api.should_receive(:branch_status_url).with(':hash_id', ':id').and_return('branch_status_url')
|
133
|
+
Semaphoreapp::Api.should_receive(:send_request).with('branch_status_url').and_return(response)
|
134
|
+
|
135
|
+
Semaphoreapp::Api.get_branch_status(':hash_id', ':id')
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should not overwrite the auth_token" do
|
139
|
+
Semaphoreapp::Api.should_receive(:set_auth_token).with({})
|
140
|
+
Semaphoreapp::Api.get_branch_status(':hash_id', ':id')
|
141
|
+
end
|
142
|
+
|
143
|
+
context "with auth_token" do
|
144
|
+
it "should set the auth_token" do
|
145
|
+
Semaphoreapp::Api.should_receive(:set_auth_token).with(hash_including(:auth_token => 'test_token'))
|
146
|
+
Semaphoreapp::Api.get_branch_status(':hash_id', ':id', :auth_token => 'test_token')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Semaphoreapp::Branch do
|
4
|
+
let(:project_hash_id) { ':hash_id' }
|
5
|
+
|
6
|
+
describe ".build" do
|
7
|
+
|
8
|
+
context "with a hash" do
|
9
|
+
|
10
|
+
let(:test_hash){ fixture(:branches).first }
|
11
|
+
|
12
|
+
subject{ Semaphoreapp::Branch.build(test_hash, project_hash_id) }
|
13
|
+
|
14
|
+
it "should call build_from_hash" do
|
15
|
+
Semaphoreapp::Branch.should_receive(:build_from_hash).with(test_hash, project_hash_id)
|
16
|
+
subject
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with an array" do
|
22
|
+
|
23
|
+
let(:test_array){ fixture(:branches) }
|
24
|
+
subject{ Semaphoreapp::Branch.build(test_array, project_hash_id) }
|
25
|
+
|
26
|
+
it "should call build_from_array" do
|
27
|
+
Semaphoreapp::Branch.should_receive(:build_from_array).with(test_array, project_hash_id)
|
28
|
+
subject
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".build_from_hash" do
|
36
|
+
|
37
|
+
let(:test_hash){ fixture(:branches).first }
|
38
|
+
subject{ Semaphoreapp::Branch.build_from_hash(test_hash, project_hash_id) }
|
39
|
+
|
40
|
+
it{ should be_an_instance_of Semaphoreapp::Branch }
|
41
|
+
|
42
|
+
fixture(:branches).first.each do |key, value|
|
43
|
+
it "should have attribute #{key}" do
|
44
|
+
subject.send(key).should == value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
describe ".build_from_array" do
|
51
|
+
|
52
|
+
let(:test_array){ fixture(:branches) }
|
53
|
+
subject{ Semaphoreapp::Branch.build_from_array(test_array, project_hash_id) }
|
54
|
+
|
55
|
+
it{ should be_an_instance_of Array }
|
56
|
+
|
57
|
+
it "should call build_from_hash for all the hashes in the array" do
|
58
|
+
test_array.each do |test_hash|
|
59
|
+
Semaphoreapp::Branch.should_receive(:build_from_hash).with(test_hash, project_hash_id)
|
60
|
+
end
|
61
|
+
|
62
|
+
subject
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe ".all_by_project_hash_id" do
|
68
|
+
|
69
|
+
let(:hash_id) { ':hash_id' }
|
70
|
+
let(:branches) { fixture(:branches) }
|
71
|
+
before{ Semaphoreapp::JsonApi.stub(:get_branches).and_return(branches) }
|
72
|
+
subject{ Semaphoreapp::Branch.all_by_project_hash_id(hash_id) }
|
73
|
+
|
74
|
+
it{ should be_an_instance_of Array }
|
75
|
+
|
76
|
+
it "should get branches JSON from the API" do
|
77
|
+
Semaphoreapp::JsonApi.should_receive(:get_branches).with(hash_id)
|
78
|
+
subject
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should call Branch.build with an array of branches" do
|
82
|
+
Semaphoreapp::Branch.should_receive(:build).with(branches, hash_id)
|
83
|
+
subject
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
describe ".find" do
|
89
|
+
|
90
|
+
let(:branches){ Semaphoreapp::Branch.build(fixture(:branches), ':hash_id') }
|
91
|
+
let(:expected_branch) { branches.first }
|
92
|
+
before{ Semaphoreapp::Branch.stub(:all_by_project_hash_id).with(':hash_id').and_return(branches) }
|
93
|
+
subject{ Semaphoreapp::Branch.find(':hash_id', expected_branch.id) }
|
94
|
+
|
95
|
+
it{ should be_an_instance_of Semaphoreapp::Branch }
|
96
|
+
it "should return the Branch object with the specified branch_id" do
|
97
|
+
subject.should == expected_branch
|
98
|
+
end
|
99
|
+
|
100
|
+
context "with the wrong branch_id" do
|
101
|
+
subject{ Semaphoreapp::Branch.find(':hash_id', ':wrong_id') }
|
102
|
+
it{ should be_nil }
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
describe ".find_by_name" do
|
108
|
+
|
109
|
+
let(:branches){ Semaphoreapp::Branch.build(fixture(:branches), ':hash_id') }
|
110
|
+
let(:expected_branch) { branches.first }
|
111
|
+
before{ Semaphoreapp::Branch.stub(:all_by_project_hash_id).with(':hash_id').and_return(branches) }
|
112
|
+
subject{ Semaphoreapp::Branch.find_by_name(':hash_id', expected_branch.name) }
|
113
|
+
|
114
|
+
it{ should be_an_instance_of Semaphoreapp::Branch }
|
115
|
+
it "should return the Branch object with the specified name" do
|
116
|
+
subject.should == expected_branch
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with the wrong name" do
|
120
|
+
subject{ Semaphoreapp::Branch.find_by_name(':hash_id', ':wrong_name') }
|
121
|
+
it{ should be_nil }
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
describe ".find_master" do
|
127
|
+
subject{ Semaphoreapp::Branch.find_master(':hash_id') }
|
128
|
+
|
129
|
+
it "should find the branch named 'master'" do
|
130
|
+
Semaphoreapp::Branch.should_receive(:find_by_name).with(anything(), 'master')
|
131
|
+
subject
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Semaphoreapp::BranchStatus do
|
4
|
+
|
5
|
+
describe ".build" do
|
6
|
+
|
7
|
+
context "with a hash" do
|
8
|
+
|
9
|
+
let(:test_hash){ fixture(:branch_statuses).first }
|
10
|
+
subject{ Semaphoreapp::BranchStatus.build(test_hash) }
|
11
|
+
|
12
|
+
it "should call build_from_hash" do
|
13
|
+
Semaphoreapp::BranchStatus.should_receive(:build_from_hash).with(test_hash)
|
14
|
+
subject
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with an array" do
|
20
|
+
|
21
|
+
let(:test_array){ fixture(:branch_statuses) }
|
22
|
+
subject{ Semaphoreapp::BranchStatus.build(test_array) }
|
23
|
+
|
24
|
+
it "should call build_from_array" do
|
25
|
+
Semaphoreapp::BranchStatus.should_receive(:build_from_array).with(test_array)
|
26
|
+
subject
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".build_from_hash" do
|
34
|
+
|
35
|
+
let(:test_hash){ fixture(:branch_statuses).first }
|
36
|
+
subject{ Semaphoreapp::BranchStatus.build_from_hash(test_hash) }
|
37
|
+
|
38
|
+
it{ should be_an_instance_of Semaphoreapp::BranchStatus }
|
39
|
+
|
40
|
+
fixture(:branch_statuses).first.reject{ |key| key == 'commit' }.each do |key, value|
|
41
|
+
it "should have attribute #{key}" do
|
42
|
+
subject.send(key).should == value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with a commit" do
|
47
|
+
it "should have a Commit object as the commit attribute" do
|
48
|
+
subject.commit.should be_an_instance_of Semaphoreapp::Commit
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "without a commit" do
|
53
|
+
before{ test_hash.delete('commit') }
|
54
|
+
it "should set the commit attribute to nil" do
|
55
|
+
subject.commit.should be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe ".build_from_array" do
|
62
|
+
|
63
|
+
let(:test_array){ fixture(:branch_statuses) }
|
64
|
+
subject{ Semaphoreapp::BranchStatus.build_from_array(test_array) }
|
65
|
+
|
66
|
+
it{ should be_an_instance_of Array }
|
67
|
+
|
68
|
+
it "should call build_from_hash for all the hashes in the array" do
|
69
|
+
test_array.each do |test_hash|
|
70
|
+
Semaphoreapp::BranchStatus.should_receive(:build_from_hash).with(test_hash)
|
71
|
+
end
|
72
|
+
|
73
|
+
subject
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Semaphoreapp::Build do
|
4
|
+
|
5
|
+
describe ".build" do
|
6
|
+
|
7
|
+
context "with a hash" do
|
8
|
+
|
9
|
+
let(:test_hash){ fixture(:builds).first }
|
10
|
+
subject{ Semaphoreapp::Build.build(test_hash) }
|
11
|
+
|
12
|
+
it "should call build_from_hash" do
|
13
|
+
Semaphoreapp::Build.should_receive(:build_from_hash).with(test_hash)
|
14
|
+
subject
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with an array" do
|
20
|
+
|
21
|
+
let(:test_array){ fixture(:builds) }
|
22
|
+
subject{ Semaphoreapp::Build.build(test_array) }
|
23
|
+
|
24
|
+
it "should call build_from_array" do
|
25
|
+
Semaphoreapp::Build.should_receive(:build_from_array).with(test_array)
|
26
|
+
subject
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".build_from_hash" do
|
34
|
+
|
35
|
+
let(:test_hash){ fixture(:builds).first }
|
36
|
+
subject{ Semaphoreapp::Build.build_from_hash(test_hash) }
|
37
|
+
|
38
|
+
it{ should be_an_instance_of Semaphoreapp::Build }
|
39
|
+
|
40
|
+
fixture(:builds).first.reject{ |key| key == 'commit' }.each do |key, value|
|
41
|
+
it "should have attribute #{key}" do
|
42
|
+
subject.send(key).should == value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with a commit" do
|
47
|
+
it "should have a Commit object as the commit attribute" do
|
48
|
+
subject.commit.should be_an_instance_of Semaphoreapp::Commit
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "without a commit" do
|
53
|
+
before{ test_hash.delete('commit') }
|
54
|
+
it "should set the commit attribute to nil" do
|
55
|
+
subject.commit.should be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe ".build_from_array" do
|
62
|
+
|
63
|
+
let(:test_array){ fixture(:builds) }
|
64
|
+
subject{ Semaphoreapp::Build.build_from_array(test_array) }
|
65
|
+
|
66
|
+
it{ should be_an_instance_of Array }
|
67
|
+
|
68
|
+
it "should call build_from_hash for all the hashes in the array" do
|
69
|
+
test_array.each do |test_hash|
|
70
|
+
Semaphoreapp::Build.should_receive(:build_from_hash).with(test_hash)
|
71
|
+
end
|
72
|
+
|
73
|
+
subject
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Semaphoreapp::Commit do
|
4
|
+
|
5
|
+
describe ".build" do
|
6
|
+
|
7
|
+
let(:test_hash){ fixture(:commit) }
|
8
|
+
subject{ Semaphoreapp::Commit.build(test_hash) }
|
9
|
+
|
10
|
+
it{ should be_an_instance_of Semaphoreapp::Commit }
|
11
|
+
|
12
|
+
fixture(:commit).each do |key, value|
|
13
|
+
it "should have attribute #{key}" do
|
14
|
+
subject.send(key).should == value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Semaphoreapp::JsonApi do
|
4
|
+
|
5
|
+
describe ".raise_if_error" do
|
6
|
+
context "with an error" do
|
7
|
+
let(:error){ {'error' => 'error message'} }
|
8
|
+
subject{ Semaphoreapp::JsonApi.raise_if_error(error) }
|
9
|
+
|
10
|
+
it{ expect{ subject }.to raise_error Semaphoreapp::Api::Error }
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with no error" do
|
14
|
+
let(:obj){ Object.new }
|
15
|
+
subject{ Semaphoreapp::JsonApi.raise_if_error(obj) }
|
16
|
+
|
17
|
+
it{ expect{ subject }.not_to raise_error Semaphoreapp::Api::Error }
|
18
|
+
|
19
|
+
it "should return its parameter without changes" do
|
20
|
+
subject.should == obj
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Semaphoreapp::Project do
|
4
|
+
|
5
|
+
describe ".build" do
|
6
|
+
|
7
|
+
context "with a hash" do
|
8
|
+
|
9
|
+
let(:test_hash){ fixture(:projects).first }
|
10
|
+
|
11
|
+
subject{ Semaphoreapp::Project.build(test_hash) }
|
12
|
+
|
13
|
+
it "should call build_from_hash" do
|
14
|
+
Semaphoreapp::Project.should_receive(:build_from_hash).with(test_hash)
|
15
|
+
subject
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with an array" do
|
21
|
+
|
22
|
+
let(:test_array){ fixture(:projects) }
|
23
|
+
subject{ Semaphoreapp::Project.build(test_array) }
|
24
|
+
|
25
|
+
it "should call build_from_array" do
|
26
|
+
Semaphoreapp::Project.should_receive(:build_from_array).with(test_array)
|
27
|
+
subject
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe ".build_from_hash" do
|
35
|
+
|
36
|
+
let(:test_hash){ fixture(:projects).first }
|
37
|
+
subject{ Semaphoreapp::Project.build_from_hash(test_hash) }
|
38
|
+
|
39
|
+
it{ should be_an_instance_of Semaphoreapp::Project }
|
40
|
+
|
41
|
+
fixture(:projects).first.reject{ |key| key == 'branches' }.each do |key, value|
|
42
|
+
it "should have attribute #{key}" do
|
43
|
+
subject.send(key).should == value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with branch statuses" do
|
48
|
+
it "should have an array of BranchStatus object as the 'branches' attribute" do
|
49
|
+
subject.branches.should be_an_instance_of Array
|
50
|
+
subject.branches.each{ |branch| branch.should be_an_instance_of Semaphoreapp::BranchStatus }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "without branch statuses" do
|
55
|
+
before{ test_hash.delete('branches') }
|
56
|
+
it "should set the 'branches' attribute to nil" do
|
57
|
+
subject.branches.should be_nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe ".build_from_array" do
|
64
|
+
|
65
|
+
let(:test_array){ fixture(:projects) }
|
66
|
+
subject{ Semaphoreapp::Project.build_from_array(test_array) }
|
67
|
+
|
68
|
+
it{ should be_an_instance_of Array }
|
69
|
+
|
70
|
+
it "should call build_from_hash for all the hashes in the array" do
|
71
|
+
test_array.each do |test_hash|
|
72
|
+
Semaphoreapp::Project.should_receive(:build_from_hash).with(test_hash)
|
73
|
+
end
|
74
|
+
|
75
|
+
subject
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.unshift File.realpath File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
|
3
|
+
require 'semaphoreapp'
|
4
|
+
|
5
|
+
def json_fixture(name)
|
6
|
+
File.read File.join(File.dirname(__FILE__), 'fixtures', "#{name.to_s}.json")
|
7
|
+
end
|
8
|
+
|
9
|
+
def fixture(name)
|
10
|
+
JSON.parse(json_fixture(name))
|
11
|
+
end
|
12
|
+
|
13
|
+
# See: http://stackoverflow.com/a/7364289/551557
|
14
|
+
RSpec.configure do |config|
|
15
|
+
# Use color in STDOUT
|
16
|
+
config.color_enabled = true
|
17
|
+
|
18
|
+
# Use color not only in STDOUT but also in pagers and files
|
19
|
+
config.tty = true
|
20
|
+
|
21
|
+
# Use the specified formatter
|
22
|
+
config.formatter = :documentation # :progress, :html, :textmate
|
23
|
+
end
|