test/helper.rb in sinatra_more-0.2.9 vs test/helper.rb in sinatra_more-0.3.0
- old
+ new
@@ -44,9 +44,25 @@
attributes.merge!(:count => 0)
matcher = HaveSelector.new(name, attributes)
raise "Please specify a block!" if html.blank?
assert matcher.matches?(html), matcher.failure_message
end
+
+ # Silences the output by redirecting to stringIO
+ # silence_logger { ...commands... } => "...output..."
+ def silence_logger(&block)
+ orig_stdout = $stdout
+ $stdout = log_buffer = StringIO.new
+ block.call
+ $stdout = orig_stdout
+ log_buffer.rewind && log_buffer.read
+ end
+
+ # Asserts that a file matches the pattern
+ def assert_match_in_file(pattern, file)
+ assert File.exist?(file), "File '#{file}' does not exist!"
+ assert_match pattern, File.read(file)
+ end
end
module Webrat
module Logging
def logger # :nodoc: