diff options
Diffstat (limited to 'spec/syntax_suggest/integration')
| -rw-r--r-- | spec/syntax_suggest/integration/ruby_command_line_spec.rb | 30 | ||||
| -rw-r--r-- | spec/syntax_suggest/integration/syntax_suggest_spec.rb | 81 |
2 files changed, 87 insertions, 24 deletions
diff --git a/spec/syntax_suggest/integration/ruby_command_line_spec.rb b/spec/syntax_suggest/integration/ruby_command_line_spec.rb index 61102dad2a..02354ceff0 100644 --- a/spec/syntax_suggest/integration/ruby_command_line_spec.rb +++ b/spec/syntax_suggest/integration/ruby_command_line_spec.rb @@ -9,7 +9,7 @@ module SyntaxSuggest Dir.mktmpdir do |dir| tmpdir = Pathname(dir) script = tmpdir.join("script.rb") - script.write <<~'EOM' + script.write <<~EOM puts Kernel.private_methods EOM @@ -46,6 +46,24 @@ module SyntaxSuggest end end + # Since Ruby 3.2 includes syntax_suggest as a default gem, we might accidentally + # be requiring the default gem instead of this library under test. Assert that's + # not the case + it "tests current version of syntax_suggest" do + Dir.mktmpdir do |dir| + tmpdir = Pathname(dir) + script = tmpdir.join("script.rb") + contents = <<~'EOM' + puts "suggest_version is #{SyntaxSuggest::VERSION}" + EOM + script.write(contents) + + out = `#{ruby} -I#{lib_dir} -rsyntax_suggest/version #{script} 2>&1` + + expect(out).to include("suggest_version is #{SyntaxSuggest::VERSION}").once + end + end + it "detects require error and adds a message with auto mode" do Dir.mktmpdir do |dir| tmpdir = Pathname(dir) @@ -76,8 +94,6 @@ module SyntaxSuggest end it "gem can be tested when executing on Ruby with default gem included" do - skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2") - out = `#{ruby} -I#{lib_dir} -rsyntax_suggest -e "puts SyntaxError.instance_method(:detailed_message).source_location" 2>&1` expect($?.success?).to be_truthy @@ -85,8 +101,6 @@ module SyntaxSuggest end it "annotates a syntax error in Ruby 3.2+ when require is not used" do - skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2") - Dir.mktmpdir do |dir| tmpdir = Pathname(dir) script = tmpdir.join("script.rb") @@ -141,7 +155,7 @@ module SyntaxSuggest Dir.mktmpdir do |dir| tmpdir = Pathname(dir) script = tmpdir.join("script.rb") - script.write <<~'EOM' + script.write <<~EOM $stderr = STDOUT eval("def lol") EOM @@ -149,7 +163,7 @@ module SyntaxSuggest out = `#{ruby} -I#{lib_dir} -rsyntax_suggest #{script} 2>&1` expect($?.success?).to be_falsey - expect(out).to include("(eval):1") + expect(out).to match(/\(eval.*\):1/) expect(out).to_not include("SyntaxSuggest") expect(out).to_not include("Could not find filename") @@ -160,7 +174,7 @@ module SyntaxSuggest Dir.mktmpdir do |dir| tmpdir = Pathname(dir) script = tmpdir.join("script.rb") - script.write <<~'EOM' + script.write <<~EOM break EOM diff --git a/spec/syntax_suggest/integration/syntax_suggest_spec.rb b/spec/syntax_suggest/integration/syntax_suggest_spec.rb index bb50fafce7..de9bc5d38e 100644 --- a/spec/syntax_suggest/integration/syntax_suggest_spec.rb +++ b/spec/syntax_suggest/integration/syntax_suggest_spec.rb @@ -13,7 +13,7 @@ module SyntaxSuggest io = StringIO.new - benchmark = Benchmark.measure do + benchmark_measure do debug_perf do SyntaxSuggest.call( io: io, @@ -21,11 +21,11 @@ module SyntaxSuggest filename: file ) end - debug_display(io.string) - debug_display(benchmark) end - expect(io.string).to include(<<~'EOM') + debug_display(io.string) + + expect(io.string).to include(<<~EOM) 6 class SyntaxTree < Ripper 170 def self.parse(source) 174 end @@ -41,7 +41,7 @@ module SyntaxSuggest io = StringIO.new debug_perf do - benchmark = Benchmark.measure do + benchmark_measure do SyntaxSuggest.call( io: io, source: file.read, @@ -49,11 +49,10 @@ module SyntaxSuggest ) end debug_display(io.string) - debug_display(benchmark) end expect(io.string).to_not include("def ruby_install_binstub_path") - expect(io.string).to include(<<~'EOM') + expect(io.string).to include(<<~EOM) > 1067 def add_yarn_binary > 1068 return [] if yarn_preinstalled? > 1069 | @@ -71,7 +70,7 @@ module SyntaxSuggest ) debug_display(io.string) - expect(io.string).to include(<<~'EOM') + expect(io.string).to include(<<~EOM) 1 Rails.application.routes.draw do > 113 namespace :admin do > 116 match "/foobar(*path)", via: :all, to: redirect { |_params, req| @@ -90,7 +89,7 @@ module SyntaxSuggest ) debug_display(io.string) - expect(io.string).to include(<<~'EOM') + expect(io.string).to include(<<~EOM) 1 describe "webmock tests" do 22 it "body" do 27 query = Cutlass::FunctionQuery.new( @@ -112,12 +111,9 @@ module SyntaxSuggest ) debug_display(io.string) - expect(io.string).to include(<<~'EOM') + expect(io.string).to include(<<~EOM) 5 module DerailedBenchmarks 6 class RequireTree - 7 REQUIRED_BY = {} - 9 attr_reader :name - 10 attr_writer :cost > 13 def initialize(name) > 18 def self.reset! > 25 end @@ -160,7 +156,6 @@ module SyntaxSuggest out = io.string expect(out).to include(<<~EOM) 16 class Rexe - 18 VERSION = '1.5.1' > 77 class Lookups > 140 def format_requires > 148 end @@ -169,7 +164,7 @@ module SyntaxSuggest end it "ambiguous end" do - source = <<~'EOM' + source = <<~EOM def call # 0 print "lol" # 1 end # one # 2 @@ -189,7 +184,7 @@ module SyntaxSuggest end it "simple regression" do - source = <<~'EOM' + source = <<~EOM class Dog def bark puts "woof" @@ -207,5 +202,59 @@ module SyntaxSuggest > 4 end EOM end + + it "multi-line chain with missing paren" do + source = <<~EOM + class Dog + def bark + User + .where(name: "schneems" + .first + end + end + EOM + io = StringIO.new + SyntaxSuggest.call( + io: io, + source: source + ) + out = io.string + expect(out).to include(<<~EOM) + > 3 User + > 4 .where(name: "schneems" + > 5 .first + EOM + end + + it "empty else" do + source = <<~EOM + class Foo + def foo + if cond? + foo + else + + end + end + + # ... + + def bar + if @recv + end_is_missing_here + end + end + EOM + + io = StringIO.new + SyntaxSuggest.call( + io: io, + source: source + ) + out = io.string + expect(out).to include(<<~EOM) + end_is_missing_here + EOM + end end end |
