1 # frozen_string_literal: true
3 require "bundler/setup"
4 require "syntax_suggest/api"
9 RSpec.configure do |config|
10 # Enable flags like --only-failures and --next-failure
11 config.example_status_persistence_file_path = ".rspec_status"
13 # Disable RSpec exposing methods globally on `Module` and `main`
14 config.disable_monkey_patching!
16 config.expect_with :rspec do |c|
20 if config.color_mode == :automatic
21 if config.color_enabled? && ((ENV["TERM"] == "dumb") || ENV["NO_COLOR"]&.slice(0))
22 config.color_mode = :off
27 # Used for debugging modifications to
29 def debug_display(output)
30 return unless ENV["DEBUG_DISPLAY"]
42 root_dir.join("../lib")
53 spec_dir.join("fixtures")
57 !root_dir.join("syntax_suggest.gemspec").exist?
60 def code_line_array(source)
61 SyntaxSuggest::CleanDocument.new(source: source).call.lines
64 autoload :RubyProf, "ruby-prof"
67 raise "No block given" unless block_given?
71 result = RubyProf.profile do
75 dir = SyntaxSuggest.record_dir("tmp")
76 printer = RubyProf::MultiPrinter.new(result, [:flat, :graph, :graph_html, :tree, :call_tree, :stack, :dot])
77 printer.print(path: dir, profile: "profile")
85 def run!(cmd, raise_on_nonzero_exit: true)
87 raise "Command: #{cmd} failed: #{out}" if !$?.success? && raise_on_nonzero_exit
91 # Allows us to write cleaner tests since <<~EOM block quotes
92 # strip off all leading indentation and we need it to be preserved