How does one launch irb during the runtime of my rspec tests?
Essentially I would like to be able to play with various things and then have my rspec test run on the according instance of the program. I am able to successfully do this during conventional runtime of the program, however I run into issues when I attempt to launch irb during runtime of an rspec test.
conventional runtime
test.rb
#!/usr/bin/env ruby
require 'irb'
puts 'hello world'
IRB.start
puts 'goodbye world'
runtime
$ ./test.rb
hello world
1.9.3-p194 :001 > puts 'yo'
yo
=> nil
1.9.3-p194 :002 > exit
goodbye world
rspec runtime
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
runtime
$ 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
$
Use pry.
Simple, fast, with syntax highlighting. After install, you just need to write:
in your code to stop executing and display developer debugging console
After you fall in love with pry, there is also useful gem called ‘pry-nav’