|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe ERBLint::Reporters::JsonReporter do |
| 6 | + describe '.show' do |
| 7 | + subject { described_class.new(stats, false).show } |
| 8 | + |
| 9 | + let(:stats) do |
| 10 | + ERBLint::Stats.new( |
| 11 | + found: 2, |
| 12 | + processed_files: { |
| 13 | + 'app/views/subscriptions/_loader.html.erb' => offenses, |
| 14 | + }, |
| 15 | + corrected: 1 |
| 16 | + ) |
| 17 | + end |
| 18 | + |
| 19 | + let(:offenses) do |
| 20 | + [ |
| 21 | + instance_double( |
| 22 | + ERBLint::Offense, |
| 23 | + message: 'Extra space detected where there should be no space.', |
| 24 | + line_number: 1, |
| 25 | + column: 7, |
| 26 | + source_range: instance_double( |
| 27 | + BetterHtml::Tokenizer::Location, |
| 28 | + last_line: 1, |
| 29 | + last_column: 9, |
| 30 | + length: 2, |
| 31 | + ), |
| 32 | + linter: ERBLint::Linters::SpaceInHtmlTag.new(nil, ERBLint::LinterConfig.new), |
| 33 | + ), |
| 34 | + instance_double( |
| 35 | + ERBLint::Offense, |
| 36 | + message: 'Remove newline before `%>` to match start of tag.', |
| 37 | + line_number: 52, |
| 38 | + column: 10, |
| 39 | + source_range: instance_double( |
| 40 | + BetterHtml::Tokenizer::Location, |
| 41 | + last_line: 54, |
| 42 | + last_column: 10, |
| 43 | + length: 10, |
| 44 | + ), |
| 45 | + linter: ERBLint::Linters::ClosingErbTagIndent.new(nil, ERBLint::LinterConfig.new), |
| 46 | + ), |
| 47 | + ] |
| 48 | + end |
| 49 | + |
| 50 | + let(:expected_hash) do |
| 51 | + { |
| 52 | + metadata: { |
| 53 | + erb_lint_version: ERBLint::VERSION, |
| 54 | + ruby_engine: RUBY_ENGINE, |
| 55 | + ruby_version: RUBY_VERSION, |
| 56 | + ruby_patchlevel: RUBY_PATCHLEVEL.to_s, |
| 57 | + ruby_platform: RUBY_PLATFORM, |
| 58 | + }, |
| 59 | + files: [{ |
| 60 | + path: 'app/views/subscriptions/_loader.html.erb', |
| 61 | + offenses: [ |
| 62 | + { |
| 63 | + linter: 'SpaceInHtmlTag', |
| 64 | + message: 'Extra space detected where there should be no space.', |
| 65 | + location: { |
| 66 | + start_line: 1, |
| 67 | + start_column: 7, |
| 68 | + last_line: 1, |
| 69 | + last_column: 9, |
| 70 | + length: 2, |
| 71 | + }, |
| 72 | + }, |
| 73 | + { |
| 74 | + linter: 'ClosingErbTagIndent', |
| 75 | + message: 'Remove newline before `%>` to match start of tag.', |
| 76 | + location: { |
| 77 | + start_line: 52, |
| 78 | + start_column: 10, |
| 79 | + last_line: 54, |
| 80 | + last_column: 10, |
| 81 | + length: 10, |
| 82 | + }, |
| 83 | + }, |
| 84 | + ], |
| 85 | + }], |
| 86 | + summary: { |
| 87 | + offenses: 2, |
| 88 | + inspected_files: 1, |
| 89 | + corrected: 1, |
| 90 | + }, |
| 91 | + } |
| 92 | + end |
| 93 | + |
| 94 | + it 'displays formatted offenses output' do |
| 95 | + expect { subject }.to(output(expected_hash.to_json + "\n").to_stdout) |
| 96 | + end |
| 97 | + end |
| 98 | +end |
0 commit comments