-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create undercover-report command #3
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0a27a7f
Created undercover-report cli
rafayet-monon 903cf89
Fix undercover argument passing.
rafayet-monon 309f347
Fix undercover argument passing bug on nil.
rafayet-monon 54b9387
Update gem version to 1.1.0
rafayet-monon 8bd4983
Add default path as constant.
rafayet-monon 4fd259d
Add comments in tests.
rafayet-monon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,46 @@ | ||
# 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') } | ||
let!(:file) { File.join(Dir.getwd, 'coverage/undercover.txt') } | ||
|
||
before(:each) do | ||
allow(described_class).to receive(:`).and_return(mock_message) | ||
end | ||
|
||
after(:all) do | ||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is
receive(:
)` for?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
receive(:
)` is to mock the -undercover #{args&.join(' ')}
CLI command output.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, I would not have guessed. So a comment would help future devs, yourself included.