Module: SolargraphTestCoverage::Config
Constant Summary collapse
- DEFAULTS =
{ 'preload_rails' => true, # can be true or false - performance optimization 'debug' => false, # can be true or false - shows debug messages when ChildFailedError is raised 'test_framework' => 'rspec', # can be 'rspec' or 'minitest' 'coverage' => [ # All diagnostics are enabled by default 'line', # Specifying an array with fewer diagnostics will overwrite this 'branch', 'test_failing', 'test_missing', 'example_failing' ], 'exclude_paths' => [ # don't attempt to find/run a spec for files that match these paths 'app/controller', 'concerns' ] }.freeze
Instance Method Summary collapse
- #branch_coverage? ⇒ Boolean
- #debug? ⇒ Boolean
- #example_failing_coverage? ⇒ Boolean
- #exclude_paths ⇒ Object
- #full_test_dir ⇒ Object
- #line_coverage? ⇒ Boolean
-
#preload_rails! ⇒ Object
This gives us a nice speed-boost when running test in child process.
- #preload_rails? ⇒ Boolean
- #require_testing_framework! ⇒ Object
- #test_dir ⇒ Object
- #test_failing_coverage? ⇒ Boolean
- #test_file_suffix ⇒ Object
- #test_framework ⇒ Object
- #test_missing_coverage? ⇒ Boolean
Instance Method Details
#branch_coverage? ⇒ Boolean
40 41 42 |
# File 'lib/solargraph_test_coverage/config.rb', line 40 def branch_coverage? plugin_config['coverage'].include? 'branch' end |
#debug? ⇒ Boolean
24 25 26 |
# File 'lib/solargraph_test_coverage/config.rb', line 24 def debug? plugin_config['debug'] end |
#example_failing_coverage? ⇒ Boolean
52 53 54 |
# File 'lib/solargraph_test_coverage/config.rb', line 52 def example_failing_coverage? plugin_config['coverage'].include? 'example_failing' end |
#exclude_paths ⇒ Object
32 33 34 |
# File 'lib/solargraph_test_coverage/config.rb', line 32 def exclude_paths plugin_config['exclude_paths'] end |
#full_test_dir ⇒ Object
60 61 62 |
# File 'lib/solargraph_test_coverage/config.rb', line 60 def full_test_dir File.join(Dir.pwd, test_dir) end |
#line_coverage? ⇒ Boolean
36 37 38 |
# File 'lib/solargraph_test_coverage/config.rb', line 36 def line_coverage? plugin_config['coverage'].include? 'line' end |
#preload_rails! ⇒ Object
This gives us a nice speed-boost when running test in child process
We rescue the LoadError since Solargraph would catch it otherwise, and not load the plugin at all.
Adding the spec/ directory to the $LOAD_PATH lets ‘require “spec_helper”’ commonly found in rails_helper work.
If Coverage was started in Rails/Spec helper by SimpleCov, calling Coverage.result after requiring stops and resets it.
This is a bit experimental
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/solargraph_test_coverage/config.rb', line 106 def preload_rails! return if defined?(Rails) || !File.file?('spec/rails_helper.rb') $LOAD_PATH.unshift(full_test_dir) unless $LOAD_PATH.include?(full_test_dir) require File.join(full_test_dir, 'rails_helper') Coverage.result(stop: true, clear: true) if Coverage.running? true rescue LoadError => e Solargraph::Logging.logger.warn "LoadError when trying to require 'rails_helper'" Solargraph::Logging.logger.warn "[#{e.class}] #{e.}" false end |
#preload_rails? ⇒ Boolean
28 29 30 |
# File 'lib/solargraph_test_coverage/config.rb', line 28 def preload_rails? plugin_config['preload_rails'] end |
#require_testing_framework! ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/solargraph_test_coverage/config.rb', line 82 def require_testing_framework! case test_framework when 'rspec' require 'rspec/core' when 'minitest' require 'minitest/autorun' else raise UnknownTestingGem end end |
#test_dir ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/solargraph_test_coverage/config.rb', line 64 def test_dir case test_framework when 'rspec' 'spec' when 'minitest' 'test' end end |
#test_failing_coverage? ⇒ Boolean
44 45 46 |
# File 'lib/solargraph_test_coverage/config.rb', line 44 def test_failing_coverage? plugin_config['coverage'].include? 'test_failing' end |
#test_file_suffix ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/solargraph_test_coverage/config.rb', line 73 def test_file_suffix case test_framework when 'rspec' '_spec.rb' when 'minitest' '_test.rb' end end |
#test_framework ⇒ Object
56 57 58 |
# File 'lib/solargraph_test_coverage/config.rb', line 56 def test_framework plugin_config['test_framework'] end |
#test_missing_coverage? ⇒ Boolean
48 49 50 |
# File 'lib/solargraph_test_coverage/config.rb', line 48 def test_missing_coverage? plugin_config['coverage'].include? 'test_missing' end |