Skip to content

Commit f8e6521

Browse files
Revert "Drop old RSpec support"
This reverts commit 9d7203f.
1 parent 3576704 commit f8e6521

File tree

10 files changed

+708
-3
lines changed

10 files changed

+708
-3
lines changed

rspec-maven-plugin/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
<executions>
2121
<execution>
2222
<id>integration-test-no-pom</id>
23+
<configuration>
24+
<pomExcludes>
25+
<pomExclude>rspec1-no-pom/pom.xml</pomExclude>
26+
</pomExcludes>
27+
</configuration>
2328
</execution>
2429
</executions>
2530
</plugin>

rspec-maven-plugin/src/it/rspec-path/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<dependency>
1919
<groupId>rubygems</groupId>
2020
<artifactId>rspec</artifactId>
21-
<version>3.10.0</version>
21+
<version>2.11.0</version>
2222
<type>gem</type>
2323
<scope>test</scope>
2424
</dependency>

rspec-maven-plugin/src/it/without-specs-path/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<dependency>
1919
<groupId>rubygems</groupId>
2020
<artifactId>rspec</artifactId>
21-
<version>3.10.0</version>
21+
<version>2.7.0</version>
2222
<type>gem</type>
2323
<scope>test</scope>
2424
</dependency>

rspec-maven-plugin/src/main/java/de/saumya/mojo/rspec/RSpecMavenTestScriptFactory.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,28 @@ protected void getRunnerScript(StringBuilder builder) {
2424
builder.append("require %q(rspec/core/formatters/html_formatter)\n");
2525
builder.append("\n");
2626

27-
builder.append("require %q(de/saumya/mojo/rspec/rspec3/maven_surefire_reporter)\n");
27+
builder.append("if RSpec::Core::Formatters.respond_to? :register\n");
28+
29+
builder.append(" require %q(de/saumya/mojo/rspec/rspec3/maven_surefire_reporter)\n");
2830
builder.append("::RSpec.configure do |config|\n");
2931
builder.append(" config.add_formatter RSpec::Core::Formatters::ProgressFormatter\n");
3032
builder.append(" config.add_formatter RSpec::Core::Formatters::HtmlFormatter, File.open( \"#{REPORT_PATH}\", 'w' )\n");
3133
builder.append(" config.add_formatter MavenSurefireReporter\n");
3234
builder.append("end\n");
35+
builder.append("else\n");
36+
37+
builder.append(" require %q(de/saumya/mojo/rspec/rspec2/multi_formatter)\n");
38+
builder.append(" require %q(de/saumya/mojo/rspec/rspec2/maven_console_progress_formatter)\n");
39+
builder.append(" require %q(de/saumya/mojo/rspec/rspec2/maven_surefire_reporter)\n");
40+
builder.append(" require %q(de/saumya/mojo/rspec/rspec2/monkey_patch)\n");
41+
builder.append("::MultiFormatter.formatters << [ MavenConsoleProgressFormatter, nil ]\n");
42+
builder.append("::MultiFormatter.formatters << [ MavenSurefireReporter, \"#{TARGET_DIR}\" ] \n");
43+
builder.append("::MultiFormatter.formatters << [ RSpec::Core::Formatters::HtmlFormatter, File.open( \"#{REPORT_PATH}\", 'w' ) ] \n");
44+
builder.append("\n");
45+
builder.append("::RSpec.configure do |config|\n");
46+
builder.append(" config.formatter = ::MultiFormatter\n");
47+
builder.append("end\n");
48+
builder.append("end\n");
3349
builder.append("\n");
3450
builder.append("::RSpec::Core::Runner.disable_autorun!\n");
3551
builder.append("RESULT = ::RSpec::Core::Runner.run( run_args, STDERR, STDOUT)\n");
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
require 'spec/runner/formatter/base_formatter'
3+
4+
class MojoLog
5+
6+
def info(str)
7+
puts str
8+
end
9+
10+
end
11+
12+
MOJO_LOG = MojoLog.new
13+
14+
class MavenConsoleProgressFormatter < Spec::Runner::Formatter::BaseFormatter
15+
16+
def initialize(options, where)
17+
super( options, where )
18+
@first = true
19+
@passing = []
20+
@pending = []
21+
@failing = []
22+
@filename = nil
23+
end
24+
25+
def example_group_started(example_group)
26+
#MOJO_LOG.info( "spec dir #{SPEC_DIR}")
27+
#MOJO_LOG.info( "location #{example_group.location}" )
28+
unless ( @first )
29+
MOJO_LOG.info( " #{@passing.size} passing; #{@failing.size} failing; #{@pending.size} pending")
30+
end
31+
@first = false
32+
@passing = []
33+
@pending = []
34+
@failing = []
35+
example_group.location =~ /^(.*):([0-9])+/
36+
filename = $1
37+
lineno = $2
38+
filename = filename[ SPEC_DIR.length..-1 ]
39+
if ( filename[0,1] == "/" )
40+
filename = filename[1..-1]
41+
end
42+
unless ( @filename == filename )
43+
@filename = filename
44+
MOJO_LOG.info( "SPEC: #{@filename}" )
45+
end
46+
47+
MOJO_LOG.info( " - #{example_group.description}" )
48+
super( example_group )
49+
end
50+
51+
def example_passed(example)
52+
@passing << example
53+
end
54+
55+
def example_pending(example, message)
56+
@pending << example
57+
end
58+
59+
def example_failed(example, counter, failure)
60+
@failing << example
61+
end
62+
63+
def dump_summary(duration, example_count, failure_count, pending_count)
64+
unless ( @first )
65+
MOJO_LOG.info( " #{@passing.size} passing; #{@failing.size} failing; #{@pending.size} pending")
66+
end
67+
pass_count = example_count - ( failure_count + pending_count )
68+
MOJO_LOG.info( "=========================================" )
69+
MOJO_LOG.info( "TOTAL: #{pass_count} passing; #{failure_count} failing; #{pending_count} pending")
70+
71+
if SUMMARY_REPORT
72+
73+
# Creating the XML report
74+
FileUtils.mkdir_p File.dirname SUMMARY_REPORT
75+
content = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
76+
<testsuite failures=\"#{failure_count}\" time=\"#{duration}\" errors=\"0\" skipped=\"#{pending_count}\" tests=\"#{example_count}\" name=\"Ruby\">\n"
77+
78+
# Passing
79+
@passing.each { |test|
80+
content = content + "<testcase time=\"0.0\" name=\"#{test.description}\"/>\n"
81+
}
82+
83+
# Pending - considering as failures
84+
@pending.each { |test|
85+
content = content + "<testcase time=\"0.0\" name=\"#{test.description}\"><failure></failure></testcase>\n"
86+
}
87+
88+
# Failures
89+
@failing.each { |test|
90+
content = content + "<testcase time=\"0.0\" name=\"#{test.description}\"><failure></failure></testcase>\n"
91+
}
92+
93+
content = content + "</testsuite>"
94+
95+
File.open(SUMMARY_REPORT, 'w+') {|f| f.write(content) }
96+
end
97+
end
98+
99+
end
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
2+
require 'spec/runner/formatter/base_formatter'
3+
4+
5+
class FileInfo
6+
attr_accessor :path
7+
attr_accessor :groups
8+
9+
def initialize(path)
10+
@path = path
11+
@groups = []
12+
end
13+
14+
def duration
15+
@groups.inject(0){|sum,e|sum+=e.duration}
16+
end
17+
18+
def examples
19+
@groups.collect{|e| e.examples}.flatten
20+
end
21+
22+
def passing
23+
@groups.collect{|e| e.passing}.flatten
24+
end
25+
26+
def failing
27+
@groups.collect{|e| e.failing}.flatten
28+
end
29+
30+
def pending
31+
@groups.collect{|e| e.pending}.flatten
32+
end
33+
34+
end
35+
36+
class GroupInfo
37+
attr_accessor :rspec_group
38+
attr_accessor :examples
39+
40+
def initialize(rspec_group)
41+
@rspec_group = rspec_group
42+
@examples = []
43+
end
44+
45+
def duration
46+
@examples.inject(0){|sum,e|sum+=e.duration}
47+
end
48+
49+
def passing
50+
@examples.select{|e| e.status == :passing }
51+
end
52+
53+
def failing
54+
@examples.select{|e| e.status == :failing }
55+
end
56+
57+
def pending
58+
@examples.select{|e| e.status == :pending }
59+
end
60+
61+
end
62+
63+
class ExampleInfo
64+
attr_accessor :rspec_example
65+
attr_accessor :duration
66+
attr_accessor :status
67+
68+
attr_accessor :failure
69+
attr_accessor :message
70+
71+
def initialize(rspec_example)
72+
@rspec_example = rspec_example
73+
@duration = 0
74+
@start_time = Time.now
75+
@status = :pending
76+
end
77+
78+
def finish()
79+
@duration = ( Time.now - @start_time ).to_f
80+
end
81+
end
82+
83+
84+
class MavenSurefireReporter < Spec::Runner::Formatter::BaseFormatter
85+
86+
attr_accessor :output
87+
88+
def initialize(options, output)
89+
super( options, output )
90+
@file_info = {}
91+
92+
@output = output
93+
94+
@current_file_info = nil
95+
@current_group_info = nil
96+
@current_example_info = nil
97+
end
98+
99+
def files
100+
@file_info.values
101+
end
102+
103+
def example_group_started(example_group)
104+
setup_current_file_info( example_group )
105+
setup_current_group_info( example_group )
106+
@current_group = example_group
107+
end
108+
109+
def setup_current_file_info(example_group)
110+
filename = filename_for( example_group )
111+
@current_file_info = @file_info[ filename ]
112+
if ( @current_file_info.nil? )
113+
@current_file_info = FileInfo.new( filename )
114+
@file_info[ filename ] = @current_file_info
115+
end
116+
end
117+
118+
def setup_current_group_info(example_group)
119+
@current_group_info = GroupInfo.new( example_group )
120+
@current_file_info.groups << @current_group_info
121+
end
122+
123+
def setup_current_example_info(example)
124+
@current_example_info = ExampleInfo.new( example )
125+
@current_group_info.examples << @current_example_info
126+
end
127+
128+
def filename_for(example_group)
129+
example_group.location =~ /^(.*):([0-9])+/
130+
filename = $1
131+
lineno = $2
132+
filename = filename[ SPEC_DIR.length..-1 ]
133+
if ( filename[0,1] == "/" )
134+
filename = filename[1..-1]
135+
end
136+
filename
137+
end
138+
139+
def example_started(example)
140+
example_finished() unless ( @current_example.nil? )
141+
142+
setup_current_example_info( example )
143+
end
144+
145+
def example_finished()
146+
@current_example_info.finish
147+
@current_example_info = nil
148+
end
149+
150+
def example_passed(example)
151+
@current_example_info.status = :passing
152+
example_finished
153+
end
154+
155+
def example_failed(example, counter, failure)
156+
return unless @current_example_info
157+
@current_example_info.status = :failing
158+
@current_example_info.failure = failure
159+
example_finished
160+
end
161+
162+
def example_pending(example, message)
163+
@current_example_info.status = :pending
164+
@current_example_info.failure = message
165+
example_finished
166+
end
167+
168+
def xml_escape(str)
169+
str.gsub( /&/, '&amp;' ).gsub( /"/, '&quot;' )
170+
end
171+
172+
def start_dump
173+
files.each do |f|
174+
output_filename = File.join( output, "TEST-#{File.basename(f.path, '.rb')}" ) + '.xml'
175+
FileUtils.mkdir_p( File.dirname( output_filename ) )
176+
File.open( output_filename, 'w' ) do |output|
177+
output.puts( %Q(<?xml version="1.0" encoding="UTF-8" ?>) )
178+
output.puts( %Q(<testsuite name="#{f.path}" time="#{f.duration}" tests="#{f.examples.size}" errors="#{f.failing.size}" skipped="#{f.pending.size}">) )
179+
f.groups.each do |g|
180+
g.examples.each do |ex|
181+
case_name = xml_escape( g.rspec_group.description + ' ' + ex.rspec_example.description )
182+
output.puts( %Q( <testcase time="#{ex.duration}" name="#{case_name}">) )
183+
if ( ex.status == :pending )
184+
output.puts( %Q( <skipped/>) )
185+
elsif ( ex.status == :failing )
186+
output.puts( %Q( <failure/>) )
187+
end
188+
output.puts( %Q( </testcase>) )
189+
end
190+
end
191+
output.puts( %Q(</testsuite>) )
192+
end
193+
end
194+
end
195+
196+
end

0 commit comments

Comments
 (0)