ciat 0.4.8 → 0.4.9

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 (60) hide show
  1. data/README.rdoc +4 -4
  2. data/lib/ciat.rb +3 -5
  3. data/lib/ciat/differs/html_differ.rb +3 -4
  4. data/lib/ciat/erb_helpers.rb +6 -4
  5. data/lib/ciat/feedback/composite.rb +2 -2
  6. data/lib/ciat/feedback/feedback_counter.rb +2 -2
  7. data/lib/ciat/feedback/html_feedback.rb +25 -8
  8. data/lib/ciat/feedback/html_feedback_builder.rb +28 -0
  9. data/lib/ciat/feedback/return_status.rb +1 -1
  10. data/lib/ciat/feedback/standard_output.rb +1 -1
  11. data/lib/ciat/io.rb +17 -0
  12. data/lib/ciat/processors/basic_processing.rb +21 -30
  13. data/lib/ciat/{executors → processors}/java.rb +7 -8
  14. data/lib/ciat/{executors → processors}/parrot.rb +9 -10
  15. data/lib/ciat/rake_task.rb +1 -1
  16. data/lib/ciat/subresult.rb +20 -0
  17. data/lib/ciat/suite.rb +27 -38
  18. data/lib/ciat/suite_builder.rb +54 -0
  19. data/lib/ciat/test.rb +32 -18
  20. data/lib/ciat/test_element.rb +7 -2
  21. data/lib/ciat/{crate.rb → test_file.rb} +24 -16
  22. data/lib/ciat/test_result.rb +24 -0
  23. data/lib/ciat/traffic_light.rb +6 -0
  24. data/lib/templates/detail_row.html.erb +5 -4
  25. data/lib/templates/group_header.html.erb +2 -2
  26. data/lib/templates/report.html.erb +1 -1
  27. data/lib/templates/summary_row.html.erb +4 -4
  28. data/spec/ciat/erb_helpers_spec.rb +71 -0
  29. data/spec/ciat/feedback/composite_spec.rb +28 -0
  30. data/spec/ciat/feedback/feedback_counter_spec.rb +91 -0
  31. data/spec/ciat/feedback/html_feedback_spec.rb +48 -0
  32. data/spec/ciat/feedback/return_status_spec.rb +90 -0
  33. data/spec/ciat/feedback/standard_output_spec.rb +109 -0
  34. data/spec/ciat/processors/basic_processing_spec.rb +146 -0
  35. data/spec/ciat/processors/java_spec.rb +31 -0
  36. data/spec/ciat/processors/parrot_spec.rb +40 -0
  37. data/spec/ciat/subresult_spec.rb +40 -0
  38. data/spec/ciat/suite_builder_spec.rb +70 -0
  39. data/spec/ciat/suite_spec.rb +64 -0
  40. data/spec/ciat/test_element_spec.rb +78 -0
  41. data/spec/ciat/test_file_spec.rb +96 -0
  42. data/spec/ciat/test_spec.rb +127 -0
  43. data/spec/ciat/traffic_light_spec.rb +41 -0
  44. data/spec/ciat_spec.rb +2 -0
  45. data/spec/spec_helper.rb +134 -0
  46. data/spec/templates/detail_row/elements_html_erb_spec.rb +60 -0
  47. data/spec/templates/detail_row_html_erb_spec.rb +73 -0
  48. data/spec/templates/elements/diff_html_erb_spec.rb +28 -0
  49. data/spec/templates/elements/plain_element_html_erb_spec.rb +36 -0
  50. data/spec/templates/report_html_erb_spec.rb +85 -0
  51. data/spec/templates/summary_row_html_erb_spec.rb +93 -0
  52. data/spec/templates/test_numbers_html_erb_spec.rb +82 -0
  53. metadata +54 -32
  54. data/History.txt +0 -96
  55. data/Rakefile +0 -40
  56. data/ciat.gemspec +0 -53
  57. data/lib/ciat/cargo.rb +0 -55
  58. data/lib/ciat/compilers/java.rb +0 -54
  59. data/lib/ciat/processors/copy.rb +0 -37
  60. data/lib/ciat/version.rb +0 -7
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ require 'ciat/feedback/html_feedback'
4
+
5
+ describe CIAT::Feedback::HtmlFeedback do
6
+ before(:each) do
7
+ @counter = mock("counter")
8
+ @feedback = CIAT::Feedback::HtmlFeedback.new(@counter, {})
9
+ end
10
+
11
+ it "should have a pre-test action" do
12
+ suite, output_folder = mock("suite"), mock("output folder")
13
+
14
+ suite.should_receive(:output_folder).
15
+ at_least(:once).and_return(output_folder)
16
+ FileUtils.should_receive(:mkdir_p).with(output_folder)
17
+ FileUtils.should_receive(:cp).with(/.*\/data\/ciat.css/, output_folder)
18
+ FileUtils.should_receive(:cp).with(/.*\/data\/prototype.js/, output_folder)
19
+
20
+ @feedback.pre_tests(suite)
21
+ end
22
+
23
+ it "should generate a report" do
24
+ suite = mock("suite")
25
+ html, report_filename = mock("html"), mock("report filename")
26
+
27
+ @feedback.should_receive(:generate_html).with(suite).and_return(html)
28
+ @feedback.should_receive(:report_filename).and_return(report_filename)
29
+ @feedback.should_receive(:write_file).with(report_filename, html)
30
+
31
+ @feedback.post_tests(suite)
32
+ end
33
+
34
+ it "should generate html" do
35
+ suite = mock("suite")
36
+ erb_template, binding = mock("erb_template"), mock("binding")
37
+ filename = mock("filename")
38
+
39
+ suite.should_receive(:results).and_return(mock("results"))
40
+ suite.should_receive(:processors).and_return(mock("processors"))
41
+ suite.should_receive(:size).and_return(mock("size"))
42
+ @feedback.should_receive(:build_erb).and_return(erb_template)
43
+ @feedback.should_receive(:binding).with().and_return(binding)
44
+ erb_template.should_receive(:result).with(binding)
45
+
46
+ @feedback.generate_html(suite)
47
+ end
48
+ end
@@ -0,0 +1,90 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ require 'ciat/feedback/return_status'
4
+
5
+ describe CIAT::Feedback::ReturnStatus do
6
+ GREEN = CIAT::TrafficLight.new(:green)
7
+ YELLOW = CIAT::TrafficLight.new(:yellow)
8
+ RED = CIAT::TrafficLight.new(:red)
9
+
10
+ before(:each) do
11
+ @feedback = CIAT::Feedback::ReturnStatus.new
12
+ end
13
+
14
+ it "should be okay without any tests" do
15
+ lambda { @feedback.post_tests(mock("suite")) }.should_not raise_error
16
+ end
17
+
18
+ it "should ignore a green light" do
19
+ @feedback.report_subresult(mock("processor", :light => GREEN))
20
+
21
+ lambda { @feedback.post_tests(mock("suite")) }.should_not raise_error
22
+ end
23
+
24
+ it "should ignore many green lights" do
25
+ @feedback.report_subresult(mock("processor", :light => GREEN))
26
+ @feedback.report_subresult(mock("processor", :light => GREEN))
27
+ @feedback.report_subresult(mock("processor", :light => GREEN))
28
+
29
+ lambda { @feedback.post_tests(mock("suite")) }.should_not raise_error
30
+ end
31
+
32
+ it "should fail after yellow processor" do
33
+ @feedback.report_subresult(mock("processor", :light => YELLOW))
34
+
35
+ lambda { @feedback.post_tests(mock("suite")) }.
36
+ should raise_error(RuntimeError)
37
+ end
38
+
39
+ it "should fail after many yellow processors" do
40
+ @feedback.report_subresult(mock("processor", :light => YELLOW))
41
+ @feedback.report_subresult(mock("processor", :light => YELLOW))
42
+ @feedback.report_subresult(mock("processor", :light => YELLOW))
43
+
44
+ lambda { @feedback.post_tests(mock("suite")) }.
45
+ should raise_error(RuntimeError)
46
+ end
47
+
48
+ it "should fail after red processor" do
49
+ @feedback.report_subresult(mock("processor", :light => RED))
50
+
51
+ lambda { @feedback.post_tests(mock("suite")) }.
52
+ should raise_error(RuntimeError)
53
+ end
54
+
55
+ it "should fail after many red processors" do
56
+ @feedback.report_subresult(mock("processor", :light => RED))
57
+ @feedback.report_subresult(mock("processor", :light => RED))
58
+ @feedback.report_subresult(mock("processor", :light => RED))
59
+
60
+ lambda { @feedback.post_tests(mock("suite")) }.
61
+ should raise_error(RuntimeError)
62
+ end
63
+
64
+ it "should fail after many different processors (red last)" do
65
+ @feedback.report_subresult(mock("processor", :light => GREEN))
66
+ @feedback.report_subresult(mock("processor", :light => YELLOW))
67
+ @feedback.report_subresult(mock("processor", :light => RED))
68
+
69
+ lambda { @feedback.post_tests(mock("suite")) }.
70
+ should raise_error(RuntimeError)
71
+ end
72
+
73
+ it "should fail after many different processors (yellow last)" do
74
+ @feedback.report_subresult(mock("processor", :light => GREEN))
75
+ @feedback.report_subresult(mock("processor", :light => RED))
76
+ @feedback.report_subresult(mock("processor", :light => YELLOW))
77
+
78
+ lambda { @feedback.post_tests(mock("suite")) }.
79
+ should raise_error(RuntimeError)
80
+ end
81
+
82
+ it "should fail after many different processors (green last)" do
83
+ @feedback.report_subresult(mock("processor", :light => YELLOW))
84
+ @feedback.report_subresult(mock("processor", :light => RED))
85
+ @feedback.report_subresult(mock("processor", :light => GREEN))
86
+
87
+ lambda { @feedback.post_tests(mock("suite")) }.
88
+ should raise_error(RuntimeError)
89
+ end
90
+ end
@@ -0,0 +1,109 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ require 'ciat/feedback/standard_output'
4
+
5
+ describe CIAT::Feedback::StandardOutput do
6
+ before(:each) do
7
+ @counter = mock("counter")
8
+ @feedback = CIAT::Feedback::StandardOutput.new(@counter)
9
+ end
10
+
11
+ describe "the post-test report" do
12
+ it "should report just the total number of tests" do
13
+ suite = mock("suite")
14
+
15
+ suite.should_receive(:size).and_return(88)
16
+ @counter.should_receive(:failure_count).and_return(0)
17
+ @counter.should_receive(:error_count).and_return(0)
18
+ @feedback.should_receive(:print).with("\n")
19
+ @feedback.should_receive(:print).with("88 tests executed")
20
+ @feedback.should_receive(:print).with(".\n")
21
+
22
+ @feedback.post_tests(suite)
23
+ end
24
+
25
+ it "should report the number of tests and failures" do
26
+ suite = mock("suite")
27
+
28
+ suite.should_receive(:size).and_return(30)
29
+ @counter.should_receive(:failure_count).at_least(:once).and_return(12)
30
+ @counter.should_receive(:error_count).and_return(0)
31
+ @feedback.should_receive(:print).with("\n")
32
+ @feedback.should_receive(:print).with("30 tests executed")
33
+ @feedback.should_receive(:print).with(", 12 failures")
34
+ @feedback.should_receive(:print).with(".\n")
35
+
36
+ @feedback.post_tests(suite)
37
+ end
38
+
39
+ it "should report the number of tests and errors" do
40
+ suite = mock("suite")
41
+
42
+ suite.should_receive(:size).and_return(3)
43
+ @counter.should_receive(:failure_count).and_return(0)
44
+ @counter.should_receive(:error_count).at_least(:once).and_return(1)
45
+ @feedback.should_receive(:print).with("\n")
46
+ @feedback.should_receive(:print).with("3 tests executed")
47
+ @feedback.should_receive(:print).with(", 1 errors")
48
+ @feedback.should_receive(:print).with(".\n")
49
+
50
+ @feedback.post_tests(suite)
51
+ end
52
+
53
+ it "should report the number of tests, failures, and errors" do
54
+ suite = mock("suite")
55
+
56
+ suite.should_receive(:size).and_return(78)
57
+ @counter.should_receive(:failure_count).at_least(:once).and_return(9)
58
+ @counter.should_receive(:error_count).at_least(:once).and_return(3)
59
+ @feedback.should_receive(:print).with("\n")
60
+ @feedback.should_receive(:print).with("78 tests executed")
61
+ @feedback.should_receive(:print).with(", 9 failures")
62
+ @feedback.should_receive(:print).with(", 3 errors")
63
+ @feedback.should_receive(:print).with(".\n")
64
+
65
+ @feedback.post_tests(suite)
66
+ end
67
+ end
68
+
69
+ describe "reporting on a processor" do
70
+ before(:each) do
71
+ @light = mock("light")
72
+ @processor = mock("processor")
73
+ @processor.should_receive(:light).at_least(:once).and_return(@light)
74
+ end
75
+
76
+ it "should report a green light" do
77
+ expect_light(:green)
78
+ @feedback.should_receive(:putc).with(".")
79
+
80
+ @feedback.report_subresult(@processor)
81
+ end
82
+
83
+ it "should report a red light" do
84
+ expect_light(:red)
85
+ @feedback.should_receive(:putc).with("F")
86
+
87
+ @feedback.report_subresult(@processor)
88
+ end
89
+
90
+ it "should report a yellow light" do
91
+ expect_light(:yellow)
92
+ @feedback.should_receive(:putc).with("E")
93
+
94
+ @feedback.report_subresult(@processor)
95
+ end
96
+
97
+ it "should report an unset light" do
98
+ expect_light(:unset)
99
+ @feedback.should_receive(:putc).with("-")
100
+
101
+ @feedback.report_subresult(@processor)
102
+ end
103
+
104
+ def expect_light(setting)
105
+ @light.should_receive(:setting).at_least(:once).and_return(setting)
106
+ end
107
+ end
108
+
109
+ end
@@ -0,0 +1,146 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe CIAT::Processors::BasicProcessing do
4
+ class Processor
5
+ include CIAT::Processors::BasicProcessing
6
+ end
7
+
8
+ before(:each) do
9
+ @processor = Processor.new
10
+ end
11
+
12
+ describe "processing" do
13
+ before(:each) do
14
+ @test = mock("test")
15
+ end
16
+
17
+ it "should execute and diff normally" do
18
+ @processor.should_receive(:execute).with(@test).and_return(true)
19
+ @processor.should_receive(:diff).with(@test).and_return(true)
20
+
21
+ @processor.process(@test).should == CIAT::TrafficLight::GREEN
22
+ end
23
+
24
+ it "should execute with an error" do
25
+ @processor.should_receive(:execute).with(@test).and_return(false)
26
+
27
+ @processor.process(@test).should == CIAT::TrafficLight::YELLOW
28
+ end
29
+
30
+ it "should execute normally and diff with a failure" do
31
+ @processor.should_receive(:execute).with(@test).and_return(true)
32
+ @processor.should_receive(:diff).with(@test).and_return(false)
33
+
34
+ @processor.process(@test).should == CIAT::TrafficLight::RED
35
+ end
36
+ end
37
+
38
+ describe "executing a processor for a test" do
39
+ it "should put together and execute a shell command" do
40
+ test, ok, result = mock("test"), mock("ok"), mock("result")
41
+
42
+ @processor.should_receive(:executable).and_return("[executable]")
43
+ @processor.should_receive(:input_file).with(test).
44
+ and_return("[input]")
45
+ @processor.should_receive(:command_line_args).with(test).
46
+ and_return("[args]")
47
+ @processor.should_receive(:output_file).with(test).
48
+ and_return("[output]")
49
+ @processor.should_receive(:error_file).with(test).
50
+ and_return("[error]")
51
+ @processor.should_receive(:sh).
52
+ with("[executable] '[input]' [args] > '[output]' 2> '[error]'").
53
+ and_yield(ok, result)
54
+
55
+ @processor.execute(test).should == ok
56
+ end
57
+ end
58
+
59
+ describe "handling command-line arguments" do
60
+ it "should strip command-line arguments" do
61
+ test = mock("test")
62
+ command_line = mock("command_line")
63
+
64
+ test.should_receive(:element?).with(:command_line).and_return(true)
65
+ test.should_receive(:element).with(:command_line).
66
+ and_return(command_line)
67
+ command_line.should_receive(:content).
68
+ and_return(" argument1 \t argument2 \n\n")
69
+
70
+ @processor.command_line_args(test).should == "argument1 \t argument2"
71
+ end
72
+
73
+ it "should return empty string if none provided" do
74
+ test = mock("test")
75
+
76
+ test.should_receive(:element?).with(:command_line).and_return(false)
77
+
78
+ @processor.command_line_args(test).should == ''
79
+ end
80
+ end
81
+
82
+ describe "computing a diff" do
83
+ it "should compute a diff in HTML" do
84
+ test, kind, result =
85
+ mock("test"), mock("processor kind"), mock("result")
86
+ output_name = mock("output name")
87
+
88
+ @processor.should_receive(:kind).any_number_of_times.and_return(kind)
89
+ kind.should_receive(:output_name).any_number_of_times.
90
+ and_return(output_name)
91
+ original_file = expect_element_as_file(test, output_name)
92
+ generated_file = expect_element_as_file(test, output_name, :generated)
93
+ diff_file = expect_element_as_file(test, output_name, :diff)
94
+ @processor.should_receive(:html_diff).
95
+ with(original_file, generated_file, diff_file).and_return(result)
96
+
97
+ @processor.diff(test).should eql(result)
98
+ end
99
+
100
+ def expect_element_as_file(test, *names)
101
+ element, filename = mock("#{names} element"), mock("#{names} filename")
102
+ test.should_receive(:element).with(*names).and_return(element)
103
+ element.should_receive(:as_file).and_return(filename)
104
+ filename
105
+ end
106
+ end
107
+
108
+ it "should get filename of input" do
109
+ test = mock("test")
110
+ kind, element, name = mock("kind"), mock("element"), mock("name")
111
+ filename = mock("filename")
112
+
113
+ @processor.should_receive(:kind).and_return(kind)
114
+ kind.should_receive(:input_name).and_return(name)
115
+ test.should_receive(:element).with(name).and_return(element)
116
+ element.should_receive(:as_file).and_return(filename)
117
+
118
+ @processor.input_file(test).should eql(filename)
119
+ end
120
+
121
+ it "should get filename of input" do
122
+ test = mock("test")
123
+ kind, element, name = mock("kind"), mock("element"), mock("name")
124
+ filename = mock("filename")
125
+
126
+ @processor.should_receive(:kind).and_return(kind)
127
+ kind.should_receive(:output_name).and_return(name)
128
+ test.should_receive(:element).with(name, :generated).and_return(element)
129
+ element.should_receive(:as_file).and_return(filename)
130
+
131
+ @processor.output_file(test).should eql(filename)
132
+ end
133
+
134
+ it "should get filename of input" do
135
+ test = mock("test")
136
+ kind, element, name = mock("kind"), mock("element"), mock("name")
137
+ filename = mock("filename")
138
+
139
+ @processor.should_receive(:kind).and_return(kind)
140
+ kind.should_receive(:output_name).and_return(name)
141
+ test.should_receive(:element).with(name, :error).and_return(element)
142
+ element.should_receive(:as_file).and_return(filename)
143
+
144
+ @processor.error_file(test).should eql(filename)
145
+ end
146
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ require 'ciat/processors/java'
4
+
5
+ describe CIAT::Processors::Java do
6
+ describe "mixins" do
7
+ it "should use basic processing module" do
8
+ CIAT::Processors::Java.should include(CIAT::Processors::BasicProcessing)
9
+ end
10
+
11
+ it "should use HTML differ" do
12
+ CIAT::Processors::Java.should include(CIAT::Differs::HtmlDiffer)
13
+ end
14
+ end
15
+
16
+ it "should have settable options" do
17
+ CIAT::Processors::Java.new(mock("classpath"), mock("interpreter class")) do |executor|
18
+ executor.kind = mock("processor kind")
19
+ executor.description = mock("description")
20
+ end
21
+ end
22
+
23
+ it "should have an executable" do
24
+ @classpath = mock("classpath", :to_s => 'the classpath')
25
+ @interpreter_class = mock("interpreter", :to_s => 'the interpreter')
26
+
27
+ @processor = CIAT::Processors::Java.new(@classpath, @interpreter_class)
28
+ @processor.executable.should == "java -cp 'the classpath' the interpreter"
29
+ end
30
+
31
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ require 'ciat/processors/parrot'
4
+
5
+ describe CIAT::Processors::Parrot do
6
+ describe "mixins" do
7
+ it "should use basic processing module" do
8
+ CIAT::Processors::Parrot.should include(CIAT::Processors::BasicProcessing)
9
+ end
10
+
11
+ it "should use basic processing module" do
12
+ CIAT::Processors::Parrot.should include(CIAT::Differs::HtmlDiffer)
13
+ end
14
+ end
15
+
16
+ describe "default executor" do
17
+ before(:each) do
18
+ @executor = CIAT::Processors::Parrot.new
19
+ end
20
+
21
+ it "should have an executable" do
22
+ @executor.executable.should == "parrot"
23
+ end
24
+ end
25
+
26
+ it "should have settable options" do
27
+ CIAT::Processors::Parrot.new do |executor|
28
+ executor.kind = mock("processor kind")
29
+ executor.description = mock("description")
30
+ executor.libraries = mock("libraries")
31
+ end
32
+ end
33
+
34
+ it "should use system libraries" do
35
+ executor = CIAT::Processors::Parrot.new do |e|
36
+ e.libraries = ["/usr/local/foo", "../bar"]
37
+ end
38
+ executor.executable.should == "parrot -L/usr/local/foo -L../bar"
39
+ end
40
+ end