# Html parser / assertions in a model

**URL:** <https://www.ruby-forum.com/t/html-parser-assertions-in-a-model/180615>\
**Category:** Rails\
**Created:** [December 23, 2009, 10:23am UTC](https://www.ruby-forum.com/t/html-parser-assertions-in-a-model/180615 "2009-12-23T10:23:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roslind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c67d28/32.png) [@roslind](https://www.ruby-forum.com/u/roslind)\
**Post date:** [December 23, 2009, 10:23am UTC](https://www.ruby-forum.com/t/html-parser-assertions-in-a-model/180615/1 "2009-12-23T10:23:55Z")

</div>

I am using http.get in a model to parse html code returned from a Oracle  
server.

My first try was to use assertions (assert and assert\_select) to test  
and parse the html code. But I have problems including the methods in  
the model. Have tried both “include” and copy/paste to get assertion  
methods into my model. Works as a model, but I get load errors when I am  
using the model from a controller.

Does anyone known the correct way to get assertion methods merged into a  
model?

I am considering replace assertions with a html parser. Is there a  
recommented html parser for ruby?

---

<div class="post-metadata">

**Author:** ![roslind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c67d28/32.png) [@roslind](https://www.ruby-forum.com/u/roslind)\
**Post date:** [December 23, 2009, 11:02am UTC](https://www.ruby-forum.com/t/html-parser-assertions-in-a-model/180615/2 "2009-12-23T11:02:19Z")

</div>

Ok, it looks like I have to use both load and include to prevent load  
error when the model with assertions are used from a controller.

load ‘/usr/lib/ruby/1.8/test/unit/assertions.rb’  
class OlapDatabaseTrans \< ActiveRecord::Base  
include Test::Unit::Assertions  
…  
end

---

<div class="post-metadata">

**Author:** ![roslind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c67d28/32.png) [@roslind](https://www.ruby-forum.com/u/roslind)\
**Post date:** [December 23, 2009, 5:36pm UTC](https://www.ruby-forum.com/t/html-parser-assertions-in-a-model/180615/3 "2009-12-23T17:36:31Z")

</div>

Jan R. wrote:

> I am using http.get in a model to parse html code returned from a Oracle  
> server.
> 
> My first try was to use assertions (assert and assert\_select) to test  
> and parse the html code. But I have problems including the methods in  
> the model.

Why do you need assertions to parse HTML? Assertions are for tests, not  
generic parsing.

> Have tried both “include” and copy/paste to get assertion  
> methods into my model. Works as a model, but I get load errors when I am  
> using the model from a controller.

What do the errors say?

> Does anyone known the correct way to get assertion methods merged into a  
> model?
> 
> I am considering replace assertions with a html parser.

Good idea.

> Is there a  
> recommented html parser for ruby?

I think most people are using Nokogiri these days.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
