Skip to content

Commit

Permalink
Inherit from Base formatter instead of Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
StefSchenkelaars committed Apr 3, 2020
1 parent 116f170 commit d9773c2
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 32 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--color
--require spec_helper
--format documentation
--format RSpec::Github::Formatter
13 changes: 1 addition & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,20 @@ PATH
remote: .
specs:
rspec-github (1.0.0.develop)
rspec-core (~> 3.0)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
diff-lcs (1.3)
jaro_winkler (1.5.4)
parallel (1.19.1)
parser (2.7.0.5)
ast (~> 2.4.0)
rainbow (3.0.0)
rexml (3.2.4)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.0)
rspec-support (~> 3.9.0)
rspec-expectations (3.9.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.0)
rubocop (0.81.0)
jaro_winkler (~> 1.5.1)
Expand All @@ -42,7 +32,6 @@ PLATFORMS
ruby

DEPENDENCIES
rspec (~> 3.0)
rspec-github!
rubocop (~> 0.81.0)

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ And to always run it with this formatter, you can set it in the `.rspec` file:
--format RSpec::Github::Formatter
```

Note that you can select multiple formatters so that you can also see other output:
```bash
rspec --format RSpec::Github::Formatter --format progress
rspec --format RSpec::Github::Formatter --format documentation
```

## Development
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.
Publishing a new version is handled by the [publish workflow](.github/workflows/publish.yml). This workflow publishes a GitHub release to [rubygems](https://rubygems.org/) with the version defined in the release.
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'rspec/github/version'
require 'rspec/github/formatter'

module Rspec
module RSpec
module Github
end
end
7 changes: 3 additions & 4 deletions lib/rspec/github/formatter.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# frozen_string_literal: true

require 'rspec/core/formatters/documentation_formatter'
require 'rspec/core'
require 'rspec/core/formatters/base_formatter'

module RSpec
module Github
class Formatter < RSpec::Core::Formatters::DocumentationFormatter
class Formatter < RSpec::Core::Formatters::BaseFormatter
RSpec::Core::Formatters.register self, :example_failed, :example_pending

def example_failed(failure)
super
file, line = failure.example.location.split(':')
output.puts "::error file=#{file},line=#{line}::#{failure.message_lines.join('%0A')}"
end

def example_pending(pending)
super
file, line = pending.example.location.split(':')
output.puts "::warning file=#{file},line=#{line}::#{pending.example.full_description}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/github/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module Rspec
module RSpec
module Github
VERSION = '1.0.0.develop'
end
Expand Down
4 changes: 2 additions & 2 deletions rspec-github.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require_relative 'lib/rspec/github/version'

Gem::Specification.new do |spec|
spec.name = 'rspec-github'
spec.version = Rspec::Github::VERSION
spec.version = RSpec::Github::VERSION
spec.authors = ['Stef Schenkelaars']
spec.email = ['[email protected]']

Expand All @@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
# Specify which files should be added to the gem when it is released.
spec.files = Dir['{lib}/**/*']

spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_runtime_dependency 'rspec-core', '~> 3.0'
spec.add_development_dependency 'rubocop', '~> 0.81.0'
end
16 changes: 4 additions & 12 deletions spec/rspec/github/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@
)
end

it 'still includes the documentation format' do
is_expected.to include "#{example.description} (FAILED"
end

it 'includes the GitHub annotation formatted error' do
is_expected.to include <<~MESSAGE
it 'outputs the GitHub annotation formatted error' do
is_expected.to eq <<~MESSAGE
::error file=./spec/models/user_spec.rb,line=12::#{notification.message_lines.join('%0A')}
MESSAGE
end
Expand All @@ -61,12 +57,8 @@
)
end

it 'still includes the documentation format' do
is_expected.to include "#{example.description} (PENDING: Not yet implemented)"
end

it 'includes the GitHub annotation formatted error' do
is_expected.to include <<~MESSAGE
it 'outputs the GitHub annotation formatted error' do
is_expected.to eq <<~MESSAGE
::warning file=./spec/models/user_spec.rb,line=12::#{example.full_description}
MESSAGE
end
Expand Down

0 comments on commit d9773c2

Please sign in to comment.