diff --git a/Rakefile b/Rakefile index e92e2be..87233b3 100644 --- a/Rakefile +++ b/Rakefile @@ -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 @@ -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] diff --git a/test/integration_test.rb b/test/integration_test.rb index 366c365..b04fb23 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -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