-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
131 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# bin/undercover_report | ||
|
||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
$LOAD_PATH.unshift("#{__dir__}/../lib") | ||
|
||
require 'undercover/cli' | ||
|
||
puts DangerUndercover::CLI.run(ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'fileutils' | ||
|
||
module DangerUndercover | ||
# module for undercover-report | ||
module CLI | ||
class << self | ||
# Runs the undercover command with provided arguments | ||
# and writes the output to a file | ||
# @return [String] | ||
# | ||
def run(args = nil) | ||
undercover_output = `undercover #{args&.join(' ')}` | ||
|
||
File.open(output_file, 'w') do |f| | ||
f.write(undercover_output) | ||
end | ||
|
||
undercover_output | ||
end | ||
|
||
private | ||
|
||
# Returns the file to write report to | ||
# @return [String] | ||
# | ||
def output_file | ||
create_directory! | ||
|
||
File.join(output_directory, 'undercover.txt') | ||
end | ||
|
||
# Creates directory if doesn't exists | ||
# @return [String] | ||
# | ||
def create_directory! | ||
return if Dir.exist?(output_directory) | ||
|
||
FileUtils.mkdir_p(output_directory) | ||
end | ||
|
||
# Output directory | ||
# @return [String] | ||
# | ||
def output_directory | ||
File.join(Dir.getwd, 'coverage') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Undercover | ||
VERSION = '1.0.0' | ||
VERSION = '1.1.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require File.expand_path('spec_helper', __dir__) | ||
require 'undercover/cli' | ||
|
||
# rubocop:disable Metrics/BlockLength | ||
module DangerUndercover | ||
describe DangerUndercover::CLI do | ||
let!(:mock_message) { 'Test Passed' } | ||
let!(:directory) { File.join(Dir.getwd, 'coverage') } # default directory | ||
let!(:file) { File.join(Dir.getwd, 'coverage/undercover.txt') } # default file | ||
|
||
before(:each) do | ||
# mocks the undercover #{args&.join(' ')} CLI command output. | ||
allow(described_class).to receive(:`).and_return(mock_message) | ||
end | ||
|
||
after(:all) do | ||
# removes the folder after tests pass. | ||
FileUtils.rm_rf(File.join(Dir.getwd, 'coverage')) | ||
end | ||
|
||
it 'prints the undercover output' do | ||
expect(described_class.run).to eql(mock_message) | ||
end | ||
|
||
it "creates a default folder if doesn't exists" do | ||
FileUtils.rm_rf(directory) | ||
described_class.run | ||
|
||
expect(Dir.exist?(directory)).to be true | ||
end | ||
|
||
it 'creates default file undercover.txt' do | ||
described_class.run | ||
|
||
expect(File.exist?(file)).to be true | ||
end | ||
|
||
it 'writes undercover report to default file' do | ||
described_class.run | ||
report = File.open(file).read | ||
|
||
expect(report).to eql(mock_message) | ||
end | ||
end | ||
end | ||
# rubocop:enable Metrics/BlockLength |