Skip to content

Commit

Permalink
run Raketask :test twice with different modes
Browse files Browse the repository at this point in the history
  • Loading branch information
prog-supdex committed Oct 19, 2023
1 parent 91c89a7 commit 2dc6053
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 12 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "bundler/gem_tasks"
require "rake/testtask"
require "rubocop/rake_task"

Rake::TestTask.new(:test) do |t|
Rake::TestTask.new(:rubocop_md_tests) do |t|
t.libs << "test"
t.libs << "lib"
t.warning = false
Expand All @@ -11,4 +11,15 @@ end

RuboCop::RakeTask.new

task :test do
ENV["MD_LOAD_MODE"] = "inline"
$stdout.puts "⚙️ Runs rubocop with '-r rubocop_md' options"
Rake::Task[:rubocop_md_tests].invoke

ENV["MD_LOAD_MODE"] = "config"
$stdout.puts "⚙️ Runs rubocop with 'required rubocop_md' section in .rubocop.yml"
Rake::Task[:rubocop_md_tests].reenable
Rake::Task[:rubocop_md_tests].invoke
end

task default: [:rubocop, :test]
19 changes: 18 additions & 1 deletion test/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,31 @@
require "fileutils"

module RuboCopRunner
MD_LOAD_INLINE_MODE = "inline"

def run_rubocop(path, options: "")
output, _status = Open3.capture2(
"bundle exec rubocop #{options} #{path}",
cmd_command_by_env(path, options),
chdir: File.join(__dir__, "fixtures")
)

output
end

private

def cmd_command_by_env(path, options)
cmd_command = "bundle exec rubocop"
load_mode = ENV.fetch("MD_LOAD_MODE", MD_LOAD_INLINE_MODE)

if load_mode == MD_LOAD_INLINE_MODE
md_path = File.expand_path("../lib/rubocop-md.rb", __dir__)

cmd_command = "#{cmd_command} -r #{md_path}"
end

"#{cmd_command} #{options} #{path}"
end
end

class RuboCop::Markdown::AnalyzeTest < Minitest::Test
Expand Down

0 comments on commit 2dc6053

Please sign in to comment.