|
30 | 30 | it "returns an array of Toolinfo objects" do |
31 | 31 | expect(toolsync.info_array).to all(be_a(Icarus::Mod::Tools::Toolinfo)) |
32 | 32 | end |
| 33 | + |
| 34 | + context "when JSON parsing fails" do |
| 35 | + let(:valid_url) { "https://example.com/valid.json" } |
| 36 | + let(:invalid_url) { "https://example.com/invalid.json" } |
| 37 | + let(:valid_response) { { tools: [{ name: "Valid Tool", author: "Author", description: "Test", fileType: "EXE", fileURL: "http://example.com/tool.exe" }] } } |
| 38 | + |
| 39 | + before do |
| 40 | + toolsync.instance_variable_set(:@info_array, nil) |
| 41 | + allow(firestore_double).to receive(:toolinfo).and_return([valid_url, invalid_url]) |
| 42 | + allow_any_instance_of(Icarus::Mod::Tools::Sync::Helpers).to receive(:retrieve_from_url).with(valid_url).and_return(valid_response) |
| 43 | + allow_any_instance_of(Icarus::Mod::Tools::Sync::Helpers).to receive(:retrieve_from_url).with(invalid_url).and_raise( |
| 44 | + JSON::ParserError.new("invalid escape character in string: '\\Users\\foo\\bar' at line 1 column 10") |
| 45 | + ) |
| 46 | + end |
| 47 | + |
| 48 | + it "warns with a concise error message without stack trace" do |
| 49 | + stderr_output = StringIO.new |
| 50 | + original_stderr = $stderr |
| 51 | + $stderr = stderr_output |
| 52 | + |
| 53 | + toolsync.info_array |
| 54 | + |
| 55 | + $stderr = original_stderr |
| 56 | + output = stderr_output.string |
| 57 | + |
| 58 | + expect(output).to match(/Skipped; Invalid JSON: invalid escape character/) |
| 59 | + expect(output).not_to match(/JSON::Ext::Parser/) |
| 60 | + expect(output).not_to match(/lib\/ruby\/gems/) |
| 61 | + end |
| 62 | + |
| 63 | + it "skips the invalid URL and continues processing" do |
| 64 | + result = toolsync.info_array |
| 65 | + expect(result.length).to eq(1) |
| 66 | + expect(result.first.name).to eq("Valid Tool") |
| 67 | + end |
| 68 | + end |
33 | 69 | end |
34 | 70 |
|
35 | 71 | describe "#find" do |
|
0 commit comments