Vscode-ruby: rspec doesn't execute as a program, it is parsed as if it's a code file.

Created on 1 Jun 2018  路  3Comments  路  Source: rubyide/vscode-ruby

Your environment

  • vscode-ruby version: 0.6.1
  • Ruby version: 2.4.1
  • VS Code version: 1.23.1
  • Operating System: 10.13.3
  • Hardware (optional): MacBook Pro

Expected behavior

Putting the following configuration in launch.json
{
"name": "RSpec - active spec file only",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "../.rbenv/shims/rspec",
"args": ["${file}"]
},

Should allow me to run my spec file like it runs at the terminal

Actual behavior

rspec bash program is opened as if it is the ruby script to be ran, and since it's a bash script and not a ruby script, I get an error that shows a syntax error in the ruby bash script.
< The following is the error message which just shows the first few lines of the rspec bash program's code where it thinks it's getting a syntax error because I guess it thinks it's supposed to open the file and not run it as a program. >

Uncaught exception: /Users//.rbenv/shims/rspec:3: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
[ -n "$RBENV_DEBUG" ] && set -x
^
/Users//.rbenv/shims/rspec:3: syntax error, unexpected ']', expecting end-of-input
[ -n "$RBENV_DEBUG" ] && set -x

Steps to reproduce the problem

1) install rbenv
2) install ruby 2.4.1 using rbenv
3) setup a launcher with the configuration pasted above in the expected behavior in VS Code's launch.json file.
4) create a spec file to run
5) go into debug mode on VS Code
6) select the launcher you just created (RSpec - active spec file only)
7) Press the green arrow to Debug the spec file using the launcher.

Most helpful comment

@degoeym change:
"pathToBundler": "${env:HOME}/.rbenv/shims/bundle",
to:
"pathToBundler": "${workspaceRoot}/bin/bundle",,

All 3 comments

Looks like this is an issue with how rbenv switches ruby versions. rbenv creates a shim directory, and in it, somehow creates a pointer type file to the correct version of rspec, by not using the rspec file in the shim directory, but instead, using the rspec file in the /bin directory does the trick and fixes this issue. Closing this issue.

@atracy Could you share your updated config to show what the updated program property looks like?

@degoeym change:
"pathToBundler": "${env:HOME}/.rbenv/shims/bundle",
to:
"pathToBundler": "${workspaceRoot}/bin/bundle",,

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lalunamel picture lalunamel  路  5Comments

wingrunr21 picture wingrunr21  路  4Comments

SerkanOruc picture SerkanOruc  路  5Comments

pelletencate picture pelletencate  路  5Comments

ckruse picture ckruse  路  5Comments