You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sql_timer_struct_spec.rb 3.0 kB

12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. require 'spec_helper'
  2. require 'rack-mini-profiler'
  3. describe Rack::MiniProfiler::SqlTimerStruct do
  4. describe 'valid sql timer' do
  5. before do
  6. @sql = Rack::MiniProfiler::SqlTimerStruct.new("SELECT * FROM users", 200, Rack::MiniProfiler::PageTimerStruct.new({}), nil)
  7. end
  8. it 'has an ExecuteType' do
  9. @sql['ExecuteType'].should_not be_nil
  10. end
  11. it 'has a FormattedCommandString' do
  12. @sql['FormattedCommandString'].should_not be_nil
  13. end
  14. it 'has a StackTraceSnippet' do
  15. @sql['StackTraceSnippet'].should_not be_nil
  16. end
  17. it 'has a StartMilliseconds' do
  18. @sql['StartMilliseconds'].should_not be_nil
  19. end
  20. it 'has a DurationMilliseconds' do
  21. @sql['DurationMilliseconds'].should_not be_nil
  22. end
  23. it 'has a IsDuplicate' do
  24. @sql['IsDuplicate'].should_not be_nil
  25. end
  26. end
  27. describe 'backtrace' do
  28. it 'has a snippet' do
  29. sql = Rack::MiniProfiler::SqlTimerStruct.new("SELECT * FROM users", 200, Rack::MiniProfiler::PageTimerStruct.new({}), nil)
  30. sql['StackTraceSnippet'].should_not be nil
  31. end
  32. it 'includes rspec in the trace (default is no filter)' do
  33. sql = Rack::MiniProfiler::SqlTimerStruct.new("SELECT * FROM users", 200, Rack::MiniProfiler::PageTimerStruct.new({}), nil)
  34. sql['StackTraceSnippet'].should match /rspec/
  35. end
  36. it "doesn't include rspec if we filter for only app" do
  37. Rack::MiniProfiler.config.backtrace_includes = [/\/app/]
  38. sql = Rack::MiniProfiler::SqlTimerStruct.new("SELECT * FROM users", 200, Rack::MiniProfiler::PageTimerStruct.new({}), nil)
  39. sql['StackTraceSnippet'].should_not match /rspec/
  40. end
  41. it "includes rspec if we filter for it" do
  42. Rack::MiniProfiler.config.backtrace_includes = [/\/(app|rspec)/]
  43. sql = Rack::MiniProfiler::SqlTimerStruct.new("SELECT * FROM users", 200, Rack::MiniProfiler::PageTimerStruct.new({}), nil)
  44. sql['StackTraceSnippet'].should match /rspec/
  45. end
  46. it "ingores rspec if we specifically ignore it" do
  47. Rack::MiniProfiler.config.backtrace_ignores = [/\/rspec/]
  48. sql = Rack::MiniProfiler::SqlTimerStruct.new("SELECT * FROM users", 200, Rack::MiniProfiler::PageTimerStruct.new({}), nil)
  49. sql['StackTraceSnippet'].should_not match /rspec/
  50. end
  51. it "should omit the backtrace if the query takes less than the threshold time" do
  52. Rack::MiniProfiler.config.backtrace_threshold_ms = 100
  53. sql = Rack::MiniProfiler::SqlTimerStruct.new("SELECT * FROM users", 50, Rack::MiniProfiler::PageTimerStruct.new({}), nil)
  54. sql['StackTraceSnippet'].should be nil
  55. end
  56. it "should not omit the backtrace if the query takes more than the threshold time" do
  57. Rack::MiniProfiler.config.backtrace_threshold_ms = 100
  58. sql = Rack::MiniProfiler::SqlTimerStruct.new("SELECT * FROM users", 200, Rack::MiniProfiler::PageTimerStruct.new({}), nil)
  59. sql['StackTraceSnippet'].should_not be nil
  60. end
  61. end
  62. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...