Rails 如何使用 pry debug unit test

heliang7 · June 04, 2012 · Last by heliang7 replied at June 12, 2012 · 4591 hits

尝试 pry -r ./test/unit/xxx.rb

得到错误‘cannot load such file -- test_helper’

应该如何才能 debug rails 的单元测试呢?

我自己搞定了。

pry -Itest -r ./test/unit/xxx.rb

就行了。

@hisea 的帮助下,终于可以调试了。 总结下: 不用这么麻烦,和运行 rails s 一样

  1. 加入 pry 对应的 gem 到 test group
  2. 加入 binding.pry
  3. 运行测试即可

#2 楼 @heliang7 用法都一样,不只是 test, server 也可以这样来 debug.

#3 楼 @hisea server 的 debug 反而是先就知道的。test 的先尝试失败了,就怀疑不是那样了(估计忘了加 gem 到 test group。

You need to Sign in before reply, if you don't have an account, please Sign up first.