Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

puts within method in rspec test

Tags:

my_file_spec.rb:

require 'spec_helper'
require 'my_file'

module M
  describe C do
    it 'should print everything' do
      c = C.new
      c.meth.should == "something"
    end
  end
end

my_file.rb:

module M
  class C
    puts "class TEXT" # label1
    def meth
     puts "method TEXT" # label2
     return "something"
    end
  end
end 

The output is:

class TEXT

M::C
  should print everything

Finished in 0.75 seconds
1 example, 0 failures

And finally the question: "Why wasn't the label2 -- ("method TEXT") printed after the test had been run?"

P.S. Ruby192, rspec2

like image 714
ted Avatar asked Aug 15 '12 13:08

ted


1 Answers

Try using $stderr.puts "method TEXT". This works for me. Just be aware that it is considered bad practice to write tests that have output that you need to examine manually, but I guess you already know that...

like image 119
davidrac Avatar answered Oct 23 '22 03:10

davidrac