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

Allow debugging with vscode #1517

Merged
merged 10 commits into from
Apr 6, 2021
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ target
*.tmproj
.#*
.idea
.vscode
*.pyc
*.rbc
rerun.txt
Expand All @@ -29,6 +30,7 @@ tags
.ruby-version
.project
Gemfile.local
Gemfile.local.lock
.envrc
Gemfile.lock
bin/json-formatter
Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ AllCops:
# `-S/--display-style-guide` option.
DisplayStyleGuide: true
Exclude:
- 'bin/*'
- 'tmp/**/*'
- 'vendor/**/*'
- 'temp_app/**/*'
Expand Down
22 changes: 17 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,29 @@ You can chat with the core team on https://gitter.im/cucumber/contributors. We t

## Installing your own gems

A `Gemfile.local`-file can be used to have your own gems installed to support
your normal development workflow.
A `Gemfile.local`-file can be used to have your own gems installed to support your normal development workflow.
Execute `bundle config set --local gemfile Gemfile.local` to use it per default.

Example:

~~~ruby
gem 'pry'
gem 'pry-byebug'
gem 'byebug'
# Include the regular Gemfile
eval File.read('Gemfile')

group :development do
gem 'byebug'
gem 'debase', require: false
gem 'ruby-debug-ide', require: false
gem 'pry'
gem 'pry-byebug'
end
~~~

## Using Visual Studio Code?

Sample for launch.json configuration is available in
[docs/vscode-example-launch-configuration.md](https://github.com/cucumber/cucumber-ruby/blob/master/docs/vscode-example-launch-configuration.md)

## Note on Patches/Pull Requests

* Fork the project. Make a branch for your change.
Expand Down
29 changes: 29 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile.local",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
94 changes: 94 additions & 0 deletions docs/vscode-example-launch-configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
## Pre-requisites

### Ruby Extension

Install and configure the
[ruby extension](https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby)

### Use `debase` and `ruby-debug-ide` gems locally

Make sure to use a `Gemfile.local` file with `debase` and `ruby-debug-ide` gems.

~~~ruby
# Include the regular Gemfile
eval File.read('Gemfile')

group :development do
gem 'debase', require: false
gem 'ruby-debug-ide', require: false
end
~~~

Execute `bundle config set --local gemfile Gemfile.local` to use it per default,
then `bundle install`.

## Sample launch.json

The following `launch.json` - to be placed in the `.vscode` folder - allows to use
VSCode debugging features like **breakpoints** and **watches**.

```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Cucumber",
"type": "Ruby",
"request": "launch",
"useBundler": true,
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/cucumber",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "Cucumber current feature file",
"type": "Ruby",
"request": "launch",
"useBundler": true,
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/cucumber",
"args": ["${file}"],
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "Cucumber scenario under cursor",
"type": "Ruby",
"request": "launch",
"useBundler": true,
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/cucumber",
"args": ["${file}:${lineNumber}"],
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "Rspec",
"type": "Ruby",
"request": "launch",
"useBundler": true,
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "Rspec current file",
"type": "Ruby",
"request": "launch",
"useBundler": true,
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"args": ["${file}"],
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "Rspec current line",
"type": "Ruby",
"request": "launch",
"useBundler": true,
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"args": ["${file}:${lineNumber}"],
"internalConsoleOptions": "openOnSessionStart"
}
]
}
```
1 change: 1 addition & 0 deletions lib/cucumber/formatter/backtrace_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Formatter
test/unit
.gem/ruby
bin/bundle
rdebug-ide
]

@backtrace_filters << RbConfig::CONFIG['rubyarchdir'] if RbConfig::CONFIG['rubyarchdir']
Expand Down