Sha256: 0a23a6265a090720c33c9e7842f25de85f424f154ea0d02bd27b6f155672ac99

Contents?: true

Size: 1.98 KB

Versions: 39

Compression:

Stored size: 1.98 KB

Contents

require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'mocha'
require 'rack/test'
require 'webrat'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'active_support_helpers'
require 'sinatra_more'

class Test::Unit::TestCase
  include SinatraMore::OutputHelpers
  include SinatraMore::TagHelpers
  include SinatraMore::AssetTagHelpers
  include Rack::Test::Methods
  include Webrat::Methods
  include Webrat::Matchers

  Webrat.configure do |config|
    config.mode = :rack
  end

  def stop_time_for_test
    time = Time.now
    Time.stubs(:now).returns(time)
    return time
  end

  # assert_has_tag(:h1, :content => "yellow") { "<h1>yellow</h1>" }
  # In this case, block is the html to evaluate
  def assert_has_tag(name, attributes = {}, &block)
    html = block && block.call
    matcher = HaveSelector.new(name, attributes)
    raise "Please specify a block!" if html.blank?
    assert matcher.matches?(html), matcher.failure_message
  end

  # assert_has_no_tag, tag(:h1, :content => "yellow") { "<h1>green</h1>" }
  # In this case, block is the html to evaluate
  def assert_has_no_tag(name, attributes = {}, &block)
    html = block && block.call
    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:
      @logger = nil
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
sinatra_more-0.3.41 test/helper.rb
sinatra_more-0.3.40 test/helper.rb
sinatra_more-0.3.39 test/helper.rb
sinatra_more-0.3.38 test/helper.rb
sinatra_more-0.3.37 test/helper.rb
sinatra_more-0.3.36 test/helper.rb
sinatra_more-0.3.35 test/helper.rb
sinatra_more-0.3.34 test/helper.rb
sinatra_more-0.3.33 test/helper.rb
sinatra_more-0.3.32 test/helper.rb
sinatra_more-0.3.31 test/helper.rb
sinatra_more-0.3.30 test/helper.rb
sinatra_more-0.3.29 test/helper.rb
sinatra_more-0.3.28 test/helper.rb
sinatra_more-0.3.27 test/helper.rb
sinatra_more-0.3.26 test/helper.rb
sinatra_more-0.3.25 test/helper.rb
sinatra_more-0.3.24 test/helper.rb
sinatra_more-0.3.23 test/helper.rb
sinatra_more-0.3.22 test/helper.rb