Skip to content

Commit

Permalink
Track coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynetics committed May 14, 2023
1 parent 9ebcfaf commit 1a934f3
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ jobs:
bundler-cache: true
- name: Run the default task
run: bundle exec rake
- uses: codecov/codecov-action@v3
if: matrix.ruby == '3.2.0'
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ gemspec
# gem 'regexp_parser', path: '../regexp_parser'

gem "rake", "~> 13.0"

gem "rspec", "~> 3.0"
gem "simplecov-cobertura"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# Repper

[![Gem Version](https://badge.fury.io/rb/repper.svg)](http://badge.fury.io/rb/repper)
[![Build Status](https://github.com/jaynetics/repper/actions/workflows/main.yml/badge.svg)](https://github.com/jaynetics/repper/actions)
[![Coverage](https://codecov.io/gh/jaynetics/repper/branch/main/graph/badge.svg?token=0993K9I8VC)](https://codecov.io/gh/jaynetics/repper)

Repper is a regular expression pretty printer and formatter for Ruby.

## Installation
Expand Down
15 changes: 15 additions & 0 deletions spec/repper/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,20 @@
.to output.to_stderr
.and raise_error(SystemExit) { |e| expect(e.status).to be_nonzero }
end

require 'tempfile'

it 'takes pathes as arguments' do
file_1 = "#{Dir.tmpdir}/#{rand}.rb"
file_2 = "#{Dir.tmpdir}/#{rand}.rb"
File.write(file_1, 'foo')
File.write(file_2, 'foo')
expect(Repper::Codemod).to receive(:call).twice.and_return 'bar'

Repper::Command.call([file_1, file_2])

expect(File.read(file_1)).to eq 'bar'
expect(File.read(file_2)).to eq 'bar'
end
end
end
7 changes: 7 additions & 0 deletions spec/repper/core_ext/regexp_ext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@
expect(/foo/.inspect).to eq '/foo/'
expect(/foo/.dup.extend(Repper::RegexpExt).inspect).to eq 'YO'
end

it 'gracefully handles errors' do
expect(Repper).to receive(:render).and_raise('oopsy')
expect do
expect(/foo/.dup.extend(Repper::RegexpExt).inspect).to eq '/foo/'
end.to output(/Error in Repper:.*oopsy/m).to_stderr
end
end
9 changes: 9 additions & 0 deletions spec/repper/format/structured_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,13 @@
/x
EOS
end

it 'represents literal n/r/t/v whitespace with escapes' do
result = Repper.render(/#{"\n"}/, format: :structured)
expect(result).to have_raw_text <<~'EOS'
/
\n
/
EOS
end
end
7 changes: 7 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
if RUBY_VERSION.start_with?('3.2')
require 'simplecov'
require 'simplecov-cobertura'
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
SimpleCov.start
end

require "repper"
require_relative "support/matchers"

Expand Down
11 changes: 11 additions & 0 deletions spec/support/matchers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
RSpec.describe 'have_color' do
it 'matches for colorized strings' do
expect('foo').not_to have_color
expect { expect('foo').to have_color }
.to raise_error(RSpec::Expectations::ExpectationNotMetError)

expect(Rainbow('foo').color('#FF0000')).to have_color
expect { expect(Rainbow('foo').color('#FF0000')).not_to have_color }
.to raise_error(RSpec::Expectations::ExpectationNotMetError)
end
end

0 comments on commit 1a934f3

Please sign in to comment.