Skip to content

Commit 65f04b5

Browse files
committed
test: fix share report sharing output
1 parent 36a83e0 commit 65f04b5

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

lib/skunk/commands/status_sharer.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ def share_enabled?
7373

7474
# @return [Boolean] Check if share URL is empty
7575
def share_url_empty?
76-
ENV["SHARE_URL"].to_s == ""
76+
share_url == ""
77+
end
78+
79+
def share_url
80+
ENV["SHARE_URL"].to_s
7781
end
7882

7983
def payload

test/lib/skunk/application_test.rb

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "test_helper"
44
require "skunk/cli/application"
5+
require "skunk/commands/default"
56
require "rubycritic/core/analysed_module"
67
require "minitest/stub_const"
78

@@ -46,14 +47,15 @@
4647
end
4748

4849
context "when passing an environment variable SHARE=true" do
49-
let(:argv) { ["--out=tmp/shared_report.txt", "samples/rubycritic"] }
50+
let(:argv) { ["--out=tmp", "samples/rubycritic"] }
5051
let(:success_code) { 0 }
51-
let(:shared_message) do
52-
"Shared at: https://skunk.fastruby.io/j"
53-
end
52+
let(:generated_message) { "Generated with Skunk" }
53+
let(:shared_message) { "Shared at: https://skunk.fastruby.io/j" }
54+
let(:share_url) { "https://skunk.fastruby.io" }
55+
let(:report_path) { "tmp/skunk_report.txt" }
5456

5557
around do |example|
56-
stub_request(:post, "https://skunk.fastruby.io/reports").to_return(
58+
stub_request(:post, "#{share_url}/reports").to_return(
5759
status: 200,
5860
body: '{"id":"j"}',
5961
headers: { "Content-Type" => "application/json" }
@@ -62,20 +64,21 @@
6264
end
6365

6466
it "share report to default server" do
65-
FileUtils.rm("tmp/shared_report.txt", force: true)
67+
FileUtils.rm(report_path, force: true)
6668
FileUtils.mkdir_p("tmp")
6769

68-
RubyCritic::AnalysedModule.stub_any_instance(:churn, 1) do
69-
RubyCritic::AnalysedModule.stub_any_instance(:coverage, 100.0) do
70-
Skunk::Command::Default.stub_any_instance(:share_enabled?, true) do
71-
Skunk::Command::StatusSharer.stub_any_instance(:not_sharing?, false) do
72-
Skunk::Command::StatusSharer.stub_any_instance(:share, "Shared at: https://skunk.fastruby.io/j") do
73-
result = application.execute
74-
_(result).must_equal success_code
75-
output = File.read("tmp/shared_report.txt")
76-
_(output).must_include(shared_message)
77-
end
70+
Skunk::Command::Default.stub_any_instance(:share_enabled?, true) do
71+
Skunk::Command::StatusSharer.stub_any_instance(:share_url, share_url) do
72+
Skunk::Command::StatusSharer.stub_any_instance(:share, "Shared at: #{share_url}/j") do
73+
stdout = capture_stdout do
74+
result = application.execute
75+
_(result).must_equal success_code
7876
end
77+
_(File.exist?(report_path)).must_equal true
78+
file_output = File.read(report_path)
79+
80+
_(file_output).must_include(generated_message)
81+
_(stdout).must_include(shared_message)
7982
end
8083
end
8184
end

0 commit comments

Comments
 (0)