public
Created

The test case of executing two rspec behaviours with line numbers

  • Download Gist
add_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13
describe "Add" do # sample test rspec 1
 
it "can add single digit" do
puts "Add 1 + 2"
(1+2).should == 3
end
it "can add double digit" do
puts "Add 11 + 22"
(11+22).should == 33
end
end
drive_rspec_runner.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13
require 'rubygems'
require 'rspec'
 
err, out = StringIO.new, StringIO.new
 
args = ["add_spec.rb", "--line_number", "4"]
RSpec::Core::Runner.run(args, err, out)
 
RSpec.reset
args = ["minus_spec.rb", "--line_number", "10"]
RSpec::Core::Runner.run(args, err, out)
 
out.rewind; puts out.read
minus_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
describe "Minu" do
 
 
# No tests on line 4
 
it "can minus single digit" do
puts "3 - 2"
(3-2).should == 1
end
it "can minus double digit" do
puts "22 - 11"
(22-11).should == 11
end
end

Download three files in the same folder, then run drive_rspec_runner.rb

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.