rocha 0.1.0
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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +25 -0
- data/Rakefile +2 -0
- data/lib/rocha/formatter.rb +80 -0
- data/lib/rocha/reporter/example.rb +34 -0
- data/lib/rocha/reporter/example_group.rb +37 -0
- data/lib/rocha/reporter/metadata.rb +80 -0
- data/lib/rocha/reporter.rb +95 -0
- data/lib/rocha/version.rb +3 -0
- data/lib/rocha.rb +12 -0
- data/rocha.gemspec +19 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 tchak
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Rocha
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'rocha'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install rocha
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
1. Fork it
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require "colorize"
|
2
|
+
|
3
|
+
module Rocha
|
4
|
+
class Formatter
|
5
|
+
attr_reader :io, :examples
|
6
|
+
|
7
|
+
def initialize(io)
|
8
|
+
@io = io
|
9
|
+
@examples = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def start(expected_example_count=nil); end
|
13
|
+
def example_group_started(group); end
|
14
|
+
def example_started(example); end
|
15
|
+
|
16
|
+
def example_passed(example)
|
17
|
+
@examples << example
|
18
|
+
io.write(".".green)
|
19
|
+
end
|
20
|
+
|
21
|
+
def example_failed(example)
|
22
|
+
@examples << example
|
23
|
+
io.write("F".red)
|
24
|
+
end
|
25
|
+
|
26
|
+
def example_pending(example)
|
27
|
+
@examples << example
|
28
|
+
io.write("P".yellow)
|
29
|
+
end
|
30
|
+
|
31
|
+
def example_group_finished(group); end
|
32
|
+
def stop; end
|
33
|
+
|
34
|
+
def start_dump
|
35
|
+
io.puts ""
|
36
|
+
end
|
37
|
+
|
38
|
+
def dump_pending
|
39
|
+
pending_examples = examples.select(&:pending?)
|
40
|
+
if pending_examples.present?
|
41
|
+
io.puts ""
|
42
|
+
io.puts(pending_examples.map {|example| pending_message(example)}.join("\n\n"))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def dump_failures
|
47
|
+
failed_examples = examples.select(&:failed?)
|
48
|
+
if failed_examples.present?
|
49
|
+
io.puts ""
|
50
|
+
io.puts(failed_examples.map {|example| failure_message(example)}.join("\n\n"))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def dump_summary(duration, example_count, failure_count, pending_count)
|
55
|
+
seconds = "%.2f" % duration
|
56
|
+
io.puts ""
|
57
|
+
io.puts "Finished in #{seconds} seconds"
|
58
|
+
io.puts "#{example_count} examples, #{failure_count} failed, #{pending_count} pending"
|
59
|
+
end
|
60
|
+
|
61
|
+
def seed(seed); end
|
62
|
+
|
63
|
+
def close
|
64
|
+
io.close if IO === io && io != $stdout
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def failure_message(example)
|
69
|
+
msg = []
|
70
|
+
msg << " Failed: #{example.full_description}"
|
71
|
+
msg << " #{example.exception.message}"
|
72
|
+
msg << " in #{example.exception.backtrace.first}" if example.exception.backtrace.present?
|
73
|
+
msg.join("\n").red
|
74
|
+
end
|
75
|
+
|
76
|
+
def pending_message(example)
|
77
|
+
" Pending: #{example.full_description}".yellow
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "rocha/reporter/metadata"
|
2
|
+
|
3
|
+
# The Example class mimics the public interface of RSpec::Core::Example.
|
4
|
+
|
5
|
+
module Rocha
|
6
|
+
class Reporter
|
7
|
+
class Example
|
8
|
+
attr_reader :metadata, :parent
|
9
|
+
|
10
|
+
def initialize(data, parent)
|
11
|
+
@metadata = Metadata.new(data)
|
12
|
+
@parent = parent
|
13
|
+
end
|
14
|
+
|
15
|
+
delegate :full_description, :description, :location, :file_path, :line_number, :pending, :pending_message, :exception, :execution_result, :to => :metadata
|
16
|
+
|
17
|
+
alias_method :pending?, :pending
|
18
|
+
alias_method :options, :metadata
|
19
|
+
alias_method :example_group, :parent
|
20
|
+
|
21
|
+
def passed?
|
22
|
+
execution_result[:status] == "passed"
|
23
|
+
end
|
24
|
+
|
25
|
+
def failed?
|
26
|
+
execution_result[:status] == "failed"
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_metadata(data)
|
30
|
+
metadata.update(data)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "rocha/reporter/metadata"
|
2
|
+
|
3
|
+
# The ExampleGroup class mimics the public interface of RSpec::Core::ExampleGroup.
|
4
|
+
|
5
|
+
module Rocha
|
6
|
+
class Reporter
|
7
|
+
class ExampleGroup
|
8
|
+
attr_reader :metadata, :parent
|
9
|
+
|
10
|
+
def initialize(data, parent)
|
11
|
+
@metadata = Metadata.new(data)
|
12
|
+
@parent = parent
|
13
|
+
end
|
14
|
+
|
15
|
+
delegate :full_description, :description, :file_path, :described_class, :to => :metadata
|
16
|
+
|
17
|
+
alias_method :display_name, :description
|
18
|
+
|
19
|
+
def parent_groups
|
20
|
+
ancestor = parent
|
21
|
+
groups = []
|
22
|
+
while ancestor
|
23
|
+
groups << ancestor
|
24
|
+
ancestor = ancestor.parent
|
25
|
+
end
|
26
|
+
|
27
|
+
groups
|
28
|
+
end
|
29
|
+
|
30
|
+
alias_method :ancestors, :parent_groups
|
31
|
+
|
32
|
+
def update_metadata(data)
|
33
|
+
metadata.update(data)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# The Metadata class mimics the public interface of RSpec::Core::Metadata.
|
2
|
+
|
3
|
+
module Rocha
|
4
|
+
class Reporter
|
5
|
+
class SpecException < Exception
|
6
|
+
def pending_fixed?
|
7
|
+
false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Metadata
|
12
|
+
attr_reader :data
|
13
|
+
|
14
|
+
def initialize(data)
|
15
|
+
@data = data
|
16
|
+
end
|
17
|
+
|
18
|
+
def [](key)
|
19
|
+
respond_to?(key) ? send(key) : data[key]
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(data)
|
23
|
+
@data.merge!(data)
|
24
|
+
end
|
25
|
+
|
26
|
+
def file_path
|
27
|
+
data['path']
|
28
|
+
end
|
29
|
+
|
30
|
+
alias_method :location, :file_path
|
31
|
+
|
32
|
+
def line_number
|
33
|
+
STDERR.puts "line_number not implemented" if Rocha.verbose
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def execution_result
|
38
|
+
@execution_result ||= {
|
39
|
+
:status => data['status'],
|
40
|
+
:started_at => nil,
|
41
|
+
:finished_at => nil,
|
42
|
+
:run_time => data['duration'],
|
43
|
+
:exception => exception
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def exception
|
48
|
+
return unless data['status'] == "failed"
|
49
|
+
|
50
|
+
@exception ||= begin
|
51
|
+
e = Reporter::SpecException.new("#{data['error']['name']}: #{data['error']['message']}")
|
52
|
+
e.set_backtrace([])
|
53
|
+
e
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def pending_message
|
58
|
+
STDERR.puts "pending_message not implemented" if Rocha.verbose
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def described_class
|
63
|
+
STDERR.puts "described_class not implemented" if Rocha.verbose
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def pending
|
68
|
+
data['status'] == "pending"
|
69
|
+
end
|
70
|
+
|
71
|
+
def description
|
72
|
+
data['title']
|
73
|
+
end
|
74
|
+
|
75
|
+
def full_description
|
76
|
+
data['fullTitle']
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require "rocha/reporter/example"
|
2
|
+
require "rocha/reporter/example_group"
|
3
|
+
|
4
|
+
# The Rocha Reporter implements the same protocol as the RSpec Reporter.
|
5
|
+
# More details on the RSpec Reporter protocol are available in the rspec-core
|
6
|
+
# repository: https://github.com/rspec/rspec-core/blob/1852a7f4221c5731e108484cb2debfbaca60b283/lib/rspec/core/formatters/base_formatter.rb#L8-L25
|
7
|
+
|
8
|
+
module Rocha
|
9
|
+
class Reporter
|
10
|
+
EVENT_CONVERSIONS = {
|
11
|
+
'suite' => :example_group_started,
|
12
|
+
'test' => :example_started,
|
13
|
+
'pass' => :example_passed,
|
14
|
+
'fail' => :example_failed,
|
15
|
+
'pending' => :example_pending,
|
16
|
+
'suite end' => :example_group_finished,
|
17
|
+
}
|
18
|
+
|
19
|
+
attr_reader :start_time, :duration, :example_count, :failure_count, :pending_count
|
20
|
+
|
21
|
+
def initialize(*formatters)
|
22
|
+
@formatters = formatters
|
23
|
+
@example_count = @failure_count = @pending_count = 0
|
24
|
+
@duration = @start_time = nil
|
25
|
+
@examples, @groups = {}, {}
|
26
|
+
end
|
27
|
+
|
28
|
+
def start(expected_example_count=nil)
|
29
|
+
@start_time = Time.now
|
30
|
+
process_event :start, expected_example_count
|
31
|
+
end
|
32
|
+
|
33
|
+
def finish(seed=nil)
|
34
|
+
begin
|
35
|
+
stop
|
36
|
+
process_event :start_dump
|
37
|
+
process_event :dump_pending
|
38
|
+
process_event :dump_failures
|
39
|
+
process_event :dump_summary, @duration, @example_count, @failure_count, @pending_count
|
40
|
+
process_event :seed, seed if seed
|
41
|
+
ensure
|
42
|
+
process_event :close
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def stop
|
47
|
+
@duration = Time.now - @start_time if @start_time
|
48
|
+
process_event :stop
|
49
|
+
end
|
50
|
+
|
51
|
+
def passed?
|
52
|
+
@examples.values.all? { |example| example.passed? || example.pending? }
|
53
|
+
end
|
54
|
+
|
55
|
+
def process_mocha_event(event)
|
56
|
+
if event['event'] == 'start'
|
57
|
+
start(event['testCount'])
|
58
|
+
elsif event['event'] == 'end'
|
59
|
+
finish
|
60
|
+
elsif event['type']
|
61
|
+
object = update_or_create_object(event['data'], event['type'])
|
62
|
+
process_event EVENT_CONVERSIONS[event['event']], object
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def process_event(method, *args, &block)
|
67
|
+
case method
|
68
|
+
when :example_started
|
69
|
+
@example_count += 1
|
70
|
+
when :example_failed
|
71
|
+
@failure_count += 1
|
72
|
+
when :example_pending
|
73
|
+
@pending_count += 1
|
74
|
+
end
|
75
|
+
|
76
|
+
@formatters.each do |formatter|
|
77
|
+
formatter.send method, *args, &block
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def update_or_create_object(data, type)
|
82
|
+
collection = type == 'test' ? @examples : @groups
|
83
|
+
object = collection[data['fullTitle']]
|
84
|
+
if object
|
85
|
+
object.update_metadata(data)
|
86
|
+
else
|
87
|
+
klass = type == 'test' ? Example : ExampleGroup
|
88
|
+
parent = @groups[data['parentFullTitle']]
|
89
|
+
object = collection[data['fullTitle']] = klass.new(data, parent)
|
90
|
+
end
|
91
|
+
|
92
|
+
object
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/rocha.rb
ADDED
data/rocha.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rocha/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["tchak"]
|
6
|
+
gem.email = ["paul@chavard.net"]
|
7
|
+
gem.description = %q{RSpec reporter for mocha}
|
8
|
+
gem.summary = %q{RSpec reporter for mocha}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.add_dependency "colorize"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.name = "rocha"
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
gem.version = Rocha::VERSION
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rocha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- tchak
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: colorize
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: RSpec reporter for mocha
|
31
|
+
email:
|
32
|
+
- paul@chavard.net
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/rocha.rb
|
43
|
+
- lib/rocha/formatter.rb
|
44
|
+
- lib/rocha/reporter.rb
|
45
|
+
- lib/rocha/reporter/example.rb
|
46
|
+
- lib/rocha/reporter/example_group.rb
|
47
|
+
- lib/rocha/reporter/metadata.rb
|
48
|
+
- lib/rocha/version.rb
|
49
|
+
- rocha.gemspec
|
50
|
+
homepage: ''
|
51
|
+
licenses: []
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.23
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: RSpec reporter for mocha
|
74
|
+
test_files: []
|