Skip to content

Commit b54a574

Browse files
author
Andreas Alin
committedJan 27, 2010
initial commit
0 parents  commit b54a574

6 files changed

+136
-0
lines changed
 

‎README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Ruby-Processing spec formatter
2+
3+
## Requirements
4+
5+
* [JRuby](http://jruby.org/)
6+
* [RSpec](http://github.com/dchelimsky/rspec) (gem install rspec)
7+
* [Ruby-Processing](http://wiki.github.com/jashkenas/ruby-processing/) (gem install ruby-processing)
8+
9+
## How to run
10+
11+
Type:
12+
13+
jruby -S rake spec
14+

‎Rakefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require 'rubygems'
2+
require 'spec'
3+
require 'spec/rake/spectask'
4+
5+
namespace :spec do
6+
desc 'Run specs'
7+
Spec::Rake::SpecTask.new(:run) do |t|
8+
t.spec_opts << '--require' << 'lib/processing_formatter'
9+
t.spec_opts << '--format ProcessingFormatter'
10+
t.spec_files = Dir.glob(File.join(File.dirname(__FILE__), 'spec/**/*_spec.rb'))
11+
end
12+
end
13+
14+
desc 'Run specs'
15+
task :spec => 'spec:run'
16+

‎lib/.processing_formatter.rb.swp

12 KB
Binary file not shown.

‎lib/processing_formatter.rb

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
require 'rubygems'
2+
require 'ruby-processing'
3+
require 'spec/runner/formatter/base_formatter'
4+
5+
module Processing ; SKETCH_PATH = __FILE__ ; end
6+
7+
class SpecSketch < Processing::App
8+
attr_reader :number_of_examples
9+
10+
def setup
11+
smooth
12+
no_stroke
13+
frame_rate 30
14+
color_mode RGB, 1
15+
16+
reset_number_of_examples!(0)
17+
end
18+
19+
def reset_number_of_examples!(num)
20+
@number_of_examples = num
21+
@results = []
22+
end
23+
24+
def add_result!(result)
25+
@results << result
26+
end
27+
28+
def draw
29+
background(0)
30+
31+
if number_of_examples > 0
32+
example_width = self.width / number_of_examples.to_f
33+
34+
number_of_examples.times do |i|
35+
case @results[i]
36+
when :passed
37+
fill(0.0, 1.0, 0.0)
38+
when :failed
39+
fill(1.0, 0.0, 0.0)
40+
when :pending
41+
fill(1.0, 1.0, 0.0)
42+
else
43+
fill(0.3, 0.3, 0.3)
44+
end
45+
46+
x = i * example_width
47+
rect(x, 0, example_width, self.height)
48+
end
49+
end
50+
end
51+
end
52+
53+
class ProcessingFormatter < Spec::Runner::Formatter::BaseFormatter
54+
def initialize(options, output)
55+
@sketch = SpecSketch.new(:width => 800, :height => 800, :title => "Spec Sketch")
56+
end
57+
58+
def start(example_count)
59+
@sketch.reset_number_of_examples!(example_count)
60+
end
61+
62+
def example_group_started(example_group_proxy)
63+
end
64+
65+
def example_started(example_proxy)
66+
sleep 0.1
67+
end
68+
69+
def example_passed(example_proxy)
70+
@sketch.add_result! :passed
71+
end
72+
73+
def example_failed(example_proxy, counter, failure)
74+
@sketch.add_result! :failed
75+
end
76+
77+
def example_pending(example_proxy, message, deprecated_pending_location=nil)
78+
@sketch.add_result! :pending
79+
end
80+
81+
def close
82+
@sketch.close
83+
end
84+
end

‎spec/lib/fail_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require File.join(File.dirname(__FILE__), '../spec_helper')
2+
3+
class Fail
4+
end
5+
6+
describe Fail do
7+
100.times do
8+
if (rand(10) % 3).zero?
9+
it('should fail') { true.should be_false }
10+
else
11+
it('should win') { true.should be_true }
12+
end
13+
end
14+
end

‎spec/spec_helper.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'rubygems'
2+
require 'spec'
3+
4+
$LOAD_PATH.push(File.join(File.dirname(__FILE__), '../lib'))
5+
6+
Spec::Runner.configure do |config|
7+
end
8+

0 commit comments

Comments
 (0)
Please sign in to comment.