buildbox 0.0.4 → 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,28 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'running a build' do
4
6
  let(:commit) { "3e0c65433b241ff2c59220f80bcdcd2ebb7e4b96" }
5
7
  let(:command) { "rspec test_spec.rb" }
6
- let(:build) { Buildbox::Build.new(:project_id => 1, :build_id => 1, :repository => FIXTURES_PATH.join("repo.git").to_s, :commit => commit, :command => command) }
8
+ let(:env) { { } }
9
+ let(:build) { Buildbox::Build.new(:project => { :name => "test", :team => { :name => "test" } }, :number => 1, :script => script, :env => env) }
10
+ let(:runner) { Buildbox::Runner.new(build) }
11
+ let(:script) do
12
+ <<-SCRIPT
13
+ #/bin/bash
14
+ set -e
15
+ echo `pwd`
16
+ if [ ! -d ".git" ]; then
17
+ git clone "#{FIXTURES_PATH.join("repo.git").to_s}" ./ -q
18
+ fi
19
+ git clean -fd
20
+ git fetch -q
21
+ git checkout -qf #{commit}
22
+ bundle install --local
23
+ #{command}
24
+ SCRIPT
25
+ end
7
26
 
8
27
  before do
9
28
  Buildbox.stub(:root_path).and_return(TEMP_PATH)
@@ -15,10 +34,21 @@ describe 'running a build' do
15
34
 
16
35
  context 'running a working build' do
17
36
  it "returns a successfull result" do
18
- result = build.start
37
+ runner.start
38
+
39
+ build.should be_success
40
+ build.output.should =~ /1 example, 0 failures/
41
+ end
42
+ end
43
+
44
+ context 'running a working build with a semi colon in the command' do
45
+ let(:command) { "rspec test_spec.rb;" }
46
+
47
+ it "returns a successfull result" do
48
+ runner.start
19
49
 
20
- result.should be_success
21
- result.output.should =~ /1 example, 0 failures/
50
+ build.should be_success
51
+ build.output.should =~ /1 example, 0 failures/
22
52
  end
23
53
  end
24
54
 
@@ -26,10 +56,98 @@ describe 'running a build' do
26
56
  let(:commit) { "2d762cdfd781dc4077c9f27a18969efbd186363c" }
27
57
 
28
58
  it "returns a unsuccessfull result" do
29
- result = build.start
59
+ runner.start
60
+
61
+ build.should_not be_success
62
+ build.output.should =~ /1 example, 1 failure/
63
+ end
64
+ end
65
+
66
+ context 'running a failing build that has commands after the one that failed' do
67
+ let(:commit) { "2d762cdfd781dc4077c9f27a18969efbd186363c" }
68
+ let(:command) { "rspec test_spec.rb; echo 'oh no you didnt!'" }
69
+
70
+ it "returns a unsuccessfull result" do
71
+ runner.start
72
+
73
+ build.should_not be_success
74
+ build.output.should =~ /1 example, 1 failure/
75
+ end
76
+ end
77
+
78
+ context 'running a ruby script' do
79
+ let(:script) do
80
+ <<-SCRIPT
81
+ #!/usr/bin/env ruby
82
+ puts 'hello'
83
+ exit 123
84
+ SCRIPT
85
+ end
86
+
87
+ it "runs and returns the correct output" do
88
+ runner.start
89
+
90
+ build.output.should == 'hello'
91
+ build.exit_status.should == 123
92
+ end
93
+ end
94
+
95
+ context 'accessing ENV variables with a ruby script' do
96
+ let(:env) { { "FOO" => "great" } }
97
+ let(:script) do
98
+ <<-SCRIPT
99
+ #!/usr/bin/env ruby
100
+ puts ENV["FOO"]
101
+ SCRIPT
102
+ end
103
+
104
+ it "runs and returns the correct output" do
105
+ runner.start
106
+
107
+ build.output.should == 'great'
108
+ end
109
+ end
110
+
111
+ context 'accessing ENV variables with a bash script' do
112
+ let(:env) { { "BAR" => "great" } }
113
+ let(:script) do
114
+ <<-SCRIPT
115
+ echo $BAR
116
+ SCRIPT
117
+ end
118
+
119
+ it "runs and returns the correct output" do
120
+ runner.start
121
+
122
+ build.output.should == 'great'
123
+ end
124
+ end
125
+
126
+ context 'running a failing build that returns a non standard exit status' do
127
+ let(:command) { "exit 123" }
128
+
129
+ it "returns a unsuccessfull result" do
130
+ runner.start
30
131
 
31
- result.should_not be_success
32
- result.output.should =~ /1 example, 1 failure/
132
+ build.should_not be_success
133
+ build.exit_status.should == 123
134
+ end
135
+ end
136
+
137
+ context 'a build that has a command with a syntax error' do
138
+ let(:command) { 'if ( echo yay' }
139
+
140
+ it "returns a unsuccessfull result" do
141
+ runner.start
142
+
143
+ build.should_not be_success
144
+
145
+ # bash 3.2.48 prints "syntax error" in lowercase.
146
+ # freebsd 9.1 /bin/sh prints "Syntax error" with capital S.
147
+ # zsh 5.0.2 prints "parse error" which we do not handle.
148
+ # localized systems will print the message in not English which
149
+ # we do not handle either.
150
+ build.output.should =~ /(syntax|parse) error/i
33
151
  end
34
152
  end
35
153
 
@@ -37,25 +155,24 @@ describe 'running a build' do
37
155
  let(:command) { 'foobar' }
38
156
 
39
157
  it "returns a unsuccessfull result" do
40
- result = build.start
158
+ runner.start
41
159
 
42
- result.should_not be_success
160
+ build.should_not be_success
43
161
  # ubuntu: sh: 1: foobar: not found
44
162
  # osx: sh: foobar: command not found
45
- result.output.should =~ /foobar.+not found/
163
+ build.output.should =~ /foobar.+not found/
46
164
  end
47
165
  end
48
166
 
49
167
  context 'running multiple builds in a row' do
50
168
  it "returns a successfull result when the build passes" do
51
- first_result = build.start
52
- second_result = build.start
53
-
54
- first_result.should be_success
55
- first_result.output.should =~ /1 example, 0 failures/
169
+ runner.start
170
+ build.should be_success
171
+ build.output.should =~ /1 example, 0 failures/
56
172
 
57
- second_result.should be_success
58
- second_result.output.should =~ /1 example, 0 failures/
173
+ runner.start
174
+ build.should be_success
175
+ build.output.should =~ /1 example, 0 failures/
59
176
  end
60
177
  end
61
178
 
@@ -63,12 +180,12 @@ describe 'running a build' do
63
180
  it "returns a successfull result" do
64
181
  result = nil
65
182
  thread = Thread.new do
66
- result = build.start
183
+ result = runner.start
67
184
  end
68
185
  thread.join
69
186
 
70
- result.should be_success
71
- result.output.should =~ /1 example, 0 failures/
187
+ build.should be_success
188
+ build.output.should =~ /1 example, 0 failures/
72
189
  end
73
190
  end
74
191
 
@@ -78,12 +195,12 @@ describe 'running a build' do
78
195
  it "returns a successfull result" do
79
196
  result = nil
80
197
  thread = Thread.new do
81
- result = build.start
198
+ result = runner.start
82
199
  end
83
200
  thread.join
84
201
 
85
- result.should_not be_success
86
- result.output.should =~ /1 example, 1 failure/
202
+ build.should_not be_success
203
+ build.output.should =~ /1 example, 1 failure/
87
204
  end
88
205
  end
89
206
  end
@@ -1,7 +1,12 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'logger'
4
+ require 'celluloid'
5
+
1
6
  RSpec.configure do |config|
2
7
  config.before(:each) do
3
8
  logger = Logger.new(StringIO.new)
4
9
 
5
- Buildbox.stub(:logger => logger)
10
+ Celluloid.logger = logger
6
11
  end
7
12
  end
@@ -0,0 +1 @@
1
+ require 'webmock/rspec'
metadata CHANGED
@@ -1,71 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: '0.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Pitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-15 00:00:00.000000000 Z
11
+ date: 2013-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
20
- type: :development
19
+ version: '0.8'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0.8'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: faraday_middleware
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
47
+ version: '2.0'
48
+ type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - '>='
52
+ - - ~>
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: '2.0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: rspec
56
+ name: multi_json
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - '>='
59
+ - - ~>
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
61
+ version: '1.7'
62
+ type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - '>='
66
+ - - ~>
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: '1.7'
55
69
  - !ruby/object:Gem::Dependency
56
- name: dotenv
70
+ name: celluloid
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - '>='
73
+ - - ~>
60
74
  - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
75
+ version: '0.14'
76
+ type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - '>='
80
+ - - ~>
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: '0.14'
69
83
  description: Ruby client for buildbox
70
84
  email:
71
85
  - me@keithpitt.com
@@ -74,10 +88,11 @@ executables:
74
88
  extensions: []
75
89
  extra_rdoc_files: []
76
90
  files:
77
- - .buildbox.toml
78
91
  - .gitignore
79
92
  - .rspec
93
+ - .ruby-version
80
94
  - Gemfile
95
+ - Gemfile.lock
81
96
  - LICENSE.txt
82
97
  - README.md
83
98
  - Rakefile
@@ -85,22 +100,17 @@ files:
85
100
  - buildbox-ruby.gemspec
86
101
  - lib/buildbox.rb
87
102
  - lib/buildbox/api.rb
88
- - lib/buildbox/auth.rb
89
103
  - lib/buildbox/build.rb
90
- - lib/buildbox/client.rb
104
+ - lib/buildbox/cli.rb
91
105
  - lib/buildbox/command.rb
92
106
  - lib/buildbox/configuration.rb
93
- - lib/buildbox/observer.rb
94
- - lib/buildbox/pid_file.rb
95
- - lib/buildbox/response.rb
96
- - lib/buildbox/result.rb
107
+ - lib/buildbox/environment.rb
108
+ - lib/buildbox/monitor.rb
109
+ - lib/buildbox/runner.rb
97
110
  - lib/buildbox/utf8.rb
98
111
  - lib/buildbox/version.rb
99
112
  - lib/buildbox/worker.rb
100
- - spec/buildbox/buildbox/build_spec.rb
101
113
  - spec/buildbox/buildbox/command_spec.rb
102
- - spec/buildbox/buildbox/configuration_spec.rb
103
- - spec/buildbox/buildbox_spec.rb
104
114
  - spec/fixtures/repo.git/HEAD
105
115
  - spec/fixtures/repo.git/config
106
116
  - spec/fixtures/repo.git/description
@@ -124,8 +134,8 @@ files:
124
134
  - spec/fixtures/rspec/test_spec.rb
125
135
  - spec/integration/running_a_build_spec.rb
126
136
  - spec/spec_helper.rb
127
- - spec/support/dotenv.rb
128
137
  - spec/support/silence_logger.rb
138
+ - spec/support/webmock.rb
129
139
  homepage: ''
130
140
  licenses:
131
141
  - MIT
@@ -146,15 +156,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
156
  version: '0'
147
157
  requirements: []
148
158
  rubyforge_project:
149
- rubygems_version: 2.0.0
159
+ rubygems_version: 2.0.3
150
160
  signing_key:
151
161
  specification_version: 4
152
162
  summary: Ruby client for buildbox
153
163
  test_files:
154
- - spec/buildbox/buildbox/build_spec.rb
155
164
  - spec/buildbox/buildbox/command_spec.rb
156
- - spec/buildbox/buildbox/configuration_spec.rb
157
- - spec/buildbox/buildbox_spec.rb
158
165
  - spec/fixtures/repo.git/HEAD
159
166
  - spec/fixtures/repo.git/config
160
167
  - spec/fixtures/repo.git/description
@@ -178,5 +185,5 @@ test_files:
178
185
  - spec/fixtures/rspec/test_spec.rb
179
186
  - spec/integration/running_a_build_spec.rb
180
187
  - spec/spec_helper.rb
181
- - spec/support/dotenv.rb
182
188
  - spec/support/silence_logger.rb
189
+ - spec/support/webmock.rb
@@ -1,2 +0,0 @@
1
- [build]
2
- commands = [ "bundle", "rspec" ]
@@ -1,37 +0,0 @@
1
- module Buildbox
2
- class Auth
3
- def login(options)
4
- if Buildbox.configuration.api_key
5
- error "You have already authentication. To unauthenticate, run `buildbox auth:logout`"
6
- end
7
-
8
- key = options[:api_key]
9
- api = Buildbox::API.new(:api_key => key)
10
-
11
- if api.login.success?
12
- Buildbox.configuration.update :api_key, key
13
- info "Authentication successful"
14
- end
15
- end
16
-
17
- def logout
18
- if Buildbox.configuration.api_key.nil?
19
- error "You are currently not logged in. To authenticate, run: `buildbox auth:login`"
20
- end
21
-
22
- Buildbox.configuration.update :api_key, nil
23
- info "You have successfuly logged out"
24
- end
25
-
26
- private
27
-
28
- def info(message)
29
- Buildbox.logger.info message
30
- end
31
-
32
- def error(message)
33
- Buildbox.logger.error message
34
- exit 1
35
- end
36
- end
37
- end