Permalink
Browse files

Moved code into test_helper

  • Loading branch information...
bhb committed Jan 6, 2011
1 parent 682d10a commit 286594fb97601fbb27e3e6144ba7fe30f75bfe8e
Showing with 61 additions and 61 deletions.
  1. +0 −61 test/rack-perftools-profiler_test.rb
  2. +61 −0 test/test_helper.rb
@@ -1,66 +1,5 @@
require 'test_helper'
-ITERATIONS = case RUBY_VERSION
- when /1\.9\.1/
- 350_000 # Ruby 1.9.1 is that we need to add extra iterations to get profiling data
- else
- 35_000
- end
-
-# From the Rack spec (http://rack.rubyforge.org/doc/files/SPEC.html) :
-# The Body must respond to each and must only yield String values. The Body should not be an instance of String.
-# ... The Body commonly is an Array of Strings, the application instance itself, or a File-like object.
-
-class RackResponseBody
- include Test::Unit::Assertions
-
- def initialize(body)
- assert !body.instance_of?(String)
- @body = body
- end
-
- def to_s
- str = ""
- @body.each do |part|
- str << part
- end
- str
- end
-
-end
-
-class TestApp
-
- def call(env)
- case env['PATH_INFO']
- when /method1/
- ITERATIONS.times do
- self.class.new.method1
- end
- GC.start
- when /method2/
- ITERATIONS.times do
- self.class.new.method2
- end
- GC.start
- end
- [200, {}, ['Done']]
- end
-
- def method1
- 100.times do
- 1+2+3+4+5
- end
- end
-
- def method2
- 100.times do
- 1+2+3+4+5
- end
- end
-
-end
-
class RackPerftoolsProfilerTest < Test::Unit::TestCase
include Rack::PerftoolsProfiler
View
@@ -9,3 +9,64 @@
class Test::Unit::TestCase
end
+
+ITERATIONS = case RUBY_VERSION
+ when /1\.9\.1/
+ 350_000 # Ruby 1.9.1 is that we need to add extra iterations to get profiling data
+ else
+ 35_000
+ end
+
+# From the Rack spec (http://rack.rubyforge.org/doc/files/SPEC.html) :
+# The Body must respond to each and must only yield String values. The Body should not be an instance of String.
+# ... The Body commonly is an Array of Strings, the application instance itself, or a File-like object.
+
+class RackResponseBody
+ include Test::Unit::Assertions
+
+ def initialize(body)
+ assert !body.instance_of?(String)
+ @body = body
+ end
+
+ def to_s
+ str = ""
+ @body.each do |part|
+ str << part
+ end
+ str
+ end
+
+end
+
+class TestApp
+
+ def call(env)
+ case env['PATH_INFO']
+ when /method1/
+ ITERATIONS.times do
+ self.class.new.method1
+ end
+ GC.start
+ when /method2/
+ ITERATIONS.times do
+ self.class.new.method2
+ end
+ GC.start
+ end
+ [200, {}, ['Done']]
+ end
+
+ def method1
+ 100.times do
+ 1+2+3+4+5
+ end
+ end
+
+ def method2
+ 100.times do
+ 1+2+3+4+5
+ end
+ end
+
+end

0 comments on commit 286594f

Please sign in to comment.