Skip to content

Commit a24e38f

Browse files
manucabronzdoc
authored andcommitted
add --out file option
1 parent f66b1a6 commit a24e38f

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

lib/skunk/cli/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def warn_coverage_info
3838
end
3939

4040
def print(message)
41-
@options.output_to.puts message
41+
@options.output_stream.puts message
4242
end
4343
end
4444
end

lib/skunk/cli/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def parse
2020
self
2121
end
2222

23-
def output_to
23+
def output_stream
2424
@argv_options.output_filename.nil? ? $stdout : File.open(@argv_options.output_filename, "w")
2525
end
2626

test/lib/skunk/application_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@
3030

3131
context "when passing --out option with a file" do
3232
require "fileutils"
33-
let(:argv) { ["--out tmp/generated_report.txt"] }
33+
34+
let(:argv) { ["--out=tmp/generated_report.txt"] }
3435
let(:success_code) { 0 }
3536

3637
it "writes output to the file" do
3738
FileUtils.rm("tmp/generated_report.txt", force: true)
39+
3840
result = application.execute
41+
3942
_(result).must_equal success_code
40-
file_contents = File.read("tmp/generated_report.txt")
41-
_(file_contents).must_equal File.read("test/samples/console_output.txt")
43+
_(File.exist?("tmp/generated_report.txt")).must_equal true
4244
end
4345
end
4446
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require "test_helper"
2+
3+
require "skunk/cli/options/argv"
4+
5+
describe Skunk::Cli::Options::Argv do
6+
describe "#output_filename" do
7+
context "passing --out=FILE options" do
8+
let(:argv) { ["--out=file.txt"] }
9+
10+
it "parses passed filename" do
11+
parser = Skunk::Cli::Options::Argv.new(argv)
12+
parser.parse
13+
_(parser.output_filename).must_equal "file.txt"
14+
end
15+
end
16+
17+
context "not passing the --out option" do
18+
it "is nil" do
19+
parser = Skunk::Cli::Options::Argv.new([])
20+
parser.parse
21+
_(parser.output_filename).must_be_nil
22+
end
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)