Wesley Chen wrote:
> Hi, All,
> Suppose I would like to write a method like.
>
> def test(boolean, message)
>        if boolean
>            puts message
>        else
>            puts boolean.left_value
>            puts boolean.right_value
>        end
> end
>
> Sometimes, I have to invoke the methods like:
> test(arra.include?(arrb), "arra includes arrb")
>
> test(arra.eql?(arrb), "arra equals to arrb")
>
> When the boolean is not true, I would like to get the info why they 
> don't match/equal/include.
>
>
> Any suggestion would be quite appreciated.
You should use Rspec and take a particular look at Spec::Matchers and 
the ability to create your own custom matchers.

In the case of your examples (include, eql),  it's already been done.

I just finished hooking this up to the watircraft console the other day.

C:\work\framework-examples\watircraft>script\console
Type 'irb START' at the prompt.
 >> irb START
 >> [1,2,3].should include(1)
=> true
 >> [1,2,3].should include(4)
Spec::Expectations::ExpectationNotMetError: expected [1, 2, 3] to include 4
        from 
c:/ruby-186-26/lib/ruby/gems/1.8/gems/rspec-1.2.2/lib/spec/expectat
ions.rb:57:in `fail_with'
        from 
c:/ruby-186-26/lib/ruby/gems/1.8/gems/rspec-1.2.2/lib/spec/expectat
ions/handler.rb:14:in `handle_matcher'
        from 
c:/ruby-186-26/lib/ruby/gems/1.8/gems/rspec-1.2.2/lib/spec/expectat
ions/extensions/object.rb:31:in `should'
        from (irb#1):2

This is a public service announcement brought to you by the WatirCraft 
Framework.

-- 
Bret Pettichord
CTO, WatirCraft LLC, www.watircraft.com
Lead Developer, Watir, www.watir.com
Blog, www.io.com/~wazmo/blog
Twitter, www.twitter.com/bpettichord

Watir Training: Portland/Beaverton April 16-17
www.watircraft.com/training


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to