Project

azebiki

0.0
No commit activity in last 3 years
No release in over 3 years
A DSL for validating HTML
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
 Project Readme

azebiki

Azebiki provides a simple dsl for declaring CSS and XPATH matchers against a block of HTML content. It is built on top of Webrat matchers and nokogiri.

Usage

Given this block of HTML:

<html>
<head><title>Example</title></head>
<body>
<!--
<a href="http://incomment.com">In Comment</a>
-->
<div id='main' class="big">
  <p id="body">
    <table class='short table'>
      <thead>
        <tr>
          <th>First Column</th>
        </tr>
      </thead>
    </table>
  </p>
</div>

Given this Azebiki::Checker definition:

@html = Azebiki::Checker.new HTML do
  div '#main.big' do
    p '#body' do
      table do
        thead do
          tr do
            th content: 'First Column'
          end
        end
      end
    end
  end
end


@html.success?
  # => true

Or given this definition:

@html2 = Azebiki::Checker.new HTML do
  a href: 'http://incomment.com', content: 'In Comment'
end

@html2.success?
  # => false

c@html2.errors.inspect
  # => ['Content should have included <a href="http://incomment.com">In Comment</a>, but did not']

Or give it a custom error message:

@html3 = Azebiki::Checker.new HTML do
  a(href: 'http://incomment.com', content: 'In Comment').failure_message 'No tag :tag, SORRY!'
end

@html3.errors.inspect
  # => ['No tag <a href="http://incomment.com">In Comment</a>, SORRY!']

Install

Ruby 1.9.x only, 1.8.x not supported.

$ gem install azebiki

or

gem 'azebiki', group: :test