buildlights 0.0.2 → 0.0.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.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  coverage
4
4
  rdoc
5
5
  pkg
6
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :gemcutter
2
+
3
+ gem "hpricot", "0.8.1"
4
+ gem "simple-rss", "1.2"
5
+
6
+ group :test do
7
+ gem "rspec", "1.3.0"
8
+ end
data/Rakefile CHANGED
@@ -11,49 +11,36 @@ begin
11
11
  gem.homepage = "http://github.com/darrinholst/buildlights"
12
12
  gem.authors = ["Darrin Holst"]
13
13
  gem.rubyforge_project = "buildlights"
14
- gem.add_dependency("simple-rss", ">= 1.2")
15
- gem.add_dependency("hpricot", ">= 0.8.1")
14
+ gem.add_development_dependency "rspec", ">= 1.2.9"
15
+ gem.add_dependency "simple-rss", ">= 1.2"
16
+ gem.add_dependency "hpricot", ">= 0.8.1"
16
17
  end
17
18
 
18
- Jeweler::RubyforgeTasks.new
19
+ Jeweler::GemcutterTasks.new
19
20
  rescue LoadError
20
21
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
22
  end
22
23
 
23
- require 'rake/testtask'
24
- Rake::TestTask.new(:test) do |test|
25
- test.libs << 'lib' << 'test'
26
- test.pattern = 'test/**/*_test.rb'
27
- test.verbose = true
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
28
  end
29
29
 
30
- begin
31
- require 'rcov/rcovtask'
32
- Rcov::RcovTask.new do |test|
33
- test.libs << 'test'
34
- test.pattern = 'test/**/*_test.rb'
35
- test.verbose = true
36
- end
37
- rescue LoadError
38
- task :rcov do
39
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
- end
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
41
34
  end
42
35
 
43
-
44
- task :default => :test
36
+ task :default => :spec
45
37
 
46
38
  require 'rake/rdoctask'
47
39
  Rake::RDocTask.new do |rdoc|
48
- if File.exist?('VERSION.yml')
49
- config = YAML.load(File.read('VERSION.yml'))
50
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
51
- else
52
- version = ""
53
- end
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
54
41
 
55
42
  rdoc.rdoc_dir = 'rdoc'
56
- rdoc.title = "build-lights #{version}"
43
+ rdoc.title = "foo #{version}"
57
44
  rdoc.rdoc_files.include('README*')
58
45
  rdoc.rdoc_files.include('lib/**/*.rb')
59
46
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/buildlights.gemspec CHANGED
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{buildlights}
5
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Darrin Holst"]
9
- s.date = %q{2009-08-13}
12
+ s.date = %q{2010-04-16}
10
13
  s.default_executable = %q{buildlights}
11
14
  s.email = %q{darrinholst@gmail.com}
12
15
  s.executables = ["buildlights"]
@@ -17,6 +20,7 @@ Gem::Specification.new do |s|
17
20
  s.files = [
18
21
  ".document",
19
22
  ".gitignore",
23
+ "Gemfile",
20
24
  "LICENSE",
21
25
  "README.rdoc",
22
26
  "Rakefile",
@@ -27,22 +31,22 @@ Gem::Specification.new do |s|
27
31
  "lib/ccnet.rb",
28
32
  "lib/hudson.rb",
29
33
  "lib/lights.rb",
30
- "test/ccnet_test.rb",
31
- "test/hudson_test.rb",
32
- "test/lights_test.rb",
33
- "test/test_helper.rb"
34
+ "spec/lib/ccnet_spec.rb",
35
+ "spec/lib/hudson_spec.rb",
36
+ "spec/lib/lights_spec.rb",
37
+ "spec/spec_helper.rb"
34
38
  ]
35
39
  s.homepage = %q{http://github.com/darrinholst/buildlights}
36
40
  s.rdoc_options = ["--charset=UTF-8"]
37
41
  s.require_paths = ["lib"]
38
42
  s.rubyforge_project = %q{buildlights}
39
- s.rubygems_version = %q{1.3.5}
43
+ s.rubygems_version = %q{1.3.6}
40
44
  s.summary = %q{build monitor that will trigger lights via x10}
41
45
  s.test_files = [
42
- "test/ccnet_test.rb",
43
- "test/hudson_test.rb",
44
- "test/lights_test.rb",
45
- "test/test_helper.rb"
46
+ "spec/lib/ccnet_spec.rb",
47
+ "spec/lib/hudson_spec.rb",
48
+ "spec/lib/lights_spec.rb",
49
+ "spec/spec_helper.rb"
46
50
  ]
47
51
 
48
52
  if s.respond_to? :specification_version then
@@ -50,14 +54,18 @@ Gem::Specification.new do |s|
50
54
  s.specification_version = 3
51
55
 
52
56
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
53
58
  s.add_runtime_dependency(%q<simple-rss>, [">= 1.2"])
54
59
  s.add_runtime_dependency(%q<hpricot>, [">= 0.8.1"])
55
60
  else
61
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
62
  s.add_dependency(%q<simple-rss>, [">= 1.2"])
57
63
  s.add_dependency(%q<hpricot>, [">= 0.8.1"])
58
64
  end
59
65
  else
66
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
60
67
  s.add_dependency(%q<simple-rss>, [">= 1.2"])
61
68
  s.add_dependency(%q<hpricot>, [">= 0.8.1"])
62
69
  end
63
70
  end
71
+
data/lib/hudson.rb CHANGED
@@ -4,23 +4,31 @@ require 'open-uri'
4
4
  module BuildLights
5
5
  class Hudson
6
6
  def initialize(uri, parser = FeedParser)
7
- puts "Hudson url: #{uri}" if $verbose
7
+ puts "Hudson url: #{uri}" if $verbose
8
8
  @feed = parser.parse uri
9
9
  end
10
-
10
+
11
11
  def failed_jobs
12
- @feed.entries.each.map do |entry|
12
+ jobs = {}
13
+
14
+ @feed.entries.each do |entry|
13
15
  match = /(.*) #\d+ (.*)/.match(entry.title)
14
16
  raise "Invalid rss title #{entry.title}" unless match
15
17
  name = match[1]
16
18
  status = match[2]
17
- puts "#{name} -> #{status}" if $verbose
18
- failed = /FAIL/i.match(status)
19
- name if failed
19
+
20
+ unless jobs[name]
21
+ jobs[name] = status
22
+ puts "#{name} -> #{status}" if $verbose
23
+ end
24
+ end
25
+
26
+ jobs.map do |name, status|
27
+ name if /FAIL/i.match(status)
20
28
  end.compact
21
29
  end
22
30
  end
23
-
31
+
24
32
  class FeedParser
25
33
  def self.parse(uri)
26
34
  SimpleRSS.parse(open(uri))
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe BuildLights::CcNet do
4
+ it "should return failed jobs" do
5
+ parser = parser_for(URI, ["job 1", "Failed"], ["job 2", "Failed"])
6
+ scanner = BuildLights::CcNet.new(URI, parser)
7
+ scanner.failed_jobs.should == ["job 1", "job 2"]
8
+ end
9
+
10
+ it "should not return any jobs when all successful" do
11
+ parser = parser_for(URI, ["job 1", "Success"], ["job 2", "Success"])
12
+ scanner = BuildLights::CcNet.new(URI, parser)
13
+ scanner.failed_jobs.should == []
14
+ end
15
+
16
+ it "should only return failed jobs" do
17
+ parser = parser_for(URI, ["job 1", "Success"], ["job 2", "FaileD"])
18
+ scanner = BuildLights::CcNet.new(URI, parser)
19
+ scanner.failed_jobs.should == ["job 2"]
20
+ end
21
+
22
+ def parser_for(uri, *jobs)
23
+ projects = jobs.map do |j|
24
+ project = mock
25
+ project.should_receive(:[]).with(:name).and_return(j[0])
26
+ project.should_receive(:[]).with(:lastBuildStatus).and_return(j[1])
27
+ project
28
+ end
29
+
30
+ doc = mock()
31
+ doc.should_receive(:search).with(:Project).and_return(projects)
32
+
33
+ parser = mock()
34
+ parser.should_receive(:parse).with(uri).and_return(doc)
35
+ parser
36
+ end
37
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe BuildLights::Hudson do
4
+ it "should not show any failures when all successful" do
5
+ parser = feed_parser_for(URI, "job 1 #1 (SUCCESS)", "job 2 #1 (SUCCESS)", "job 1 #1 (SUCCESS)", "job 2 #1 (SUCCESS)")
6
+ scanner = BuildLights::Hudson.new(URI, parser)
7
+ scanner.failed_jobs.should == []
8
+ end
9
+
10
+ it "should return all failed jobs" do
11
+ parser = feed_parser_for(URI, "job 1 #1 (FAILED)", "job 2 #1 (FAILED)", "job 3 #1 (SUCCESS)")
12
+ scanner = BuildLights::Hudson.new(URI, parser)
13
+ scanner.failed_jobs.should == ["job 1", "job 2"]
14
+ end
15
+
16
+ it "should return just the latest failed jobs" do
17
+ parser = feed_parser_for(URI, "job 1 #1 (FAILED)", "job 2 #2 (SUCCESS)", "job 2 #1 (FAILED)")
18
+ scanner = BuildLights::Hudson.new(URI, parser)
19
+ scanner.failed_jobs.should == ["job 1"]
20
+ end
21
+
22
+ def feed_parser_for(uri, *titles)
23
+ entries = stub(:entries => titles.map {|t| stub(:title => t)})
24
+ parser = mock
25
+ parser.should_receive(:parse).with(uri).and_return(entries)
26
+ parser
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe BuildLights::Lights do
4
+ it "should turn lights on when some jobs have failed" do
5
+ impl = mock
6
+ impl.should_receive(:turn_on).with(BuildLights::Lights::RED)
7
+ impl.should_receive(:turn_off).with(BuildLights::Lights::GREEN)
8
+ BuildLights::Lights.new(impl).failed
9
+ end
10
+
11
+ it "should turn lights off when all jobs are successful" do
12
+ impl = mock
13
+ impl.should_receive(:turn_on).with(BuildLights::Lights::GREEN)
14
+ impl.should_receive(:turn_off).with(BuildLights::Lights::RED)
15
+ BuildLights::Lights.new(impl).success
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+ Bundler.require :default, :test
5
+ $LOAD_PATH << File.join(File.dirname(__FILE__),"..","lib")
6
+ require 'buildlights'
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildlights
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 3
9
+ version: 0.0.3
5
10
  platform: ruby
6
11
  authors:
7
12
  - Darrin Holst
@@ -9,29 +14,50 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-08-13 00:00:00 -05:00
17
+ date: 2010-04-16 00:00:00 -05:00
13
18
  default_executable: buildlights
14
19
  dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
15
34
  - !ruby/object:Gem::Dependency
16
35
  name: simple-rss
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
20
38
  requirements:
21
39
  - - ">="
22
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 2
23
44
  version: "1.2"
24
- version:
45
+ type: :runtime
46
+ version_requirements: *id002
25
47
  - !ruby/object:Gem::Dependency
26
48
  name: hpricot
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
49
+ prerelease: false
50
+ requirement: &id003 !ruby/object:Gem::Requirement
30
51
  requirements:
31
52
  - - ">="
32
53
  - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ - 8
57
+ - 1
33
58
  version: 0.8.1
34
- version:
59
+ type: :runtime
60
+ version_requirements: *id003
35
61
  description:
36
62
  email: darrinholst@gmail.com
37
63
  executables:
@@ -44,6 +70,7 @@ extra_rdoc_files:
44
70
  files:
45
71
  - .document
46
72
  - .gitignore
73
+ - Gemfile
47
74
  - LICENSE
48
75
  - README.rdoc
49
76
  - Rakefile
@@ -54,10 +81,10 @@ files:
54
81
  - lib/ccnet.rb
55
82
  - lib/hudson.rb
56
83
  - lib/lights.rb
57
- - test/ccnet_test.rb
58
- - test/hudson_test.rb
59
- - test/lights_test.rb
60
- - test/test_helper.rb
84
+ - spec/lib/ccnet_spec.rb
85
+ - spec/lib/hudson_spec.rb
86
+ - spec/lib/lights_spec.rb
87
+ - spec/spec_helper.rb
61
88
  has_rdoc: true
62
89
  homepage: http://github.com/darrinholst/buildlights
63
90
  licenses: []
@@ -71,23 +98,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
98
  requirements:
72
99
  - - ">="
73
100
  - !ruby/object:Gem::Version
101
+ segments:
102
+ - 0
74
103
  version: "0"
75
- version:
76
104
  required_rubygems_version: !ruby/object:Gem::Requirement
77
105
  requirements:
78
106
  - - ">="
79
107
  - !ruby/object:Gem::Version
108
+ segments:
109
+ - 0
80
110
  version: "0"
81
- version:
82
111
  requirements: []
83
112
 
84
113
  rubyforge_project: buildlights
85
- rubygems_version: 1.3.5
114
+ rubygems_version: 1.3.6
86
115
  signing_key:
87
116
  specification_version: 3
88
117
  summary: build monitor that will trigger lights via x10
89
118
  test_files:
90
- - test/ccnet_test.rb
91
- - test/hudson_test.rb
92
- - test/lights_test.rb
93
- - test/test_helper.rb
119
+ - spec/lib/ccnet_spec.rb
120
+ - spec/lib/hudson_spec.rb
121
+ - spec/lib/lights_spec.rb
122
+ - spec/spec_helper.rb
data/test/ccnet_test.rb DELETED
@@ -1,47 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CcNetTest < Test::Unit::TestCase
4
- URI = "some uri"
5
-
6
- def test_failed_jobs
7
- parser = parser_for(URI, ["job 1", "Failed"], ["job 2", "Failed"])
8
- scanner = BuildLights::CcNet.new(URI, parser)
9
- assert_equal(["job 1", "job 2"], scanner.failed_jobs)
10
- end
11
-
12
- def test_successful_jobs
13
- parser = parser_for(URI, ["job 1", "Success"], ["job 2", "Success"])
14
- scanner = BuildLights::CcNet.new(URI, parser)
15
- assert_equal([], scanner.failed_jobs)
16
- end
17
-
18
- def test_mixed_jobs
19
- parser = parser_for(URI, ["job 1", "Success"], ["job 2", "Failed"])
20
- scanner = BuildLights::CcNet.new(URI, parser)
21
- assert_equal(["job 2"], scanner.failed_jobs)
22
- end
23
-
24
- def test_mixed_case
25
- parser = parser_for(URI, ["job 1", "FAILED"], ["job 2", "SUCCESS"], ["job 3", "FAIL"])
26
- scanner = BuildLights::CcNet.new(URI, parser)
27
- assert_equal(["job 1", "job 3"], scanner.failed_jobs)
28
- end
29
-
30
- private
31
-
32
- def parser_for(uri, *jobs)
33
- projects = jobs.map do |j|
34
- project = mock()
35
- project.stubs(:[]).with(:name).returns(j[0])
36
- project.stubs(:[]).with(:lastBuildStatus).returns(j[1])
37
- project
38
- end
39
-
40
- doc = mock()
41
- doc.expects(:search).with(:Project).returns(projects)
42
-
43
- parser = mock()
44
- parser.expects(:parse).with(uri).returns(doc)
45
- parser
46
- end
47
- end
data/test/hudson_test.rb DELETED
@@ -1,38 +0,0 @@
1
- require 'test_helper'
2
-
3
- class HudsonTest < Test::Unit::TestCase
4
- URI = "some uri"
5
-
6
- def test_all_successful
7
- parser = feed_parser_for(URI, "job 1 #1 (SUCCESS)", "job 2 #1 (SUCCESS)")
8
- scanner = BuildLights::Hudson.new(URI, parser)
9
- assert_equal([], scanner.failed_jobs)
10
- end
11
-
12
- def test_all_failed
13
- parser = feed_parser_for(URI, "job 1 #1 (FAILED)", "job 2 #1 (FAILED)")
14
- scanner = BuildLights::Hudson.new(URI, parser)
15
- assert_equal(['job 1', 'job 2'], scanner.failed_jobs)
16
- end
17
-
18
- def test_mixed
19
- parser = feed_parser_for(URI, "job 1 #1 (SUCCESS)", "job 2 #1 (FAILED)", "job 3 #1 (SUCCESS)")
20
- scanner = BuildLights::Hudson.new(URI, parser)
21
- assert_equal(['job 2'], scanner.failed_jobs)
22
- end
23
-
24
- def test_mixed_with_lower_case
25
- parser = feed_parser_for(URI, "job 1 #1 (success)", "job 2 #1 (failed)", "job 3 #1 (success)")
26
- scanner = BuildLights::Hudson.new(URI, parser)
27
- assert_equal(['job 2'], scanner.failed_jobs)
28
- end
29
-
30
- private
31
-
32
- def feed_parser_for(uri, *titles)
33
- entries = stub(:entries => titles.map {|t| stub(:title => t)})
34
- parser = mock()
35
- parser.expects(:parse).with(uri).returns(entries)
36
- parser
37
- end
38
- end
data/test/lights_test.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LightsTest < Test::Unit::TestCase
4
- def test_successful_builds
5
- impl = mock()
6
- impl.expects(:turn_on).with(1)
7
- impl.expects(:turn_off).with(2)
8
-
9
- BuildLights::Lights.new(impl).success
10
- end
11
-
12
- def test_failed_builds
13
- impl = mock()
14
- impl.expects(:turn_on).with(2)
15
- impl.expects(:turn_off).with(1)
16
-
17
- BuildLights::Lights.new(impl).failed
18
- end
19
- end
data/test/test_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'mocha'
7
- require 'buildlights'
8
-
9
- class Test::Unit::TestCase
10
- end