Skip to content

Commit 459697b

Browse files
committed
Add Yardoc
1 parent d940552 commit 459697b

18 files changed

+396
-12
lines changed

.codeclimate.yml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ plugins:
4141
config:
4242
file: ".rubocop.yml"
4343
exclude_patterns:
44+
- "doc/"
4445
- "gemfiles/"
4546
- "manual/"
4647
- "resources/"

.rubocop.yml

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ require:
33
- rubocop-rspec
44
AllCops:
55
TargetRubyVersion: 2.3
6-
Documentation:
7-
Enabled: false
86
Layout/ClassStructure:
97
Enabled: true
108
Categories:

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ before_install:
3434
before_script:
3535
- ./cc-test-reporter before-build
3636
script:
37+
- bundle exec rake
3738
- |
3839
for i in `seq 0 9`
3940
do
4041
BUNDLE_GEMFILE=gemfiles/rspec_3_$i.gemfile bundle install
41-
BUNDLE_GEMFILE=gemfiles/rspec_3_$i.gemfile bundle exec rubocop
4242
BUNDLE_GEMFILE=gemfiles/rspec_3_$i.gemfile bundle exec rspec spec
4343
done
4444
after_script:

.yardopts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
--markup markdown
2-
--hide-void-return
2+
--default-return ''
3+
--private

CHANGELOG.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## v0.1.0 (November 1, 2019)
2-
- First release
3-
- Added support for four TAP formats:
4-
- RSpec::TAP::Formatters::Default
5-
- RSpec::TAP::Formatters::Compact
6-
- RSpec::TAP::Formatters::Flat
7-
- RSpec::TAP::Formatters::FlatCompact
2+
**First Release**
3+
- Added support for four TAP formats:
4+
- RSpec::TAP::Formatters::Default
5+
- RSpec::TAP::Formatters::Compact
6+
- RSpec::TAP::Formatters::Flat
7+
- RSpec::TAP::Formatters::FlatCompact

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[![Build Status](https://travis-ci.com/avmnu-sng/rspec-tap-formatters.svg?branch=master)](https://travis-ci.com/avmnu-sng/rspec-tap-formatters)
22
[![Documentation Status](https://readthedocs.org/projects/rspec-tap-formatters/badge/?version=latest)](https://rspec-tap-formatters.readthedocs.io/en/latest/?badge=latest)
3+
[![Maintainability](https://api.codeclimate.com/v1/badges/7dd41099b7e8569fc7ec/maintainability)](https://codeclimate.com/github/avmnu-sng/rspec-tap-formatters/maintainability)
4+
[![Test Coverage](https://api.codeclimate.com/v1/badges/7dd41099b7e8569fc7ec/test_coverage)](https://codeclimate.com/github/avmnu-sng/rspec-tap-formatters/test_coverage)
35

46
**RSpec TAP Formatters** provides four different [TAP 13](https://testanything.org/tap-version-13-specification.html) format style with
57
a proper nested display of example groups and includes stats for the total

Rakefile

+31-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@ require 'bundler/setup'
44
require 'bundler/gem_tasks'
55
require 'rspec/core/rake_task'
66

7+
desc 'Generate doc'
8+
task :doc do
9+
sh 'yardoc'
10+
end
11+
12+
desc 'Verify doc coverage'
13+
task :verify_doc do
14+
sh <<-SCRIPT.gsub(/^\s+\|/, '').chomp
15+
|yard stats --list-undoc | ruby -e "
16+
| while (line = gets)
17+
| warnings ||= line.start_with?('[warn]:')
18+
| coverage ||= line[/([\\d\.]+)% documented/, 1]
19+
| end
20+
|
21+
| exit(1) if warnings || Float(coverage) != 100
22+
|"
23+
SCRIPT
24+
25+
sh <<-SCRIPT.gsub(/^\s+\|/, '').chomp
26+
|yard doc --no-cache | ruby -e "
27+
| while (line = gets)
28+
| warnings ||= line.start_with?('[warn]:')
29+
| errors ||= line.start_with?('[error]:')
30+
| end
31+
|
32+
| exit(1) if warnings || errors
33+
|"
34+
SCRIPT
35+
end
36+
737
desc 'Run Rubocop'
838
task :rubocop do
939
sh 'bundle exec rubocop'
@@ -12,4 +42,4 @@ end
1242
desc 'Run all examples'
1343
RSpec::Core::RakeTask.new(:spec)
1444

15-
task default: %i[rubocop spec]
45+
task default: %i[verify_doc rubocop spec]

bin/console

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
require 'bundler/setup'
55
require 'pry'
6+
require 'rspec/core'
67
require 'rspec/tap/formatters'
78

89
ARGV.clear

lib/rspec/tap/formatters/compact.rb

+38
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
module RSpec
88
module TAP
99
module Formatters
10+
# Compact TAP formatter
1011
class Compact < RSpec::Core::Formatters::BaseFormatter
12+
# List of subscribed notifications
1113
NOTIFICATIONS = %i[
1214
seed
1315
start
@@ -36,27 +38,40 @@ def initialize(output)
3638
@example_number = 0
3739
end
3840

41+
# Seed notification
42+
#
43+
# @param notification [SeedNotification]
3944
def seed(notification)
4045
@seed = notification.seed if notification.seed_used?
4146
end
4247

48+
# Start notification
49+
#
50+
# @param notification [StartNotification]
4351
def start(notification)
4452
super
4553

4654
@printer.start_output
4755
end
4856

57+
# Execution finished notification
4958
def start_dump(_notification)
5059
@printer.example_progress_dump
5160
end
5261

62+
# Example group start notification
63+
#
64+
# @param notification [GroupNotification]
5365
def example_group_started(notification)
5466
@printer.group_start_output(notification, @level)
5567

5668
@level += 1
5769
@example_number = 0
5870
end
5971

72+
# Example group finish notification
73+
#
74+
# @param notification [GroupNotification]
6075
def example_group_finished(notification)
6176
@printer.group_finished_output(
6277
@test_stats.data[notification.group.metadata[:line_number]],
@@ -67,10 +82,14 @@ def example_group_finished(notification)
6782
@test_stats = TestStats.new if @level.zero?
6883
end
6984

85+
# Example start notification
7086
def example_started(_notification)
7187
@example_number += 1
7288
end
7389

90+
# Passing example notification
91+
#
92+
# @param notification [ExampleNotification]
7493
def example_passed(notification)
7594
@test_stats.populate(notification, 1)
7695
@printer.example_progress_output(:success)
@@ -81,6 +100,9 @@ def example_passed(notification)
81100
)
82101
end
83102

103+
# Failing example notification
104+
#
105+
# @param notification [FailedExampleNotification]
84106
def example_failed(notification)
85107
@test_stats.populate(notification, 2)
86108
@printer.example_progress_output(:failure)
@@ -91,6 +113,10 @@ def example_failed(notification)
91113
)
92114
end
93115

116+
# Pending example notification
117+
#
118+
# @param notification [PendingExampleFailedAsExpectedNotification
119+
# , SkippedExampleException]
94120
def example_pending(notification)
95121
@test_stats.populate(notification, 3)
96122
@printer.example_progress_output(:pending)
@@ -102,18 +128,30 @@ def example_pending(notification)
102128
)
103129
end
104130

131+
# Failure outside of example notification
132+
#
133+
# @param notification [MessageNotification]
105134
def message(notification)
106135
@printer.message_output(notification)
107136
end
108137

138+
# Failure examples notification
139+
#
140+
# @param notification [ExamplesNotification]
109141
def dump_failures(notification)
110142
@printer.store_failed_examples_summary(notification)
111143
end
112144

145+
# Pending examples notification
146+
#
147+
# @param notification [ExamplesNotification]
113148
def dump_pending(notification)
114149
@printer.store_pending_examples_summary(notification)
115150
end
116151

152+
# Examples summary notification
153+
#
154+
# @param notification [SummaryNotification]
117155
def dump_summary(notification)
118156
@printer.summary_output(notification, @seed)
119157
end

lib/rspec/tap/formatters/core_ext/hash.rb

+25
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
# frozen_string_literal: true
22

3+
# Extensions to the core String class
34
class Hash
45
unless method_defined?(:compact)
6+
# Removes nil and blank values.
7+
# The value is either +NilClass+ or +String+.
8+
#
9+
# @return [Hash] compact hash
10+
#
11+
# @example
12+
# { you: 0, me: nil, we: ' ' }.compact
13+
# #=> { you: 0 }
514
def compact
615
reject { |_, value| value.nil? || value.blank? }
716
end
817
end
918

1019
unless method_defined?(:transform_keys)
20+
# Transforms hash keys.
21+
# The value is either +NilClass+ or +String+.
22+
#
23+
# @return [Hash] with transformed keys
24+
#
25+
# @example
26+
# { you: 0, me: nil, we: ' '}.transform_keys(&:upcase)
27+
# #=> { YOU: 0, ME: nil, WE: ' '}
1128
def transform_keys
1229
return enum_for(:transform_keys) { size } unless block_given?
1330

@@ -20,6 +37,14 @@ def transform_keys
2037
end
2138

2239
unless method_defined?(:stringify_keys)
40+
# Transforms hash keys by using +to_s+.
41+
# The value is either +NilClass+ or +String+.
42+
#
43+
# @return [Hash] with transformed keys
44+
#
45+
# @example
46+
# { you: 0, me: nil, we: ' '}.stringify_keys
47+
# #=> { "you" => 0, "me" => nil, "we" => ' '}
2348
def stringify_keys
2449
transform_keys(&:to_s)
2550
end

lib/rspec/tap/formatters/core_ext/string.rb

+33
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
11
# frozen_string_literal: true
22

3+
# Extensions to the core String class
34
class String
45
unless method_defined?(:blank?)
6+
# Checks whether a string is blank. A string is considered blank if it
7+
# is either empty or contains only whitespaces.
8+
#
9+
# @return [Boolean] true is the string is blank, false otherwise
10+
#
11+
# @example
12+
# ''.blank?
13+
# #=> true
14+
#
15+
# @example
16+
# ' '.blank?
17+
# #=> true
18+
#
19+
# @example
20+
# ' abc '.blank?
21+
# #=> false
522
def blank?
623
empty? || strip.empty?
724
end
825
end
926

1027
unless method_defined?(:present?)
28+
# Checks whether a string is present. A string is considered present if it
29+
# is not blank.
30+
#
31+
# @return [Boolean] true is the string is present, false otherwise
32+
#
33+
# @example
34+
# ''.present?
35+
# #=> false
36+
#
37+
# @example
38+
# ' '.present?
39+
# #=> false
40+
#
41+
# @example
42+
# ' abc '.present?
43+
# #=> true
1144
def present?
1245
!blank?
1346
end

0 commit comments

Comments
 (0)