|
2 | 2 |
|
3 | 3 | require "test_helper" |
4 | 4 | require "skunk/cli/application" |
| 5 | +require "skunk/commands/default" |
5 | 6 | require "rubycritic/core/analysed_module" |
6 | 7 | require "minitest/stub_const" |
7 | 8 |
|
|
46 | 47 | end |
47 | 48 |
|
48 | 49 | 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"] } |
50 | 51 | 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" } |
54 | 56 |
|
55 | 57 | around do |example| |
56 | | - stub_request(:post, "https://skunk.fastruby.io/reports").to_return( |
| 58 | + stub_request(:post, "#{share_url}/reports").to_return( |
57 | 59 | status: 200, |
58 | 60 | body: '{"id":"j"}', |
59 | 61 | headers: { "Content-Type" => "application/json" } |
|
62 | 64 | end |
63 | 65 |
|
64 | 66 | it "share report to default server" do |
65 | | - FileUtils.rm("tmp/shared_report.txt", force: true) |
| 67 | + FileUtils.rm(report_path, force: true) |
66 | 68 | FileUtils.mkdir_p("tmp") |
67 | 69 |
|
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 |
78 | 76 | 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) |
79 | 82 | end |
80 | 83 | end |
81 | 84 | end |
|
0 commit comments