joshuapinter-cijoe 0.9.3

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.
@@ -0,0 +1,128 @@
1
+ require "helper"
2
+ require "rack/test"
3
+ require "cijoe/server"
4
+
5
+ class TestCIJoeServer < Test::Unit::TestCase
6
+ include Rack::Test::Methods
7
+
8
+ class ::CIJoe
9
+ attr_writer :current_build, :last_build
10
+ end
11
+
12
+ attr_accessor :app
13
+
14
+ def setup
15
+ @app = CIJoe::Server.new
16
+ joe = @app.joe
17
+
18
+ # make Build#restore a no-op so we don't overwrite our current/last
19
+ # build attributes set from tests.
20
+ def joe.restore
21
+ end
22
+
23
+ # make CIJoe#build! and CIJoe#git_update a no-op so we don't overwrite our local changes
24
+ # or local commits nor should we run tests.
25
+ def joe.build!
26
+ end
27
+ end
28
+
29
+ def test_ping
30
+ app.joe.last_build = build :worked
31
+ assert !app.joe.building?, "have a last build, but not a current"
32
+
33
+ get "/ping"
34
+ assert_equal 200, last_response.status
35
+ assert_equal app.joe.last_build.sha, last_response.body
36
+ end
37
+
38
+ def test_ping_building
39
+ app.joe.current_build = build :building
40
+ assert app.joe.building?, "buildin' a awsum project"
41
+
42
+ get "/ping"
43
+ assert_equal 412, last_response.status
44
+ assert_equal "building", last_response.body
45
+ end
46
+
47
+ def test_ping_building_with_a_previous_build
48
+ app.joe.last_build = build :worked
49
+ app.joe.current_build = build :building
50
+ assert app.joe.building?, "buildin' a awsum project"
51
+
52
+ get "/ping"
53
+ assert_equal 412, last_response.status
54
+ assert_equal "building", last_response.body
55
+ end
56
+
57
+ def test_ping_failed
58
+ app.joe.last_build = build :failed
59
+
60
+ get "/ping"
61
+ assert_equal 412, last_response.status
62
+ assert_equal app.joe.last_build.sha, last_response.body
63
+ end
64
+
65
+ def test_ping_should_not_reset_current_build_in_tests
66
+ current_build = build :building
67
+ app.joe.current_build = current_build
68
+ assert app.joe.building?
69
+ get "/ping"
70
+ assert_equal current_build, app.joe.current_build
71
+ end
72
+
73
+ def test_post_with_json_works
74
+ post '/', :payload => File.read("#{Dir.pwd}/test/fixtures/payload.json")
75
+ assert app.joe.building?
76
+ assert_equal 302, last_response.status
77
+ end
78
+
79
+ def test_post_does_not_build_on_branch_mismatch
80
+ post "/", :payload => {"ref" => "refs/heads/dont_build"}.to_json
81
+ assert !app.joe.building?
82
+ assert_equal 302, last_response.status
83
+ end
84
+
85
+ def test_post_builds_specific_branch
86
+ app.joe.expects(:build!).with("branchname")
87
+ post "/?branch=branchname", :payload => {"ref" => "refs/heads/master"}.to_json
88
+ assert app.joe.building?
89
+ assert_equal 302, last_response.status
90
+ end
91
+
92
+ def test_post_does_build_on_branch_match
93
+ post "/", :payload => {"ref" => "refs/heads/master"}.to_json
94
+ assert app.joe.building?
95
+ assert_equal 302, last_response.status
96
+ end
97
+
98
+ def test_post_does_build_when_build_button_is_used
99
+ post "/", :rebuild => true
100
+ assert app.joe.building?
101
+ assert_equal 302, last_response.status
102
+ end
103
+
104
+ def test_jsonp_should_return_plain_json_without_param
105
+ app.joe.last_build = build :failed
106
+ get "/api/json"
107
+ assert_equal 200, last_response.status
108
+ assert_equal 'application/json', last_response.content_type
109
+ end
110
+
111
+ def test_jsonp_should_return_jsonp_with_param
112
+ app.joe.last_build = build :failed
113
+ get "/api/json?jsonp=fooberz"
114
+ assert_equal 200, last_response.status
115
+ assert_equal 'application/json', last_response.content_type
116
+ assert_match /^fooberz\(/, last_response.body
117
+ end
118
+
119
+ def test_should_not_barf_when_no_build
120
+ end
121
+
122
+ # Create a new, fake build. All we care about is status.
123
+
124
+ def build status
125
+ CIJoe::Build.new "path", "user", "project", Time.now, Time.now,
126
+ "deadbeef", status, "output", nil
127
+ end
128
+ end
@@ -0,0 +1,81 @@
1
+ require 'helper'
2
+
3
+ # mock files to true
4
+ class File
5
+ class << self
6
+ alias orig_exists? exists?
7
+ alias orig_executable? executable?
8
+
9
+ def exists?(f)
10
+ return true if $hook_override
11
+ orig_exists? f
12
+ end
13
+ def executable?(f)
14
+ return true if $hook_override
15
+ orig_executable? f
16
+ end
17
+ end
18
+ end
19
+
20
+ # #mock file to be the file I want
21
+ class CIJoe
22
+ attr_writer :last_build
23
+ alias orig_path_in_project path_in_project
24
+ alias orig_git_user_and_project git_user_and_project
25
+
26
+ def path_in_project(f)
27
+ return '/tmp/test' if $hook_override
28
+ orig_path_in_project
29
+ end
30
+
31
+ def git_user_and_project
32
+ return ['mine','yours'] if $hook_override
33
+ orig_git_user_and_project
34
+ end
35
+ end
36
+
37
+ class CIJoe::Commit
38
+ attr_writer :raw_commit
39
+ end
40
+
41
+
42
+
43
+ class TestHooks < Test::Unit::TestCase
44
+ def teardown
45
+ $hook_override = nil
46
+ end
47
+
48
+ def setup
49
+ $hook_override = true
50
+ open("/tmp/test",'w') do |file|
51
+ file.write "echo $test\n"
52
+ file.write "echo $AUTHOR\n"
53
+ file.write "export test=foo\n"
54
+ end
55
+ File.chmod(0777,'/tmp/test')
56
+
57
+ @cijoe = CIJoe.new('/tmp')
58
+ @cijoe.last_build = CIJoe::Build.new "path", "user", "project", Time.now, Time.now,
59
+ "deadbeef", :failed, "output", nil
60
+ @cijoe.last_build.commit.raw_commit = "Author: commit author\nDate: now"
61
+ end
62
+
63
+ def test_leave_env_intact
64
+ ENV['AUTHOR'] = 'foo'
65
+ @cijoe.run_hook("/tmp/test")
66
+ assert ENV.size != 0, 'ENV is empty but should not be'
67
+ assert ENV['AUTHOR'] == 'foo', 'ENV munged a value'
68
+ end
69
+
70
+ def test_empty_hook_env
71
+ ENV["test"] = 'should not be shown'
72
+ output = @cijoe.run_hook("/tmp/test")
73
+ assert_equal "\ncommit author\n", output
74
+ end
75
+
76
+ def test_hook_munge_env
77
+ ENV['test'] = 'bar'
78
+ output = @cijoe.run_hook("/tmp/test")
79
+ assert ENV['test'] == 'bar'
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: joshuapinter-cijoe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Wanstrath
9
+ - Josh Owens
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-02-25 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: choice
17
+ requirement: &70345878056200 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70345878056200
26
+ - !ruby/object:Gem::Dependency
27
+ name: sinatra
28
+ requirement: &70345878055780 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70345878055780
37
+ - !ruby/object:Gem::Dependency
38
+ name: json
39
+ requirement: &70345878055360 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *70345878055360
48
+ - !ruby/object:Gem::Dependency
49
+ name: tinder
50
+ requirement: &70345878054860 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 1.4.0
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *70345878054860
59
+ - !ruby/object:Gem::Dependency
60
+ name: rack-test
61
+ requirement: &70345878054440 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *70345878054440
70
+ - !ruby/object:Gem::Dependency
71
+ name: mocha
72
+ requirement: &70345878053980 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *70345878053980
81
+ description: ! " cijoe is a sinatra-based continuous integration server. It's like
82
+ an\n old rusty pickup truck: it might be smelly and gross, but it gets the\n job
83
+ done.\n"
84
+ email: chris@ozmm.org
85
+ executables:
86
+ - cijoe
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - README.md
91
+ - Rakefile
92
+ - LICENSE
93
+ - lib/cijoe/build.rb
94
+ - lib/cijoe/campfire.rb
95
+ - lib/cijoe/commit.rb
96
+ - lib/cijoe/config.rb
97
+ - lib/cijoe/public/favicon.ico
98
+ - lib/cijoe/public/octocat.png
99
+ - lib/cijoe/public/screen.css
100
+ - lib/cijoe/queue.rb
101
+ - lib/cijoe/server.rb
102
+ - lib/cijoe/version.rb
103
+ - lib/cijoe/views/json.erb
104
+ - lib/cijoe/views/template.erb
105
+ - lib/cijoe.rb
106
+ - bin/cijoe
107
+ - test/fixtures/payload.json
108
+ - test/helper.rb
109
+ - test/test_campfire.rb
110
+ - test/test_cijoe.rb
111
+ - test/test_cijoe_queue.rb
112
+ - test/test_cijoe_server.rb
113
+ - test/test_hooks.rb
114
+ homepage: http://github.com/joshuapinter/cijoe
115
+ licenses: []
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 1.8.10
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: cijoe builds your builds.
138
+ test_files: []
139
+ has_rdoc: false