在运行RSpec测试时启动irb以进行调试?

rud*_*ph9 0 ruby testing rspec irb

如何在我的rspec测试运行期间启动irb

基本上我希望能够玩各种各样的东西,然后我的rspec测试运行在程序的相应实例上.我能够在程序的常规运行时成功执行此操作,但是当我尝试在rspec测试的运行时期间启动irb时遇到问题.

传统运行时

test.rb

#!/usr/bin/env ruby
require 'irb'

puts 'hello world'
IRB.start
puts 'goodbye world'
Run Code Online (Sandbox Code Playgroud)

运行

$ ./test.rb 
hello world
1.9.3-p194 :001 > puts 'yo'
yo
 => nil 
1.9.3-p194 :002 > exit
goodbye world
Run Code Online (Sandbox Code Playgroud)

rspec运行时

test_spec.rb

require 'spec_helper'
require 'irb'

describe "irb" do
  it "should print 'hello world', launch irb, upon exiting irb print 'goodbye world'" do
    puts 'hello world'
    IRB.start
    puts 'goodbye world'
  end
end
Run Code Online (Sandbox Code Playgroud)

运行

$ rake spec
/Users/username/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec ./spec/test_spec.rb
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}
hello world
1.9.3p194 :001 > require 'spec_helper'
 => false
1.9.3p194 :002 > require 'irb'
 => false
1.9.3p194 :003 >
1.9.3p194 :004 >   describe "irb" do
1.9.3p194 :005 >       it "should print 'hello world', launch irb, upon exiting irb print 'goodbye world'" do
1.9.3p194 :006 >           puts 'hello world'
1.9.3p194 :007?>         IRB.start
1.9.3p194 :008?>         puts 'goodbye world'
1.9.3p194 :009?>       end
1.9.3p194 :010?>   end1.9.3p194 :010?>
 => RSpec::Core::ExampleGroup::Nested_2
1.9.3p194 :010 >
goodbye world
.

Finished in 0.10321 seconds
1 example, 0 failures

Randomized with seed 62613
$
Run Code Online (Sandbox Code Playgroud)

小智 5

使用.

简单,快速,语法高亮.安装完成后,您只需要写:

binding.pry
Run Code Online (Sandbox Code Playgroud)

在您的代码中停止执行并显示开发人员调试控制台

在你爱上撬之后,还有一个名为'pry-nav'的有用宝石