-
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.
Merge pull request #1 from Daniel-N-Huss/command_line_and_readme_stuff
Command line and readme stuff
- Loading branch information
Showing
9 changed files
with
175 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ gem "rake" | |
gem "minitest" | ||
gem "standard" | ||
gem "m" | ||
gem "mocktail" |
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,7 @@ | ||
#!/usr/bin/env ruby | ||
|
||
$LOAD_PATH.unshift("#{__dir__}/../lib") | ||
|
||
require "gem_dating" | ||
|
||
exit GemDating::Cli.new(ARGV).run |
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,23 @@ | ||
module GemDating | ||
class Cli | ||
SUCCESS = 0 | ||
GENERAL_ERROR = 1 | ||
|
||
def initialize(argv) | ||
@argv = argv | ||
end | ||
|
||
def run | ||
if @argv.empty? | ||
$stdout << "Usage: gem_dating [GEMFILE_FILEPATH]\n" | ||
return GENERAL_ERROR | ||
end | ||
|
||
path = @argv.first | ||
|
||
$stdout << GemDating.from_file(path).table_print << "\n" | ||
|
||
SUCCESS | ||
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
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,66 @@ | ||
require "test_helper" | ||
require "date" | ||
|
||
class GemDating::CliTest < Minitest::Test | ||
def setup | ||
@spec1 = Gem::Specification.new do |s| | ||
s.name = "banana-client" | ||
s.version = "21.1.0" | ||
s.date = DateTime.parse("1990-08-21") | ||
end | ||
@spec2 = Gem::Specification.new do |s| | ||
s.name = "rails-on-rubies" | ||
s.version = "70.0.5" | ||
s.date = DateTime.parse("2123-05-24") | ||
end | ||
@spec3 = Gem::Specification.new do |s| | ||
s.name = "giraffeql" | ||
s.version = "0.0.2227" | ||
s.date = DateTime.parse("2023-05-17") | ||
end | ||
end | ||
|
||
def test_gemfile | ||
exit_code = nil | ||
|
||
Mocktail.replace(GemDating::Rubygems) | ||
stubs { |m| GemDating::Rubygems.fetch(m.is_a(Array)) }.with { [@spec1, @spec2, @spec3] } | ||
|
||
stdout, _stderr = capture_io do | ||
exit_code = GemDating::Cli.new(["test/Gemfile.example"]).run | ||
end | ||
|
||
expected_out = <<~EXPECTED | ||
NAME | VERSION | DATE | ||
----------------|----------|----------- | ||
banana-client | 21.1.0 | 1990-08-21 | ||
rails-on-rubies | 70.0.5 | 2123-05-24 | ||
giraffeql | 0.0.2227 | 2023-05-17 | ||
EXPECTED | ||
|
||
assert_equal 0, exit_code | ||
assert_equal expected_out, stdout | ||
end | ||
|
||
def test_no_args_prints_help | ||
exit_code = nil | ||
|
||
stdout, _stderr = capture_io do | ||
exit_code = GemDating::Cli.new([]).run | ||
end | ||
|
||
expected_out = | ||
<<~EXPECTED | ||
Usage: gem_dating [GEMFILE_FILEPATH] | ||
EXPECTED | ||
|
||
assert_equal 1, exit_code | ||
assert_equal expected_out, stdout | ||
end | ||
|
||
def test_bad_filepath | ||
assert_raises Errno::ENOENT do | ||
GemDating::Cli.new(["test/Gemfile.nope"]).run | ||
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,4 +1,12 @@ | ||
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) | ||
require "gem_dating" | ||
|
||
require "minitest/autorun" | ||
require "mocktail" | ||
|
||
class Minitest::Test | ||
include Mocktail::DSL | ||
|
||
def teardown | ||
Mocktail.reset | ||
end | ||
end |