test/unit/test_tracy.rb in stack_tracy-0.1.8 vs test/unit/test_tracy.rb in stack_tracy-0.1.9

- old
+ new

@@ -9,10 +9,18 @@ c.only = nil c.exclude = nil end end + def correct(array) + if RUBY_VERSION == "1.8.7" + array.delete_if{|x| x[:call] == "IO#puts"} + array.each{|x| x[:depth] -= 1 if x[:depth] && x[:call] == "IO#write"} + end + array + end + it "should respond to methods as expected" do assert StackTracy.respond_to?(:config) assert StackTracy.respond_to?(:start) assert StackTracy.respond_to?(:stop) assert StackTracy.respond_to?(:stack_trace) @@ -23,25 +31,32 @@ end it "should be configurable" do StackTracy.config do |c| assert_equal true, c.is_a?(Struct) - assert_equal [:dump_dir, :dump_source_location, :limit, :threshold, :messages_only, :slows_only, :only, :exclude], c.members + assert_equal %w(dump_dir dump_source_location limit threshold messages_only slows_only only exclude), c.members.collect(&:to_s) c.only = "Kernel" c.exclude = ["IO", "String"] end assert_equal({:only => "Kernel", :exclude => ["IO", "String"]}, StackTracy.send(:merge_options)) assert_equal({:only => "Object", :exclude => ["IO", "String"]}, StackTracy.send(:merge_options, {:only => "Object"})) assert_equal({:only => "Object", :exclude => nil}, StackTracy.send(:merge_options, {:only => "Object", :exclude => nil})) assert_equal({:only => "Paul", :exclude => "Foo"}, StackTracy.send(:merge_options, {"only" => "Paul", "exclude" => "Foo"})) assert_equal({:only => nil, :exclude => nil}, StackTracy.send(:merge_options, {:only => nil, :exclude => nil})) - assert_equal( - "Array BasicObject Enumerable Fixnum Float Foo Hash IO Integer Kernel Module Mutex Numeric Object Rational String Symbol Thread Time", - StackTracy.send(:mod_names, [:core, "Foo"]) - ) + if RUBY_VERSION == "1.8.7" + assert_equal( + "Array Enumerable Fixnum Float Foo Hash IO Integer Kernel Module Numeric Object Rational String Symbol Thread Time", + StackTracy.send(:mod_names, [:core, "Foo"]).strip + ) + else + assert_equal( + "Array BasicObject Enumerable Fixnum Float Foo Hash IO Integer Kernel Module Mutex Numeric Object Rational String Symbol Thread Time", + StackTracy.send(:mod_names, [:core, "Foo"]) + ) + end assert_equal( "ActiveRecord::Base", StackTracy.send(:mod_names, :active_record) ) @@ -57,22 +72,22 @@ puts "testing" end file, line = __FILE__, __LINE__ - 2 st = File.expand_path("../../../lib/stack_tracy.rb", __FILE__) - assert_equal [ + assert_equal correct([ {:event => "c-call" , :file => file, :line => line, :singleton => false, :object => Kernel , :method => "puts" , :call => "Kernel#puts" }, {:event => "c-call" , :file => file, :line => line, :singleton => false, :object => IO , :method => "puts" , :call => "IO#puts" }, {:event => "c-call" , :file => file, :line => line, :singleton => false, :object => IO , :method => "write", :call => "IO#write" }, {:event => "c-return", :file => file, :line => line, :singleton => false, :object => IO , :method => "write", :call => "IO#write" }, {:event => "c-call" , :file => file, :line => line, :singleton => false, :object => IO , :method => "write", :call => "IO#write" }, {:event => "c-return", :file => file, :line => line, :singleton => false, :object => IO , :method => "write", :call => "IO#write" }, {:event => "c-return", :file => file, :line => line, :singleton => false, :object => IO , :method => "puts" , :call => "IO#puts" }, {:event => "c-return", :file => file, :line => line, :singleton => false, :object => Kernel , :method => "puts" , :call => "Kernel#puts" }, {:event => "call" , :file => st , :line => 35 , :singleton => false, :object => StackTracy, :method => "stop" , :call => "StackTracy#stop" }, {:event => "c-call" , :file => st , :line => 36 , :singleton => 0 , :object => StackTracy, :method => "_stop", :call => "StackTracy._stop"} - ], StackTracy.stack_trace.collect{ |event_info| + ]), StackTracy.stack_trace.collect{ |event_info| event_info.to_hash.tap do |hash| assert hash.delete(:nsec) hash.delete(:time) end } @@ -114,16 +129,16 @@ stack_tracy do puts "testing" end file, line = __FILE__, __LINE__ - 2 - assert_equal [ + assert_equal correct([ {:event => "c-call" , :file => file, :line => line, :singleton => false, :object => Kernel, :method => "puts" , :call => "Kernel#puts", :depth => 0}, {:event => "c-call" , :file => file, :line => line, :singleton => false, :object => IO , :method => "puts" , :call => "IO#puts" , :depth => 1}, {:event => "c-call" , :file => file, :line => line, :singleton => false, :object => IO , :method => "write", :call => "IO#write" , :depth => 2}, {:event => "c-call" , :file => file, :line => line, :singleton => false, :object => IO , :method => "write", :call => "IO#write" , :depth => 2} - ], StackTracy.select.collect{ |event_info| + ]), StackTracy.select.collect{ |event_info| event_info.to_hash.tap do |hash| assert hash.delete(:nsec) assert hash.delete(:duration) hash.delete(:time) end @@ -211,16 +226,16 @@ stack_tracy do puts "testing" end file, line = __FILE__, __LINE__ - 2 - assert_equal [ + assert_equal correct([ {:event => "c-call", :file => file, :line => line, :singleton => false, :object => Kernel, :method => "puts" , :call => "Kernel#puts", :depth => 0}, {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO , :method => "puts" , :call => "IO#puts" , :depth => 1}, {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO , :method => "write", :call => "IO#write" , :depth => 2}, {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO , :method => "write", :call => "IO#write" , :depth => 2} - ], StackTracy.select("*").collect{ |event_info| + ]), StackTracy.select("*").collect{ |event_info| event_info.to_hash.tap do |hash| assert hash.delete(:nsec) assert hash.delete(:duration) hash.delete(:time) end @@ -234,27 +249,27 @@ assert hash.delete(:duration) hash.delete(:time) end } - assert_equal [ + assert_equal correct([ {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO, :method => "puts" , :call => "IO#puts" , :depth => 0}, {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO, :method => "write", :call => "IO#write", :depth => 1}, {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO, :method => "write", :call => "IO#write", :depth => 1} - ], StackTracy.select("IO").collect{ |event_info| + ]), StackTracy.select("IO").collect{ |event_info| event_info.to_hash.tap do |hash| assert hash.delete(:nsec) assert hash.delete(:duration) hash.delete(:time) end } - assert_equal [ + assert_equal correct([ {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO, :method => "puts" , :call => "IO#puts" , :depth => 0}, {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO, :method => "write", :call => "IO#write", :depth => 1}, {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO, :method => "write", :call => "IO#write", :depth => 1} - ], StackTracy.select("IO*").collect{ |event_info| + ]), StackTracy.select("IO*").collect{ |event_info| event_info.to_hash.tap do |hash| assert hash.delete(:nsec) assert hash.delete(:duration) hash.delete(:time) end @@ -263,15 +278,15 @@ assert_equal [ ], StackTracy.select("I*").collect{ |event_info| event_info.to_hash } - assert_equal [ + assert_equal correct([ {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO, :method => "puts" , :call => "IO#puts" , :depth => 0}, {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO, :method => "write", :call => "IO#write", :depth => 1}, {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO, :method => "write", :call => "IO#write", :depth => 1} - ], StackTracy.select("IO#").collect{ |event_info| + ]), StackTracy.select("IO#").collect{ |event_info| event_info.to_hash.tap do |hash| assert hash.delete(:nsec) assert hash.delete(:duration) hash.delete(:time) end @@ -297,13 +312,13 @@ assert hash.delete(:duration) hash.delete(:time) end } - assert_equal [ + assert_equal correct([ {:event => "c-call", :file => file, :line => line, :singleton => false, :object => Kernel, :method => "puts", :call => "Kernel#puts", :depth => 0}, {:event => "c-call", :file => file, :line => line, :singleton => false, :object => IO , :method => "puts", :call => "IO#puts" , :depth => 1} - ], StackTracy.select("*#puts").collect{ |event_info| + ]), StackTracy.select("*#puts").collect{ |event_info| event_info.to_hash.tap do |hash| assert hash.delete(:nsec) assert hash.delete(:duration) hash.delete(:time) end \ No newline at end of file