Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSpec won't use syntax_suggest #171

Open
JunichiIto opened this issue Dec 24, 2022 · 3 comments
Open

RSpec won't use syntax_suggest #171

JunichiIto opened this issue Dec 24, 2022 · 3 comments

Comments

@JunichiIto
Copy link

JunichiIto commented Dec 24, 2022

I wrote a sample RSpec code to test syntax_suggest and Ruby 3.2.0rc1: https://github.com/JunichiIto/syntax_suggest_sandbox

I have a wrong spec file:

https://github.com/JunichiIto/syntax_suggest_sandbox/blob/main/spec/sample_spec.rb

RSpec.describe 'sample' do
  exampledo
    expect(1 + 1).to eq 2
  end
end

I added gem "syntax_suggest" to Gemfile and --require syntax_suggest to .rspec according to README.

I ran bundle exec rspec but RSpec won't use syntax_suggest:

$ bundle exec rspec                     

An error occurred while loading ./spec/sample_spec.rb.
Failure/Error: __send__(method, file)

SyntaxError:
  /Users/jnito/dev/sandbox/syntax_suggest_sandbox/spec/sample_spec.rb:5: syntax error, unexpected `end'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0+3/gems/rspec-core-3.12.0/lib/rspec/core/configuration.rb:2117:in `load'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0+3/gems/rspec-core-3.12.0/lib/rspec/core/configuration.rb:2117:in `load_file_handling_errors'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0+3/gems/rspec-core-3.12.0/lib/rspec/core/configuration.rb:1617:in `block in load_spec_files'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0+3/gems/rspec-core-3.12.0/lib/rspec/core/configuration.rb:1615:in `each'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0+3/gems/rspec-core-3.12.0/lib/rspec/core/configuration.rb:1615:in `load_spec_files'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0+3/gems/rspec-core-3.12.0/lib/rspec/core/runner.rb:102:in `setup'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0+3/gems/rspec-core-3.12.0/lib/rspec/core/runner.rb:86:in `run'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0+3/gems/rspec-core-3.12.0/lib/rspec/core/runner.rb:71:in `run'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0+3/gems/rspec-core-3.12.0/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0+3/gems/rspec-core-3.12.0/exe/rspec:4:in `<top (required)>'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0+3/bin/rspec:25:in `load'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0+3/bin/rspec:25:in `<top (required)>'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/3.2.0+3/bundler/cli/exec.rb:58:in `load'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/3.2.0+3/bundler/cli/exec.rb:58:in `kernel_load'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/3.2.0+3/bundler/cli/exec.rb:23:in `run'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/3.2.0+3/bundler/cli.rb:486:in `exec'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/3.2.0+3/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/3.2.0+3/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/3.2.0+3/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/3.2.0+3/bundler/cli.rb:31:in `dispatch'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/3.2.0+3/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/3.2.0+3/bundler/cli.rb:25:in `start'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/gems/3.2.0+3/gems/bundler-2.4.0.dev/libexec/bundle:48:in `block in <top (required)>'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/3.2.0+3/bundler/friendly_errors.rb:120:in `with_friendly_errors'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/lib/ruby/gems/3.2.0+3/gems/bundler-2.4.0.dev/libexec/bundle:36:in `<top (required)>'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/bin/bundle:25:in `load'
# /Users/jnito/.rbenv/versions/3.2.0-rc1/bin/bundle:25:in `<main>'
# 
#   Showing full backtrace because every line was filtered out.
#   See docs for RSpec::Configuration#backtrace_exclusion_patterns and
#   RSpec::Configuration#backtrace_inclusion_patterns for more information.
No examples found.


Finished in 0.00002 seconds (files took 0.09691 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

CLI command works fine:

$ syntax_suggest spec/sample_spec.rb 
--> /Users/jnito/dev/sandbox/syntax_suggest_sandbox/spec/sample_spec.rb

Unmatched `end', missing keyword (`do', `def`, `if`, etc.) ?

  1  RSpec.describe 'sample' do
> 2    exampledo
> 4    end
  5  end

How can I use syntax_suggest when I ran bundle exec rspec ?

@schneems
Copy link
Collaborator

The gem is included in Ruby 3.2.0 you don’t need to add it to your Gemfile.

can you check with Ruby 3.2.0 and see if it still fails?

@JunichiIto
Copy link
Author

I removed "syntax_suggest" from Gemfile and ran against Ruby 3.2.0:
JunichiIto/syntax_suggest_sandbox@1a73457

But the result did not change:

$ ruby -v
ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin21]
$ bundle exec rspec

An error occurred while loading ./spec/sample_spec.rb.
Failure/Error: __send__(method, file)

SyntaxError:
  /Users/jnito/dev/sandbox/syntax_suggest_sandbox/spec/sample_spec.rb:5: syntax error, unexpected `end'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0/gems/rspec-core-3.12.0/lib/rspec/core/configuration.rb:2117:in `load'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0/gems/rspec-core-3.12.0/lib/rspec/core/configuration.rb:2117:in `load_file_handling_errors'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0/gems/rspec-core-3.12.0/lib/rspec/core/configuration.rb:1617:in `block in load_spec_files'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0/gems/rspec-core-3.12.0/lib/rspec/core/configuration.rb:1615:in `each'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0/gems/rspec-core-3.12.0/lib/rspec/core/configuration.rb:1615:in `load_spec_files'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0/gems/rspec-core-3.12.0/lib/rspec/core/runner.rb:102:in `setup'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0/gems/rspec-core-3.12.0/lib/rspec/core/runner.rb:86:in `run'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0/gems/rspec-core-3.12.0/lib/rspec/core/runner.rb:71:in `run'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0/gems/rspec-core-3.12.0/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0/gems/rspec-core-3.12.0/exe/rspec:4:in `<top (required)>'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0/bin/rspec:25:in `load'
# /Users/jnito/dev/sandbox/syntax_suggest_sandbox/vendor/bundle/ruby/3.2.0/bin/rspec:25:in `<top (required)>'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `load'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `kernel_load'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/cli/exec.rb:23:in `run'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/cli.rb:491:in `exec'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/cli.rb:34:in `dispatch'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/cli.rb:28:in `start'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.4.1/libexec/bundle:45:in `block in <top (required)>'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
# /Users/jnito/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.4.1/libexec/bundle:33:in `<top (required)>'
# /Users/jnito/.rbenv/versions/3.2.0/bin/bundle:25:in `load'
# /Users/jnito/.rbenv/versions/3.2.0/bin/bundle:25:in `<main>'
# 
#   Showing full backtrace because every line was filtered out.
#   See docs for RSpec::Configuration#backtrace_exclusion_patterns and
#   RSpec::Configuration#backtrace_inclusion_patterns for more information.
No examples found.


Finished in 0.00002 seconds (files took 0.09088 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

ruby command works fine:

$ ruby spec/sample_spec.rb 
spec/sample_spec.rb: --> spec/sample_spec.rb
Unmatched `end', missing keyword (`do', `def`, `if`, etc.) ?
  1  RSpec.describe 'sample' do
> 2    exampledo
> 4    end
  5  end
spec/sample_spec.rb:5: syntax error, unexpected `end' (SyntaxError)

@schneems
Copy link
Collaborator

Thank you for the error report 🙏 I found the problem and possible solution. It's written here rspec/rspec-core#2990. TLDR is that rspec needs to re-raise the SyntaxError or the contents won't be written to the screen.

I'm out on vacation at the moment but I hope there is enough information for someone to pick up the work and move forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants