rbuilder 0.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.
Files changed (42) hide show
  1. data/Rakefile +47 -0
  2. data/bin/rbuilder +65 -0
  3. data/conf/example.conf +2 -0
  4. data/rbuilder/build.rb +50 -0
  5. data/rbuilder/build_command.rb +33 -0
  6. data/rbuilder/build_configuration.rb +21 -0
  7. data/rbuilder/build_description.rb +46 -0
  8. data/rbuilder/build_report.rb +40 -0
  9. data/rbuilder/build_status.rb +39 -0
  10. data/rbuilder/builder.rb +45 -0
  11. data/rbuilder/gui.rb +6 -0
  12. data/rbuilder/gui/build_details_pane.rb +105 -0
  13. data/rbuilder/gui/build_list_view_entry.rb +33 -0
  14. data/rbuilder/gui/builder_list_view.rb +92 -0
  15. data/rbuilder/gui/builder_monitor_window.rb +112 -0
  16. data/rbuilder/gui/images.rb +5 -0
  17. data/rbuilder/gui/images/broken_builder.gif +0 -0
  18. data/rbuilder/gui/images/building.gif +0 -0
  19. data/rbuilder/gui/images/failed.gif +0 -0
  20. data/rbuilder/gui/images/ok.gif +0 -0
  21. data/rbuilder/gui/images/ok_builder.gif +0 -0
  22. data/rbuilder/lib/observer.rb +7 -0
  23. data/rbuilder/libs.rb +4 -0
  24. data/rbuilder/revision_committed.rb +21 -0
  25. data/rbuilder/source_control.rb +3 -0
  26. data/rbuilder/source_control/status.rb +23 -0
  27. data/rbuilder/source_control/svn.rb +64 -0
  28. data/rbuilder/source_control/tracker.rb +36 -0
  29. data/tests/gui/test_build_details_pane.rb +118 -0
  30. data/tests/gui/test_builder_list_view.rb +202 -0
  31. data/tests/gui/test_builder_list_view_entry.rb +79 -0
  32. data/tests/gui/test_builder_monitor_window.rb +81 -0
  33. data/tests/source_control/test_source_control.rb +52 -0
  34. data/tests/source_control/test_svn.rb +60 -0
  35. data/tests/test_build.rb +111 -0
  36. data/tests/test_build_command.rb +57 -0
  37. data/tests/test_build_configuration.rb +31 -0
  38. data/tests/test_build_description.rb +106 -0
  39. data/tests/test_build_report.rb +56 -0
  40. data/tests/test_builder.rb +54 -0
  41. data/tests/test_revision_comitted.rb +30 -0
  42. metadata +104 -0
@@ -0,0 +1,111 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require File.join(File.dirname(__FILE__), 'builder_test_env')
5
+ require 'libs'
6
+
7
+
8
+ class TestBuild < Test::Unit::TestCase
9
+
10
+ def test_contains_a_summary
11
+ build = Build.new(nil,nil,nil)
12
+ assert_equal '', build.summary
13
+ end
14
+
15
+ def test_gets_archive_from_description
16
+ build = Build.new(nil, nil, nil, 'the_archive_name')
17
+ assert_equal 'the_archive_name', build.archive
18
+ end
19
+ end
20
+
21
+ class TestRunBuild < Test::Unit::TestCase
22
+ attr_reader :build, :build_description, :working_dir
23
+ def setup
24
+ @working_dir = "working_dir"
25
+ @build_description = stub(:execute => nil)
26
+ build_reason = Object
27
+ @build = Build.new(build_description, working_dir, build_reason)
28
+ end
29
+
30
+ def test_executes_build_command_in_working_dir
31
+ build_description.expects(:execute).with(working_dir,build.report)
32
+ build.run
33
+ end
34
+
35
+ def test_updates_observer
36
+ view = mock
37
+ view.expects :update # one for status to building
38
+ view.expects :update # one for status to ok
39
+ build.add_observer view
40
+ build.run
41
+ end
42
+
43
+ end
44
+
45
+ class TestBuildRevision < Test::Unit::TestCase
46
+ attr_reader :build, :stub_reason
47
+ def setup
48
+ @stub_reason = stub
49
+ @build = Build.new(nil,nil,stub_reason)
50
+ end
51
+
52
+ def test_is_retreived_from_reason
53
+ stub_reason.stubs(:revision).returns 233
54
+ assert_equal 233, build.revision
55
+ stub_reason.stubs(:revision).returns 455
56
+ assert_equal 455, build.revision
57
+ end
58
+
59
+ end
60
+
61
+
62
+
63
+ class TestBuildStatus < Test::Unit::TestCase
64
+ attr_reader :build
65
+ def setup
66
+ @build = Build.new(nil,nil,nil)
67
+
68
+ end
69
+
70
+ def test_equals_report_status
71
+ assert_equal BuildStatus.ok, build.status
72
+ build.report.green
73
+ assert_equal BuildStatus.ok, build.status
74
+ build.report.red
75
+ assert_equal BuildStatus.failed, build.status
76
+ end
77
+
78
+ def test_green_returns_true_only_when_status_is_green
79
+ assert build.green?
80
+ build.report.red
81
+ assert !build.green?
82
+ build.report.green
83
+ assert build.green?
84
+ end
85
+
86
+ def test_equals_building_if_building
87
+ build.building = true
88
+ assert_equal BuildStatus.building, build.status
89
+ end
90
+
91
+ end
92
+
93
+ class TestBuildSummary < Test::Unit::TestCase
94
+ attr_reader :build
95
+ def setup
96
+ reason = stub(:to_s => 'reason_summary')
97
+ @build = Build.new(nil,nil,reason)
98
+ build.report.info "report_summary"
99
+ end
100
+
101
+ def test_summary_is_report_summary_if_status_is_green_or_red
102
+ assert_equal 'report_summary', build.summary
103
+ build.report.red
104
+ assert_equal 'report_summary', build.summary
105
+ end
106
+
107
+ def test_summary_is_reason_if_status_is_building
108
+ build.building = true
109
+ assert_equal 'reason_summary', build.summary
110
+ end
111
+ end
@@ -0,0 +1,57 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require File.join(File.dirname(__FILE__), 'builder_test_env')
5
+ require 'libs'
6
+
7
+ class TestBuilderExecution < Test::Unit::TestCase
8
+ attr_reader :working_dir, :build_command, :the_command_line, :build_report
9
+ def setup
10
+ @working_dir = "some_dir"
11
+ @the_command_line = "ls"
12
+ @build_command = BuildCommand.new(the_command_line)
13
+ @build_command.stubs(:cd).yields
14
+ @build_command.stubs(:run_command).returns true
15
+ @build_report = stub_everything
16
+ end
17
+
18
+ def test_goes_to_working_directory_and_executes_build_command
19
+ build_command.expects(:cd).with(working_dir).yields
20
+ build_command.expects(:run_command).returns true
21
+ build_command.execute(working_dir, build_report)
22
+ end
23
+
24
+ def test_sets_build_result_to_green_if_command_succeeds
25
+ build_command.expects(:run_command).returns true
26
+ build_report.expects :green
27
+ build_command.execute(working_dir, build_report)
28
+ end
29
+
30
+ def test_sets_build_result_to_red_if_command_fails
31
+ build_command.expects(:run_command).returns false
32
+ build_report.expects :red
33
+ build_command.execute(working_dir, build_report)
34
+ end
35
+
36
+ end
37
+
38
+ class TestBuildCommandWithRealCommand < Test::Unit::TestCase
39
+ attr_reader :expected_output_lines, :build_command, :build_report
40
+ def setup
41
+ @expected_output_lines = ["line_1\n","line_2\n"]
42
+ @build_command = BuildCommand.new("echo line_1;echo line_2")
43
+ @build_report = stub_everything
44
+ end
45
+
46
+ def test_output_is_send_to_build_report
47
+ build_report.expects(:info).with("line_1\n")
48
+ build_report.expects(:info).with("line_2\n")
49
+ build_command.execute(".", build_report)
50
+ end
51
+
52
+ def test_real_normal_command_should_be_green
53
+ build_report.expects :green
54
+ build_command.execute(".", build_report)
55
+ end
56
+
57
+ end
@@ -0,0 +1,31 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require File.join(File.dirname(__FILE__), 'builder_test_env')
5
+ require 'libs'
6
+ require 'build'
7
+
8
+ class TestBuildConfiguration < Test::Unit::TestCase
9
+
10
+ def test_build_creates_build_description_and_ads_it_to_builder
11
+ builder = Builder.new
12
+ config = BuildConfiguration.new(builder)
13
+ assert_equal 0, builder.descriptions.size
14
+ config.from_text("build '.', 'some_command'")
15
+ assert_equal 1, builder.descriptions.size
16
+ end
17
+
18
+ def test_build_fails_if_directory_does_not_exist
19
+ builder = Builder.new
20
+ config = BuildConfiguration.new(builder)
21
+ assert_equal 0, builder.descriptions.size
22
+ assert_raises SourceControl::DirectoryInvalidException do
23
+ config.from_text("build 'blah', 'some_command'")
24
+ end
25
+ assert_equal 0, builder.descriptions.size
26
+ end
27
+
28
+
29
+
30
+ end
31
+
@@ -0,0 +1,106 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require File.join(File.dirname(__FILE__), 'builder_test_env')
5
+ require 'libs'
6
+ require 'revision_committed'
7
+
8
+ class TestBuildDescriptionIterate < Test::Unit::TestCase
9
+ def test_lets_source_contol_report_changes_to_self
10
+ working_dir = "some_dir"
11
+ source_control = stub(:working_dir => working_dir)
12
+ build_command = stub
13
+ build_description = BuildDescription.new(build_command, source_control)
14
+ source_control.expects(:report_change_to).with(build_description)
15
+ build_description.iterate
16
+ end
17
+ end
18
+
19
+ class TestBuildDescriptionRunABuild < Test::Unit::TestCase
20
+ attr_reader :working_dir, :build_command, :build_description, :build
21
+ def setup
22
+ @working_dir = "some_dir"
23
+ source_control = stub(:working_dir => working_dir)
24
+ @build_command = stub(:execute => nil)
25
+ @build_description = BuildDescription.new(build_command, source_control)
26
+ @build = stub(:run => nil)
27
+ @build_description.stubs(:create_build).returns(build)
28
+ end
29
+
30
+ def test_creates_and_starts_build_with_a_reason
31
+ reason = Object
32
+ build_description.expects(:create_build).with(reason).returns build
33
+ build.expects :run
34
+ build_description.run_build(reason)
35
+ end
36
+
37
+ def test_updates_observers_with_new_build_when_running_build
38
+ reason = Object
39
+ view = mock
40
+ view.expects(:update).with(:new_build => build)
41
+ build_description.add_observer view
42
+ build_description.run_build(reason)
43
+ end
44
+
45
+ def test_collects_ran_builds
46
+ reason = Object
47
+ build_description.run_build(reason)
48
+ assert_equal [build], build_description.builds
49
+ build_description.stubs(:create_build).returns(build2 = stub(:run => nil))
50
+ build_description.run_build(reason)
51
+ assert_equal [build,build2], build_description.builds
52
+ end
53
+
54
+ def test_receiving_a_commit_runs_a_build_with_reason_receiving_a_commit
55
+ revision = 234
56
+ committer = 'westgeer'
57
+ expected_reason = RevisionCommitted.new(revision,committer)
58
+ build.expects :run
59
+ build_description.expects(:create_build).with(expected_reason).returns build
60
+ build_description.new_revision_committed(SourceControl::Status.new(revision,committer))
61
+ end
62
+
63
+ end
64
+
65
+
66
+ class TestBuildCreation < Test::Unit::TestCase
67
+ def test_creates_a_build_with_a_build_descrition_reason_working_dir_and_build_report
68
+ working_dir = "working_dir"
69
+ source_control = stub(:working_dir => working_dir, :archive => 'the_archive')
70
+
71
+ build_description = Object
72
+ build_reason = Object
73
+ build_description = BuildDescription.new(build_description, source_control)
74
+ build = build_description.create_build(build_reason)
75
+
76
+ assert_same build_reason, build.reason
77
+ assert_equal 'the_archive', build.archive
78
+ end
79
+ end
80
+
81
+ class TestBuildDescriptionStatus < Test::Unit::TestCase
82
+ attr_reader :build_description, :failed_build, :successful_build
83
+ def setup
84
+ @build_description = BuildDescription.new(nil,nil)
85
+ @failed_build = stub(:green? => false)
86
+ @successful_build = stub(:green? => true)
87
+ end
88
+
89
+ def test_is_ok_initially
90
+ assert_equal BuilderState.ok, build_description.status
91
+ end
92
+
93
+ def test_is_set_to_broken_when_last_build_result_is_failed
94
+ build_description.builds << successful_build
95
+ assert_equal BuilderState.ok, build_description.status
96
+ build_description.builds << failed_build
97
+ assert_equal BuilderState.broken, build_description.status
98
+ end
99
+
100
+ def test_is_set_to_ok_when_last_build_result_is_ok
101
+ build_description.builds << failed_build
102
+ assert_equal BuilderState.broken, build_description.status
103
+ build_description.builds << successful_build
104
+ assert_equal BuilderState.ok, build_description.status
105
+ end
106
+ end
@@ -0,0 +1,56 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require File.join(File.dirname(__FILE__), 'builder_test_env')
5
+ require 'libs'
6
+
7
+ class TestBuildReport < Test::Unit::TestCase
8
+ attr_reader :build_result
9
+ def setup
10
+ @build_result = BuildReport.new
11
+ end
12
+ def test_initial_status_is_ok
13
+ assert_equal BuildStatus.ok, build_result.status
14
+ end
15
+
16
+ def test_green_sets_status_to_ok
17
+ build_result.green
18
+ assert_equal BuildStatus.ok, build_result.status
19
+ end
20
+
21
+ def test_red_sets_status_to_fail
22
+ build_result.red
23
+ assert_equal BuildStatus.failed, build_result.status
24
+ end
25
+
26
+ def test_info_is_added_to_info_list
27
+ output_lines = "build_output_line_1\n", "build_output_line_2\n"
28
+ build_result.info output_lines[0]
29
+ assert_equal output_lines[0].strip, build_result.log
30
+ build_result.info output_lines[1]
31
+ assert_equal output_lines.join("").strip, build_result.log
32
+ end
33
+ end
34
+ class TestBuildReportStatusChanges < Test::Unit::TestCase
35
+ attr_reader :build_report, :view
36
+ def setup
37
+ @view = stub(:update)
38
+ @build_report = BuildReport.new
39
+ @build_report.add_observer(view)
40
+ end
41
+ def test_observers_are_notified_when_becoming_red
42
+ view.expects(:update)
43
+ build_report.red
44
+ end
45
+
46
+ def test_observers_are_notified_when_becoming_green
47
+ view.expects(:update)
48
+ build_report.green
49
+ end
50
+
51
+ def test_observers_are_notified_with_log_line_when_info_is_received
52
+ new_log_line = "some log line \n"
53
+ view.expects(:update).with(:log_line => new_log_line.strip)
54
+ build_report.info new_log_line
55
+ end
56
+ end
@@ -0,0 +1,54 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require File.join(File.dirname(__FILE__), 'builder_test_env')
5
+ require 'libs'
6
+
7
+ class TestBuilder < Test::Unit::TestCase
8
+ attr_reader :builder, :build_description1, :build_description2
9
+ def setup
10
+ @build_description1 = stub(:status => BuilderState.ok)
11
+ @build_description2 = stub(:status => BuilderState.ok)
12
+ @builder = Builder.new
13
+ builder.add_description(build_description1)
14
+ builder.add_description(build_description2)
15
+ end
16
+
17
+ def test_iterate_iterates_each_description
18
+ build_description1.expects(:iterate)
19
+ build_description2.expects(:iterate)
20
+ builder.iterate
21
+ end
22
+
23
+ def test_each_description_calls_block_for_each_description
24
+ build_description1 = mock
25
+ build_description2 = mock
26
+ builder = Builder.new
27
+ builder.add_description(build_description1)
28
+ builder.add_description(build_description2)
29
+ result = []
30
+ builder.each_description {|description| result << description}
31
+ assert_equal [build_description1, build_description2], result
32
+ end
33
+
34
+ def test_status_is_ok_if_all_build_descriptions_are_ok
35
+ assert_equal BuilderState.ok, builder.status
36
+ end
37
+
38
+ def test_status_is_broken_if_any_build_description_is_broken
39
+ build_description1.stubs(:status).returns BuilderState.broken
40
+ assert_equal BuilderState.broken, builder.status
41
+ end
42
+
43
+ end
44
+ class TestBuildViewUpdates < Test::Unit::TestCase
45
+
46
+ def test_updates_views_afer_each_iteration
47
+ builder = Builder.new
48
+ view1 = mock('view1')
49
+ view1.expects(:update)
50
+ builder.add_observer(view1)
51
+ builder.iterate_description(stub_everything)
52
+ end
53
+
54
+ end
@@ -0,0 +1,30 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require File.join(File.dirname(__FILE__), 'builder_test_env')
5
+ require 'revision_committed'
6
+
7
+ class TestRevisionCommitted < Test::Unit::TestCase
8
+ def test_has_revision_and_committer
9
+ revision = 123
10
+ committer = 'westgeer'
11
+ event = RevisionCommitted.new(revision, committer)
12
+ assert_equal revision, event.revision
13
+ assert_equal committer, event.committer
14
+ end
15
+
16
+ def test_equals
17
+ assert_equal RevisionCommitted.new(1,'westgeest'), RevisionCommitted.new(1,'westgeest')
18
+ assert_equal RevisionCommitted.new(2,'westgeest'), RevisionCommitted.new(2,'westgeest')
19
+ assert_equal RevisionCommitted.new(1,'blah'), RevisionCommitted.new(1,'blah')
20
+
21
+ assert_not_equal RevisionCommitted.new(1,'blah'), RevisionCommitted.new(1,'westgeest')
22
+ assert_not_equal RevisionCommitted.new(1,'westgeest'), RevisionCommitted.new(1,'blah')
23
+ assert_not_equal RevisionCommitted.new(2,'westgeest'), RevisionCommitted.new(1,'westgeest')
24
+ assert_not_equal RevisionCommitted.new(1,'westgeest'), RevisionCommitted.new(2,'westgeest')
25
+ end
26
+
27
+ def test_equals_with_other_type_of_object_returns_false
28
+ assert_not_equal RevisionCommitted.new(1,'westgeest'), Object.new
29
+ end
30
+ end