class MiniTest::Spec

def app

def app
  Rack::Lint.new(@app)
end

def assert_has_no_tag(name, attributes = {}, &block)

In this case, block is the html to evaluate
assert_has_no_tag, tag(:h1, :content => "yellow") { "

green

" }
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

def assert_has_tag(name, attributes = {}, &block)

In this case, block is the html to evaluate
assert_has_tag(:h1, :content => "yellow") { "

yellow

" }
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

def assert_match_in_file(pattern, file)

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

def assert_match_in_file(pattern, file)

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

def create_template(name, content, options={})

def create_template(name, content, options={})
  FileUtils.mkdir_p(File.dirname(__FILE__) + "/views")
  FileUtils.mkdir_p(File.dirname(__FILE__) + "/views/layouts")
  path  = "/views/#{name}"
  path += ".#{options.delete(:locale)}" if options[:locale].present?
  path += ".#{options[:format]}" if options[:format].present?
  path += ".erb" unless options[:format].to_s =~ /haml|rss|atom/
  path += ".builder" if options[:format].to_s =~ /rss|atom/
  file  = File.dirname(__FILE__) + path
  File.open(file, 'w') { |io| io.write content }
  file
end

def method_missing(name, *args, &block)

Delegate other missing methods to response.
def method_missing(name, *args, &block)
  if response && response.respond_to?(name)
    response.send(name, *args, &block)
  else
    super(name, *args, &block)
  end
rescue Rack::Test::Error # no response yet
  super(name, *args, &block)
end

def mock_app(base=Padrino::Application, &block)

the application.
given. Used in setup or individual spec methods to establish
Sets up a Sinatra::Base subclass defined with the block
def mock_app(base=Padrino::Application, &block)
  @app = Sinatra.new(base, &block)
end

def mock_model(klazz, options={})

mock_model("Business", :new_record? => true) =>
def mock_model(klazz, options={})
  options.reverse_merge!(:class => klazz, :new_record? => false, :id => 20, :errors => {})
  record = stub(options)
  record.stubs(:to_ary => [record])
  record
end

def remove_views

def remove_views
  FileUtils.rm_rf(File.dirname(__FILE__) + "/views")
end

def should_eventually(desc)

def should_eventually(desc)
  it("should eventually #{desc}") { skip("Should eventually #{desc}") }
end

def stop_time_for_test

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

def with_template(name, content, options={})

def with_template(name, content, options={})
  # Build a temp layout
  template = create_template(name, content, options)
  yield
ensure
  # Remove temp layout
  File.unlink(template) rescue nil
  remove_views
end