test/test_middleware.rb in stackprof-0.2.6 vs test/test_middleware.rb in stackprof-0.2.7
- old
+ new
@@ -36,6 +36,28 @@
File.expects(:open).with(regexp_matches(/^\/foo\/stackprof-foo/), 'wb')
StackProf::Middleware.save
end
+ def test_enabled_should_use_a_proc_if_passed
+ env = {}
+
+ StackProf::Middleware.new(Object.new, enabled: Proc.new{ false })
+ refute StackProf::Middleware.enabled?(env)
+
+ StackProf::Middleware.new(Object.new, enabled: Proc.new{ true })
+ assert StackProf::Middleware.enabled?(env)
+ end
+
+ def test_enabled_should_use_a_proc_if_passed_and_use_the_request_env
+ enable_proc = Proc.new {|env| env['PROFILE'] }
+
+ env = Hash.new { false }
+ StackProf::Middleware.new(Object.new, enabled: enable_proc)
+ refute StackProf::Middleware.enabled?(env)
+
+ env = Hash.new { true}
+ StackProf::Middleware.new(Object.new, enabled: enable_proc)
+ assert StackProf::Middleware.enabled?(env)
+ end
+
end