Clxy Clxy - 3 months ago 29
Ruby Question

Run rspec on VS Code

I have rspec test code like this

describe 'Utils' do

puts 1111
describe '#time_condition' do
puts 2221
it do
puts 'aaa'
end
puts 2223
end
end


my launch.json like this

{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/spec/*_rspec.rb",
"args": [
"--pattern",
"*_rspec.rb"
]
},


when I run test on vscode, I got

1111
2221
2223


when I run test by command, got

>rspec spec --pattern *_rspec.rb
1111
2221
2223
aaa
.

Finished in 0.003 seconds (files took 0.23602 seconds to load)
1 example, 0 failures


As your can see, no 'aaa' output, means no 'it' was executed.
So...How can I make 'it' to run on vscode?

by the way, my spec config files (generated by rspec --init)like

.rspec

--color
--require spec_helper


spec\spec_helper.rb

RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end

config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end

config.profile_examples = 10

config.order = :random

Kernel.srand config.seed
end


VScode : 1.4.0

Ruby Extensions : 0.5.3

thanks

Answer

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"
  ]
},
...