# Markup\_validity 1.0.0 Released

**URL:** <https://www.ruby-forum.com/t/markup-validity-1-0-0-released/170163>\
**Category:** Ruby\
**Created:** [June 13, 2009, 2:30am UTC](https://www.ruby-forum.com/t/markup-validity-1-0-0-released/170163 "2009-06-13T02:30:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 13, 2009, 2:30am UTC](https://www.ruby-forum.com/t/markup-validity-1-0-0-released/170163/1 "2009-06-13T02:30:11Z")

</div>

markup\_validity version 1.0.0 has been released!

- [http://github.com/tenderlove/markup\_validity](http://github.com/tenderlove/markup_validity)

MarkupValidity provides test/unit and rspec helpers for checking the  
validity  
of your documents. Shortcuts for verifying xhtml-transitional and  
xhtml-strict documents are provided as well. MarkupValidity will not  
only  
tell you when your document is invalid, but it will tell you what it  
_should_  
be.

Changes:

### 1.0.0 / 2009-06-11

- 1 major enhancement

## FEATURES/PROBLEMS:

- Make sure that markup\_validity is required _after_ test/unit, or mix  
MarkupValidity::Assertions in to your test class yourself.
- Currently AWESOME!

## SYNOPSIS:

### 

# test/unit example

require ‘test/unit’  
require ‘rubygems’  
require ‘markup\_validity’

class ValidHTML \< Test::Unit::TestCase  
def test\_i\_can\_has\_valid\_xhtml  
assert\_xhtml\_transitional xhtml\_document  
end  
end

### 

# rspec example

require ‘rubygems’  
require ‘markup\_validity’

describe “my XHTML document” do  
it “can has transitional xhtml” do  
xhtml\_document.should be\_xhtml\_transitional  
end  
end

### 

# Rails controller test example

require ‘test\_helper’  
require ‘markup\_validity’

class AwesomeControllerTest \< ActionController::TestCase  
test “valid markup” do  
get :new  
assert\_xhtml\_transitional @response.body  
end  
end

### 

# Here is an example error report

Error on line: 7:  
Element ‘p’: This element is not expected. Expected is one of ( a, br,  
span, bdo, object, applet, img, map, iframe, tt ).

6:

7:

8: Yo dawg, I heard you like p-tags  
9:

  
10: 

  
.  
 is not true.

## REQUIREMENTS:

- depends on nokogiri

## INSTALL:

- gem install markup\_validity

- [http://github.com/tenderlove/markup\_validity](http://github.com/tenderlove/markup_validity)

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 13, 2009, 7:05pm UTC](https://www.ruby-forum.com/t/markup-validity-1-0-0-released/170163/2 "2009-06-13T19:05:47Z")

</div>

> Changes:  
> MarkupValidity::Assertions in to your test class yourself.  
> class ValidHTML \< Test::Unit::TestCase  
> describe “my XHTML document” do  
> class AwesomeControllerTest \< ActionController::TestCase  
> Element ‘p’: This element is not expected. Expected is one of ( a, br, span, bdo, object, applet, img, map, iframe, tt ).
> 
> - depends on nokogiri
> 
> ## INSTALL:
> 
> - gem install markup\_validity
> 
> - [http://github.com/tenderlove/markup\_validity](http://github.com/tenderlove/markup_validity)
> 
> –  
> Aaron P.[http://tenderlovemaking.com/](http://tenderlovemaking.com/)

Thanks for this nice gem! I’ve started using it on a site, but I ran  
into problems with pages containing HTML entities. My workaround is  
described here:  
[http://chrononaut.net/2009/06/13/markup\_validity\_and\_entities.html](http://chrononaut.net/2009/06/13/markup_validity_and_entities.html)

-Bjørn

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 13, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/markup-validity-1-0-0-released/170163/3 "2009-06-13T19:11:39Z")

</div>

On Sun, Jun 14, 2009 at 02:05:07AM +0900, Bjørn Arild Mæland wrote:

> > Changes:  
> > MarkupValidity::Assertions in to your test class yourself.  
> > class ValidHTML \< Test::Unit::TestCase  
> > describe “my XHTML document” do  
> > class AwesomeControllerTest \< ActionController::TestCase  
> > Element ‘p’: This element is not expected. Expected is one of ( a, br, span, bdo, object, applet, img, map, iframe, tt ).
> 
> Thanks for this nice gem! I’ve started using it on a site, but I ran  
> into problems with pages containing HTML entities. My workaround is  
> described here: [http://chrononaut.net/2009/06/13/markup\_validity\_and\_entities.html](http://chrononaut.net/2009/06/13/markup_validity_and_entities.html)

Interesting. Thanks! I’ll see if I can fix this in the gem.

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 14, 2009, 12:48am UTC](https://www.ruby-forum.com/t/markup-validity-1-0-0-released/170163/4 "2009-06-14T00:48:21Z")

</div>

On 13 Jun 2009, at 02:29, Aaron P. wrote:

> _should_  
> be.

Sweet! Do you plan on adding HTML support as well? I personally don’t  
use XHTML but I do use HTML.

Regards,

Denis

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 13, 2009, 9:19pm UTC](https://www.ruby-forum.com/t/markup-validity-1-0-0-released/170163/5 "2009-06-13T21:19:18Z")

</div>

On Sun, Jun 14, 2009 at 02:05:07AM +0900, Bjørn Arild Mæland wrote:

> > Changes:  
> > MarkupValidity::Assertions in to your test class yourself.  
> > class ValidHTML \< Test::Unit::TestCase  
> > describe “my XHTML document” do  
> > class AwesomeControllerTest \< ActionController::TestCase  
> > Element ‘p’: This element is not expected. Expected is one of ( a, br, span, bdo, object, applet, img, map, iframe, tt ).
> 
> Thanks for this nice gem! I’ve started using it on a site, but I ran  
> into problems with pages containing HTML entities. My workaround is  
> described here: [http://chrononaut.net/2009/06/13/markup\_validity\_and\_entities.html](http://chrononaut.net/2009/06/13/markup_validity_and_entities.html)

You wouldn’t happen to have any XHTML that demonstrates the problem,  
would you? I’ve written tests referencing entities, and it doesn’t  
break for me.

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 15, 2009, 4:04pm UTC](https://www.ruby-forum.com/t/markup-validity-1-0-0-released/170163/6 "2009-06-15T16:04:59Z")

</div>

On Fri, Jun 12, 2009 at 8:29 PM, Aaron  
Patterson[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Changes:  
> MarkupValidity::Assertions in to your test class yourself.  
> class ValidHTML \< Test::Unit::TestCase  
> describe “my XHTML document” do  
> class AwesomeControllerTest \< ActionController::TestCase  
> Element ‘p’: This element is not expected. Expected is one of ( a, br, span, bdo, object, applet, img, map, iframe, tt ).
> 
> [http://tenderlovemaking.com/](http://tenderlovemaking.com/)  
> This is very cool, I’d like to integrate support for this into  
> Tarantula ([GitHub - relevance/tarantula: a big hairy fuzzy spider that crawls your site, wreaking havoc](http://github.com/relevance/tarantula/tree/master)). How  
> does this compare to tidy or the w3c validator?

thanks,  
Rob

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 15, 2009, 8:05pm UTC](https://www.ruby-forum.com/t/markup-validity-1-0-0-released/170163/7 "2009-06-15T20:05:42Z")

</div>

On Sun, Jun 14, 2009 at 07:47:34AM +0900, Denis D. wrote:

> > only  
> > tell you when your document is invalid, but it will tell you what it  
> > _should_  
> > be.
> 
> Sweet! Do you plan on adding HTML support as well? I personally don’t  
> use XHTML but I do use HTML.

Possibly. This project uses schemas to validate the XHTML. I could not  
find any schemas for HTML, and I don’t want to deal with DTD validation.

I might add something, but it isn’t really high on my priority list  
since I only use XHTML.

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 15, 2009, 7:20pm UTC](https://www.ruby-forum.com/t/markup-validity-1-0-0-released/170163/8 "2009-06-15T19:20:14Z")

</div>

On Mon, Jun 15, 2009 at 11:04:00PM +0900, Rob S. wrote:

> > be.
> > 
> > require ‘markup\_validity’  
> > require ‘markup\_validity’  
> > require ‘markup\_validity’
> > 
> > –  
> > Aaron P.  
> > [http://tenderlovemaking.com/](http://tenderlovemaking.com/)
> 
> This is very cool, I’d like to integrate support for this into  
> Tarantula ([GitHub - relevance/tarantula: a big hairy fuzzy spider that crawls your site, wreaking havoc](http://github.com/relevance/tarantula/tree/master)). How  
> does this compare to tidy or the w3c validator?

I encourage you to do a comparison, but this is what I found in my small  
tests:

MarkupValidity does not complain about missing doctypes (I should  
probably make it do that). MarkupValidity reports the same errors that  
the w3c validator does, but (IMHO) MarkupValidity’s error messages are  
slightly better. Plus you don’t need to hit the network when using  
MarkupValidity.

Tidy actually corrects your document, and I think sometimes the errors  
and warnings reported are unclear. For example, this document:

Hello

Give you these errors from tidy:

line 1 column 1 - Warning: missing \<!DOCTYPE\> declaration  
line 9 column 5 - Warning: inserting implicit

line 2 column 3 - Warning: inserting missing ‘title’ element  
line 5 column 5 - Warning: trimming empty

line 9 column 5 - Warning: trimming empty

5 warnings, 0 errors were found!

MarkupValidity says this:

Error on line: 2:  
Element ‘head’: Missing child element(s). Expected is one of ( script,  
style, meta, link, object, isindex, title, base ).

1:   
2:   
3:   
4:   
5:

Error on line: 6:  
Element ‘p’: This element is not expected. Expected is one of ( a, br,  
span, bdo, object, applet, img, map, iframe, tt ).

5:

6:

7: Hello  
8:

  
9: 

When I’m testing my documents, I don’t want them corrected. _I_ want to  
do the  
corrections. If the document needs to be corrected, then something is  
wrong.

I’m not sure about speed. I suspect that MarkupValidity will be faster  
since it is not doing any document corrections. But that doesn’t really  
matter to me. The error messages are what make my life easy.
