Run rspec on VS Code
OK. I solved it!
My fault is setting wrong value to program.
Program must be rspec path.
...
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "D:/Ruby/Ruby21/bin/rspec",
"args": [
"--pattern",
"${workspaceRoot}/spec/**/*_rspec.rb"
]
},
...
Run Rspec block via hot key in VS Code
You can install this extension https://marketplace.visualstudio.com/items?itemName=noku.rails-run-spec-vscode
And then press Cmd + L
to run the specific describe
or it
Run bundle exec command Tasks in Visual Studio Code
Thanks to Hurelu in this post, who explains how shell commands are constructed using the definitions in tasks.json, I have been able to define a tasks file that can run both rspec and cucumber, using bundle's exec:
{
"command": "bundle",
"args": ["exec"],
"tasks": [
{
"suppressTaskName": true,
"taskName": "rspec",
"args": [ "rspec", "${file}" ],
"isTestCommand": true
},
{
"suppressTaskName": true,
"taskName": "cucumber",
"args": [ "cucumber", "${file}" ]
}
]
}
RSpec is the test command, so you can use Cmd+Shift+T/Ctrl+Shift+t to run the current file as an RSpec test.
Happy coding!
How to run a single RSpec test?
Not sure how long this has bee available but there is an Rspec configuration for run filtering - so now you can add this to your spec_helper.rb
:
RSpec.configure do |config|
config.filter_run_when_matching :focus
end
And then add a focus tag to the it
, context
or describe
to run only that block:
it 'runs a test', :focus do
...test code
end
RSpec documentation:
https://www.rubydoc.info/github/rspec/rspec-core/RSpec/Core/Configuration#filter_run_when_matching-instance_method
How do I run debugger with the Rails run Spec extension?
Add pry-byebug
to your gemfile and run bundle install
# Gemfile
gem 'pry-byebug'
Then, whenever you want to inspect a test, add binding.pry
inside the test.
# some_spec.rb
it "is not behaving how I want it to" do
binding.pry
expect(my_var).to eq(some_val)
end
Related Topics
Why am I Getting This Passenger Error Could Not Find Rake-0.9.2.2 in Any of the Sources
Load Two Ruby Modules/Gems with the Same Name
Can the Rails Tmp/Cache/Assets Files Be Safely Deleted
Undefined Local Variable Based on Syntax in Ruby
Calendar Events Notification Not Received on Server
Session Not Destroyed When Closing Browser - Railstutorial.Org
Why Doesnt My Ruby Coding for Finding Prime Numbers Work
How to Use Private Submit to Hide from Profile
How to Write an Rspec Test for a Ruby Method That Contains "Gets.Chomp"
Ruby: Array Contained in Array, Any Order
Getting a List of Classes That Include a Module
/Config/Initializers/Secret_Token.Rb Not Being Generated. Why Not