Skip to content

Commit

Permalink
Move test helper to module
Browse files Browse the repository at this point in the history
  • Loading branch information
khiga8 committed Mar 17, 2023
1 parent 9f95018 commit f52fc0f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion spec/erb_lint/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "spec_helper"
require "spec_utils"
require "erb_lint/cli"
require "erb_lint/cache"
require "pp"
Expand Down Expand Up @@ -103,7 +104,7 @@ module ERBLint
module Linters
class FakeLinter < Linter
def run(processed_source)
add_offense(source_range_for_code(processed_source, "<violation></violation>"),
add_offense(SpecUtils.source_range_for_code(processed_source, "<violation></violation>"),
"#{self.class.name} error")
end
end
Expand Down
9 changes: 5 additions & 4 deletions spec/erb_lint/linters/no_unused_disable_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "spec_helper"
require "spec_utils"

describe ERBLint::Linters::NoUnusedDisable do
let(:linter_config) { described_class.config_schema.new }
Expand Down Expand Up @@ -33,7 +34,7 @@ class Fake < ERBLint::Linter
let(:file) { "<span></span><%# erblint:disable-line Fake %>" }
before do
offense = ERBLint::Offense.new(ERBLint::Linters::Fake.new(file_loader, linter_config),
source_range_for_code(processed_source, "<span></span>"),
SpecUtils.source_range_for_code(processed_source, "<span></span>"),
"some fake linter message")
offense.disabled = true
linter.run(processed_source, [offense])
Expand All @@ -52,7 +53,7 @@ class Fake < ERBLint::Linter
before do
offense = ERBLint::Offense.new(
ERBLint::Linters::Fake.new(file_loader, linter_config),
source_range_for_code(processed_source, "<span>bad content</span>"),
SpecUtils.source_range_for_code(processed_source, "<span>bad content</span>"),
"some fake linter message"
)
offense.disabled = true
Expand All @@ -70,7 +71,7 @@ class Fake < ERBLint::Linter
before do
offense = ERBLint::Offense.new(
ERBLint::Linters::Fake.new(file_loader, linter_config),
source_range_for_code(processed_source, "<span></span>"),
SpecUtils.source_range_for_code(processed_source, "<span></span>"),
"some fake linter message"
)
offense.disabled = true
Expand All @@ -91,7 +92,7 @@ class Fake < ERBLint::Linter
before do
offense = ERBLint::Offense.new(
ERBLint::Linters::Fake.new(file_loader, linter_config),
source_range_for_code(processed_source, "<span></span>"),
SpecUtils.source_range_for_code(processed_source, "<span></span>"),
"some fake linter message"
)
offense.disabled = true
Expand Down
4 changes: 3 additions & 1 deletion spec/erb_lint/runner_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "spec_helper"
require "spec_utils"

describe ERBLint::Runner do
let(:file_loader) { ERBLint::FileLoader.new("/root/directory") }
Expand Down Expand Up @@ -138,7 +139,8 @@ module ERBLint
module Linters
class FakeLinter3 < Linter
def run(processed_source)
add_offense(source_range_for_code(processed_source, "<span>bad content</span>"), "#{self.class.name} error")
add_offense(SpecUtils.source_range_for_code(processed_source, "<span>bad content</span>"),
"#{self.class.name} error")
end
end

Expand Down
5 changes: 0 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# frozen_string_literal: true

require "erb_lint/all"

def source_range_for_code(processed_source, code)
offending_source = processed_source.file_content.match(code)
processed_source.to_source_range(offending_source.begin(0)...offending_source.end(0))
end
8 changes: 8 additions & 0 deletions spec/spec_utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

module SpecUtils
def self.source_range_for_code(processed_source, code)
offending_source = processed_source.file_content.match(code)
processed_source.to_source_range(offending_source.begin(0)...offending_source.end(0))
end
end

0 comments on commit f52fc0f

Please sign in to comment.