Skip to content

Commit

Permalink
Add a test for runner's autocorrect related code
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxLap committed Jul 7, 2023
1 parent 3e37286 commit 32fea51
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions spec/haml_lint/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

context 'general tests' do
let(:files) { %w[file1.slim file2.slim] }
let(:mock_linter) { double('linter', lints: [], name: 'Blah') }

let(:options) do
base_options.merge(reporter: reporter)
Expand Down Expand Up @@ -90,13 +89,23 @@
include_context 'isolated environment'

before do
`echo "%div{ class: 'foo' } hello" > example.haml`
`echo "%div{ class: 'foo' } hello" > example.haml`
end

it 'successfully reports those errors' do
runner.unstub(:collect_lints)
expect(subject.lints.first.message).to match(/Avoid defining `class` in attributes hash/)
end

context 'with autocorrect on' do
let(:options) { super().merge(autocorrect: :all) }

it 'successfully fixes those errors' do
runner.unstub(:collect_lints)
expect(subject.lints.detect(&:corrected).message).to match(/Unnecessary spacing detected./)
expect(File.read('example.haml')).to eq("%div{ class: 'foo' } hello\n")
end
end
end
end

Expand Down

0 comments on commit 32fea51

Please sign in to comment.