问题描述
我正在尝试让 Ruby 调试器在我的规范之一中运行:
I'm trying to get Ruby debugger running in one of my specs:
describe User do
it "should be valid" do
debugger
User.new.should be_valid
end
end
当我运行 rspec 时,我得到:
When I run rspec though, I get:
debugger statement ignored, use -d or --debug option to enable debugging
我尝试了以下方法:
rake spec --debug
rake spec --debug --trace
rake spec:models --debug
bundle exec rspec --debug
bundle exec rspec --debug spec/models/
bundle exec rspec --d spec/models/
bundle exec "rspec --debug" spec/models/
bundle exec rspec --debugger spec/models/
bundle exec --debugger rspec spec/models/
bundle --debugger exec rspec spec/models/
bundle --debugger exec rspec spec/models/
bundle exec --debugger rspec spec/models/
bundle exec rspec --debugger spec/models/
关于如何以正确的方式执行 rspec 的任何想法?我在使用 Rails 3.0.5、Ruby 1.9.2、RSpec 2.5.1、ruby-debug19.
Any ideas on how to exec rspec in the right way? I'm on Rails 3.0.5, Ruby 1.9.2, RSpec 2.5.1, ruby-debug19.
谢谢,贾斯汀.
推荐答案
通过在规范顶部包含require 'ruby-debug'
,您将得到您想要的:
You will get what you want by including require 'ruby-debug'
at the top of your spec:
# spec/models/user_spec.rb
require 'spec_helper'
require 'ruby-debug'
describe User do
it "should be valid" do
debugger
User.new.should be_valid
end
end
然后您将正常运行 rake spec
或 rspec
You would then run rake spec
or rspec
as normal
注意:我现在更喜欢 Ruby 2.0+ 和 pry.这几乎是相同的过程:
NOTE: I now prefer Ruby 2.0+ and pry. It is pretty much the same process:
require 'spec_helper'
require 'pry-debugger'
describe User do
it "should be valid" do
binding.pry
expect(User.new).to be_valid
end
end
此外,我通常在我的 spec_helper 文件中放置这样的需求,以便 pry-debugger 可用于我的所有规范.
Also, I generally put requires like this in my spec_helper file, so that pry-debugger is available to all of my specs.
这篇关于在 rspec 中运行 ruby 调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!