[#329967] Ruby beginner Problem — Zayd Connor <devrubygem@...>

I get the following error message when running the code below:

18 messages 2009/03/01
[#329972] Re: Ruby beginner Problem — lasitha <lasitha.ranatunga@...> 2009/03/01

On Sun, Mar 1, 2009 at 10:46 AM, Zayd Connor <devrubygem@gmail.com> wrote:

[#329973] Re: Ruby beginner Problem — Zayd Abdullah <devrubygem@...> 2009/03/01

Thanks Lasitha that worked perfect. I'm slowly getting more comfortable with

[#329975] Re: Ruby beginner Problem — Justin Collins <justincollins@...> 2009/03/01

Zayd Abdullah wrote:

[#330022] Delegating class methods — abc <arcadiorubiogarcia@...>

Hi all,

17 messages 2009/03/01

[#330038] Rub 1.9: "inline rescue" doesn't work? — Iñaki Baz Castillo <ibc@...>

Hi, is there any explanation for the folowing big difference between the same

11 messages 2009/03/01

[#330067] passing a method as a paramter — Sarah Allen <sarah@...>

I'm probably missing some basic Ruby syntax, but I'm relatively new to

13 messages 2009/03/02

[#330097] Compiling a Ruby app — Sharagoz -- <blashyrkh1@...>

Hi

22 messages 2009/03/02
[#330193] Re: Compiling a Ruby app — David Masover <ninja@...> 2009/03/03

Sharagoz -- wrote:

[#330209] expanding environment variable — Daniel Schoch <trash@...>

Hi,

13 messages 2009/03/03
[#330212] Re: expanding environment variable — Dominik Honnef <dominikho@...> 2009/03/03

On [Tue, 03.03.2009 23:28], Daniel Schoch wrote:

[#330246] fixnum problem plz help — Guy Dols <guy_dols@...>

hy

14 messages 2009/03/03

[#330287] Any solutions to Ruby's inconsistencies? — "C. Dagnon" <c-soc-rubyforum@...>

Ruby has definite positives over Java and even other scripting

29 messages 2009/03/04
[#330292] Re: Any solutions to Ruby's inconsistencies? — Yossef Mendelssohn <ymendel@...> 2009/03/04

On Mar 4, 10:02m, "C. Dagnon" <c-soc-rubyfo...@dagnon.net> wrote:

[#330322] Re: Any solutions to Ruby's inconsistencies? — "C. Dagnon" <c-soc-rubyforum@...> 2009/03/04

Yossef Mendelssohn wrote:

[#330388] Re: Any solutions to Ruby's inconsistencies? — Yossef Mendelssohn <ymendel@...> 2009/03/05

On Mar 4, 3:32m, "C. Dagnon" <c-soc-rubyfo...@dagnon.net> wrote:

[#330401] Re: Any solutions to Ruby's inconsistencies? — "C. Dagnon" <c-soc-rubyforum@...> 2009/03/05

Yossef Mendelssohn wrote:

[#330363] Ruby -Question about Framewroks — jazzez ravi <jazzezravi@...>

Hi All,

12 messages 2009/03/05

[#330383] add a new line after, w/txtfile thats comma delimited — Mmcolli00 Mom <mmc_collins@...>

How do you add a new line after you have split a text file with

16 messages 2009/03/05

[#330387] Ruby - Imperative Language Features? — Mike Stephens <rubfor@...>

The Wikipedia entry for Ruby says:

12 messages 2009/03/05

[#330601] how to un-ragged a 2D array? — Phlip <phlip2005@...>

Rubies:

12 messages 2009/03/07

[#330630] Can I access or find a object from it's instance variable? — Aki Wakabayashi <zzyzx2001@...>

Hello.

14 messages 2009/03/08

[#330638] OO style tutorials? — Paul Archer <paul@...>

I'm pretty new to Ruby, and while I've read (and mostly get) several books

20 messages 2009/03/08

[#330665] What are the 5 most innovative ruby projects/libraries? — Camille Roux <roux.camille@...>

Hi,

27 messages 2009/03/08

[#330701] Ruby OpenGL Gears example that uses shiny and velvet GLSL shaders — Michael Brooks <michael.brooks@...>

Hello:

11 messages 2009/03/09
[#330722] Re: Ruby OpenGL Gears example that uses shiny and velvet GLSL shaders — Matthias Reitinger <reitinge@...> 2009/03/09

Michael Brooks wrote:

[#330718] MacRuby 0.4 — Laurent Sansonetti <laurent.sansonetti@...>

Hi,

17 messages 2009/03/09

[#330954] How Many hours in A day — Zayd Connor <devrubygem@...>

I have a very simple ? How many hours in a day should someone who is new

17 messages 2009/03/11

[#330990] How to read a charecters from and image? — rails and rails only <mjayakumar2k6@...>

16 messages 2009/03/12
[#330993] Re: How to read a charecters from and image? — pjb@... (Pascal J. Bourguignon) 2009/03/12

rails and rails only <mjayakumar2k6@yahoo.com> writes:

[#330994] Re: How to read a charecters from and image? — Redd Vinylene <reddvinylene@...> 2009/03/12

Stop that! He's probably looking to crack CAPTCHAs.

[#331216] does IO.read block? — Michael Malone <michael.malone@...>

Hi All,

16 messages 2009/03/15
[#331218] Re: does IO.read block? — Robert Klemme <shortcutter@...> 2009/03/15

On 15.03.2009 23:02, Michael Malone wrote:

[#331307] Trying to install Fox, FXRuby, and IFMapper on Mac OS X — kpkilburn@...

I can't seem to find a specific answer on this...

12 messages 2009/03/16

[#331326] Dynamically extending modules once they have been included — pete@...373.net

It doesn't seem possible to dynamically extend modules once they have

14 messages 2009/03/17

[#331371] free RAM problem — Edouard Dantes <edrd.dantes@...>

Hi,

14 messages 2009/03/17

[#331411] hpricot 0.7 — _why <why@...>

Please enjoy a succulent, new Hpricot. A bit faster, some Ruby 1.9

25 messages 2009/03/17

[#331476] Complex sort of matrix possible, e.g. like Excel? — RichardOnRails <RichardDummyMailbox58407@...>

Hi,

18 messages 2009/03/18

[#331478] REXML get specific element — Pierre Pat <theyojimbo@...>

All,

15 messages 2009/03/18

[#331568] Modulo ? — Zayd Connor <devrubygem@...>

Maybe i need to get some sleep, but can someone explain how modulos

16 messages 2009/03/19

[#331628] Passing a named function instead of a code block? — Paul Jungwirth <once@9stmaryrd.com>

Hello,

13 messages 2009/03/20
[#331630] Re: Passing a named function instead of a code block? — Matthias Reitinger <reitinge@...> 2009/03/20

Paul Jungwirth wrote:

[#331760] Ruby GUI Libs — ntwrkd <ntwrkd@...>

Is there a nicer GUI framework for Ruby other than RubyGoo?

12 messages 2009/03/21

[#331793] Newbie needs help with first project — Daniel Dale <dochappy@...>

I was told about Ruby several weeks ago and started my journey lol. I've

15 messages 2009/03/22
[#331796] Re: Newbie needs help with first project — Stefan Codrescu <fixxie.wits@...> 2009/03/22

On Sun, Mar 22, 2009 at 9:32 AM, Daniel Dale <dochappy@gmail.com> wrote:

[#331803] convert PNG to hex — jeljer te Wies <jeljer@...>

Hey people! ..

20 messages 2009/03/22

[#331899] Test::Unit - same test, different "args" — "Luke St.Clair" <secureboot@...>

I need to run the same unit test case more than 10 times (around 150

14 messages 2009/03/23

[#331924] Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby — Felipe Coury <felipe.coury@...>

Hello there!

20 messages 2009/03/24
[#331931] Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby — gcristelli <giovanni.cristelli@...> 2009/03/24

On 24 Mar, 04:21, Felipe Coury <felipe.co...@gmail.com> wrote:

[#331938] Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby — Felipe Coury <felipe.coury@...> 2009/03/24

Giovanni / Rob,

[#331940] Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby — Felipe Coury <felipe.coury@...> 2009/03/24

Some more discoveries...

[#331941] Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby — Felipe Coury <felipe.coury@...> 2009/03/24

Just as a FYI, it works!!!

[#331948] Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby — Rob Biedenharn <Rob@...> 2009/03/24

On Mar 24, 2009, at 2:35 AM, Felipe Coury wrote:

[#365126] Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby — Joshua Mckinney <joshmckin@...> 2010/07/01

Having no luck with this. Getting the following error when generating

[#331930] tagz-5.0.0 — "ara.t.howard" <ara.t.howard@...>

44 messages 2009/03/24
[#332078] Re: [ANN] tagz-5.0.0 — "Andrew S. Townley" <ast@...> 2009/03/25

Hi Ara,

[#332095] Re: [ANN] tagz-5.0.0 — "ara.t.howard" <ara.t.howard@...> 2009/03/25

[#332141] Re: [ANN] tagz-5.0.0 — "Andrew S. Townley" <ast@...> 2009/03/25

On Wed, 2009-03-25 at 23:23 +0900, ara.t.howard wrote:

[#332160] Re: [ANN] tagz-5.0.0 — "ara.t.howard" <ara.t.howard@...> 2009/03/26

[#331971] : HOWTO start irb on a different object — Jeremy Henty <onepoint@...>

I wanted to have irb start its session on an object other than the

10 messages 2009/03/24

[#332023] ruby and 2D graphics — Philip Müller <me@...>

Hi everybody,

22 messages 2009/03/24
[#332029] Re: ruby and 2D graphics — Philip Müller <me@...> 2009/03/24

On Tue, 24 Mar 2009 21:08:34 +0100, Peter Zotov <whitequark@whitequark.ru>

[#332112] Parsing xml — Arun Kumar <arunkumar@...>

Hi,

24 messages 2009/03/25
[#332115] Re: Parsing xml — "Peter Zotov" <whitequark@...> 2009/03/25

Quoting "Arun Kumar" <arunkumar@innovaturelabs.com>:

[#332116] Re: Parsing xml — Arun Kumar <arunkumar@...> 2009/03/25

Peter Zotov wrote:

[#332118] Re: Parsing xml — "Peter Zotov" <whitequark@...> 2009/03/25

Quoting "Arun Kumar" <arunkumar@innovaturelabs.com>:

[#332206] Update latest Ruby Version 1.9 on Mac OSX — Thomas Khaipi <sayakyi@...>

Dear All,

14 messages 2009/03/26

[#332357] testy.rb - ruby testing that's mad at the world — "ara.t.howard" <ara.t.howard@...>

55 messages 2009/03/28
[#332418] Re: testy.rb - ruby testing that's mad at the world — Brian Candler <b.candler@...> 2009/03/29

Ara Howard wrote:

[#332405] Ruby 1.9, OS X, command line: negative string size (ArgumentError) — Bartlomiej Owczarek <bartlomiej@...>

Hello,

13 messages 2009/03/29

[#332474] Symbols garbage collector in Ruby1.9, fixed? — Iñaki Baz Castillo <ibc@...>

Hi, in Ruby 1.8 there is an issue when adding more and more Symbols

27 messages 2009/03/30

[#332520] When to use instance variables @ — Steve Dogers <stevedogers@...>

Hi, I have a couple questions about instance variables in Ruby.

20 messages 2009/03/30

[#332547] Localmemcache-0.2.0: The beauty of memcached. For local data. Blazingly fast. — "Sven C. Koehler" <schween@...>

Hi,

13 messages 2009/03/30

[#332624] Move over, Phusion, here comes the *real* Enterprise Edition! — Jg W Mittag <JoergWMittag+Usenet@...>

Hi!

20 messages 2009/03/31

[ANN] assert2-0.4.6 provides assert_xhtml, an alternative to assert_select

From: Phlip <phlip2005@...>
Date: 2009-03-26 12:51:48 UTC
List: ruby-talk #332186
Rubyists:

Consider the following monstrosity, coded using assert_select:

   assert_select "div#logo_box img[src=/0000/0001/logo.gif][alt=My Company]"

Now, behold it rewritten to use assert_xhtml:

   assert_xhtml do
     div.logo_box! do
       img :src => /logo.gif$/,
           :alt => 'My Company'
     end
   end

That sample contains more Ruby; it's not just one big string.

Still not convinced? Oh, I forgot the <a> around the <img>! Try this:

   assert_xhtml do
     div.logo_box! do
       a :href => '/' do
         img :src => /logo.gif$/, :alt => 'My Company'
       end
     end
   end

And we had an issue with the small logo sneaking into the logo_box once.
Let's exclude it:

   assert_xhtml do
     div.logo_box do
       a :href => '/' do
         img :src => /logo.gif$/, :alt => 'My Company'
       end
       without!{ img :src => /mini_logo.gif/ }
     end
   end

Imagine adding all that to assert_select - it would get much harder to read, and 
more complex. assert_xhtml uses Nokogiri::HTML::Builder notation, so anything it 
can build, you can query.

Version 0.4.6 adds all the following features. To begin, enter:

   gem install nokogiri assert2

== require 'assert2/xhtml' ==

All assert{ 2.0 } dependencies are optional. If you have Nokogiri
(>=1.2.2), you can test Rails views like this:

      user = users(:Moses)
      get :edit_user, :id =>  user.id

      assert_xhtml do

        form :action =>  '/users' do
          fieldset do
            legend 'Personal Information'
            label 'First name'
            input :type =>  'text',
                  :name =>  'user[first_name]'
                  :value =>  user.first_name
          end
        end

      end

That's a Rails functional test on a form. The assertion expects the form
to target the given action, and contain a fieldset, a legend, a label, and
a populated text input field. The assertion forgives any other details,
such as intervening structural tags, excess spaces, or extra attributes;
and complains if any required detail is missing, out of order, or ill-formed.

The DSL inside that block is Nokogiri::HTML::Builder notation. Generally
speaking, anything Nokogiri can build, you can specify.

=== arguments ===

Call assert_xhtml(my_xml){} to interrogate your XML. When called without
an argument, the method reads @response.body.

=== without! ===

Every assert* has a matching deny* method. assert_xhtml recognizes the
special element without! as a request to fail if the given elements
do indeed appear in your output:

     get :info, :record_id => record.id
     assert_xhtml do
       div :class => :content do
         without!{ div :class => :download }
       end
     end

That assertion will fail if the outer <div class='content'> tag does not
exist, or if any inner <div class='download'> does exist.

The without! element respects your document layout. This assertion
passes...

     assert_xhtml SAMPLE_LIST do
       ul{ li{ ul{ li 'Sales report'
           without!{ li 'All Sales report criteria' } } } }
     end

...even though the target document contains an <li>All Sales report
criteria</li>:

     <ul style='font-size: 18'>
       <li>model
         <ul>
           <li>Billings report</li>
           <li>Sales report</li>
           <li>Billings criteria</li>
           <li>Common system</li>
         </ul>
       </li>
       <li>controller
         <ul>
           <li>All Sales report criteria</li>
           <li>All Billings reports</li>
         </ul>
       </li>
     </ul>

The two <li> elements appear in different <ul> lists, so the assertion
does not associate them.

The committee does not yet know what without!{ without!{} } does, so please
do not rely on its current behavior, whatever that is!

=== escapes ===

Certain elements, such as <select> and <id>, have the same names as internal
methods. If you experience a bizarre error message, such as "wrong argument
type Hash (expected Array)", add a ! to the end of the element, like this:

     assert_xhtml do
       h2 'Sites'

       select! :id => 'sites',
               :name => 'sites[]',
               :multiple => :multiple,
               :size => SaleController::LIST_SIZE
     end

=== text ===

An element such as h3{ 'text' } will match <h3> text </h3>, with leading or
trailing blanks, but it won't match <h3><span>text</span></h3>. This rule
prevents runaway matches between high- and low-level elements.

The example for the next section illustrates how to mix text and attribute
specifications on the same element.

A text specification may be a /regexp/.

=== :xpath!=> ===

assert_xhtml works by throwing away structural information. If you need
more control over your structure, use an :xpath! attribute to apply raw
XPath specifications to your target elements.

This assertion detect the rather pedestrian fact that your <title>
element remains inside your <html><head> block - and it did not
escape and rampage off to somewhere else:

     assert_xhtml do
       title :xpath! => 'parent::head/parent::html' do
         text 'Chamber of Commerce - Info - Hope Orphanage'
       end
     end

Note the XPath evaluates as a predicate of the target <title>, so its parent 
axis lists the familiar elements in reverse.

That code also shows the 'text' directive, inserting text contents directly
into the enclosing element. A future version of Nokogiri will allow the
element's first argument to specify its text.

An :xpath! of a number evaluates to the 1-based index of an item in its
parent. This assertion forces list items to appear in the correct order:

     assert_xhtml do
       ul :style => 'font-size: 18' do
         li 'model' do
           li(:xpath! => 1){ text 'Sales report'  }
           li(:xpath! => 2){ text 'Billings report' }
           li(:xpath! => 3){ text 'Billings criteria' }
         end
       end
     end

=== :verbose! => true ===

Sometimes when an assertion fails, you can't tell why. To see each
context the assertion considers, add :verbose! => true to the lowest
element you know works, and run the tests:

     assert_xhtml SAMPLE_FORM do
       fieldset do
         li :verbose! => true do
           label 'First name', :for => :user_first_name
         end
       end
     end

The verbose option works as "spew", not as a diagnostic, and it reports
each considered element's contents.

Because XPath evaluates the <label>, in our example, before the <li>, you
might need to comment the <label> out to see a successful spew on the <li>.

=== scope ===

assert_xhtml{} yields its block to Nokogiri::HTML::Builder, which turns
every method call into an HTML element. This freedom comes at a price -
you can't easily call your own methods!

Use this scope trick to pass your outer scope into the specification:

      get :edit_user, :id => users(:Moses).id
      scope = self

      assert_xhtml do
        form :action => '/users' do
          input :value => scope.users(:Moses).first_name
        end
      end

Notice we could improve that test by declaring a variable,
user = users(:Moses), in the outer scope, and simply passing
the user variable itself into the specification.

=== :class=> ===

The :class attribute is magic. This assertion passes...

     assert_xhtml SAMPLE_LIST do
       ul :class => :kalika do
         li 'Billings report'
       end
     end

...despite the actual HTML contains <ul class='kalika goddess'>. This feature
simulates the CSS Selector notation that matches classes by their cascading
effects.

=== class & ID shortcuts ===

Nokogiri expands div.rad.thing! to <div class='rad' id='thing'/>. That
means you don't need to write div :class => 'rad', :id => 'thing' (or
ul :class => :kalika). You can then put other arguments after the shortcut,
and the <div> in our example receives them, too.

=== diagnostic message ===

When this assertion fails, it attempts to print out...

  - your reference elements, rendered as HTML
  - each "near-miss" region of your sample HTML

The next version will feature much better diagnostics. Until they work, if these 
diagnostics are not sufficient, put :verbose! on the lowest element you think 
works, and comment out its contents...

=== RSpec ===

The matching "specification", in RSpec language, is be_html_with{}.
Its syntax and behavior are the same:

   it 'should have a cute form' do
     render '/users/new'

     response.body.should be_html_with{
       form :action => '/users' do
         fieldset do
           legend 'Personal Information'
           label 'First nome'
           input :type => 'text', :name => 'user[first_name]'
         end
       end
     }
   end

Good hunting!

-- 
   Phlip

In This Thread

Prev Next