[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[Ann] Verify, a very basic testing tool.

Robert Dober

4/3/2009 8:02:00 PM

Hi List

The Verify tool is a KISS verification and test tool, it is inspired
by Ara T. Howard's testy.rb.
Ara however has still implemented a BDD framework, the purpose of
Verify is to provide a Ruby Programmer
with a very simple yet effective tool to test her assumptions about code.

Verify was motivated by a reply to Ara's release post made by Phlip.
Phlip has made an excellent point about assert.
And that very often that is (almost?) all what is needed.
The Verify tool tries to implement exactly that idea and is the
simplest possible tool to do the job (for me).

Verify has the following goals

* Almost nothing to learn, one wrapper method and three test
methods with almost no parameters all save one
optional.
# At the end a resume of the verifications with an error message
for each failed verification
# will be printed to stderr or a mocking object.
# Strings and Arrays are fine for that purpose, as the reporter
uses #<< exclusively.


* No metaprogramming, no at_exit hook, execution of the
verification inside a wrapper object, no global namespace pollution,
except the Verify method.

* Wrapper behavior inference to the testee is limited to #verify,
#verify_not and #verify_exceptions.

* Very simple output

* "Last Line Says It All" feature "================" --> all tests
ok, "***************" --> not all tests ok.

USAGE EXAMPLES:

require 'verify'

Verify do
verify do 42 end
verify_not do nil end
verify_exceptions NameError do abcdefghijk end
end

Verify "that the universe is ok" do
verify "this only shows in error reports" do
1 / 0
end
end

LICENCE:
BSD

Enjoy
Robert

Ah yeah BTW if someone really wants to download this ;)

http://rubyforge.org/frs/?group_id=3824&releas...


--
There are some people who begin the Zoo at the beginning, called
WAYIN, and walk as quickly as they can past every cage until they get
to the one called WAYOUT, but the nicest people go straight to the
animal they love the most, and stay there. ~ A.A. Milne (from
Winnie-the-Pooh)

33 Answers

Ryan Davis

4/3/2009 8:56:00 PM

0


On Apr 3, 2009, at 13:02 , Robert Dober wrote:

> Verify do
> verify do 42 end
> verify_not do nil end
> verify_exceptions NameError do abcdefghijk end
> end

refute: same length as verify!
raises: ditto!
(assert: I like assert)


Robert Dober

4/3/2009 10:16:00 PM

0

On Fri, Apr 3, 2009 at 10:56 PM, Ryan Davis <ryand-ruby@zenspider.com> wrot=
e:
>
> On Apr 3, 2009, at 13:02 , Robert Dober wrote:
>
>> =A0 =A0 =A0 Verify do
>> =A0 =A0 =A0 =A0 verify do 42 end
>> =A0 =A0 =A0 =A0 verify_not do nil end
>> =A0 =A0 =A0 =A0 verify_exceptions NameError do abcdefghijk end
>> =A0 =A0 =A0 end
>
> refute: same length as verify!
Never heard of that word before, just checked it on Websters, thanx
Ryan great idea.
> raises: ditto!
> (assert: I like assert)
So do I, but assert is normally inserted into production code, and
Verify is still a testing tool, but you know it is so easy to alias
the methods in the anonymous module that creates the wrapper object in
the Verify method ;).
Cheers
Robert
>
>
>



--=20
There are some people who begin the Zoo at the beginning, called
WAYIN, and walk as quickly as they can past every cage until they get
to the one called WAYOUT, but the nicest people go straight to the
animal they love the most, and stay there. ~ A.A. Milne (from
Winnie-the-Pooh)

Robert Dober

4/3/2009 10:45:00 PM

0

Thanks to Ryan I have changed #verify_not to #refute.
But not #alert and #raises because I am afraid that these method names
might shadow too much testee code :(.

Cheers
Robert

http://rubyforge.org/frs/?gro... (verify-0.1a)

Robert Dober

4/3/2009 10:48:00 PM

0

oops I forgot something important
Verify is Ruby1.9 only, do not look back ;).
R.

Tom Cloyd

4/3/2009 11:15:00 PM

0

Robert Dober wrote:
> oops I forgot something important
> Verify is Ruby1.9 only, do not look back ;).
> R.
>
>
>
Damn. I love this sudden burst of creativity around the topic of
testing. A Good Thing. Would love to try this new thing of yours.
Already successfully using Ara's.

But this 1.9 nonsense frustrates me. Much as I want to dive in (it's
installed and ready to go), I simply don't have time to move code I
depend upon into an environment where I don't know whether it will fly
or not, or whether it will splat after 3 days of investment and use. I
wish there was somewhere I could go to find out what gems run with 1.9
and what do not. But, that seems not to be the ruby way. That's plain
crazy, say I.

Maybe in a year it'll be different. Meanwhile, 1.87 works for me. Sad.

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Phlip

4/4/2009 4:38:00 AM

0

Tom Cloyd wrote:

> Damn. I love this sudden burst of creativity around the topic of
> testing. A Good Thing.

Oookay. Here's a sneak preview of assert{ 2.0 } 0.4.8.

You know how Ajax works by generating JavaScript, and slinging it at your web
browser? And you know how Rails purportedly tests it with "assert_rjs"? Here's a
sample:

assert_rjs :replace_html, "advanced_filter", ""

Too cute, right?

Wrong! That expands to nothing but a big Regexp, like
/Element.update.*advanced_filter/. So a payload of "advanced_filter", or even a
subsequent Element.update('advanced_filter'), could fool it.

Further, at work we do a lot of in-house Ajax, so we are at liberty to render
entire partials at whim. We require our teeming minions to use only Firefox. But
all assert_rjs does with its third argument is drop it into assert_match. That
is not powerful enough to constrain our apps!

Just now while writing this post, I got Aaron Paterson's rKelly working in an
assert_rjs clone. rKelly uses racc to parse and evaluate JavaScript. This
matches our goal of _unit_ testing soft targets. Watir, Selenium, etc. are all
great, and they introduced a generation to testing in general. Buuuuuut they
work thru the browser. We are not inventing Ajax itself; we just need to
accurately spot-check that our own data go into the correct slots in our
JavaScript payloads.

So here's a test that simulates a Rails functional test with xhr :get :

@response = OpenStruct.new(:body => "Element.update(\"label_7\", \"<input
checked=\\\"checked\\\" id=\\\"Top_Ranking\\\"
name=\\\"Top_Ranking\\\" type=\\\"checkbox\\\" value=\\\"Y\\\"
\\/>I want a pet &lt; than a chihuahua<input id=\\\"cross_sale_1\\\"
name=\\\"cross_sale_1\\\" type=\\\"hidden\\\" value=\\\"7\\\" \\/>\");")

assert_rjs :replace_html, :label_7

K, so far that looks like the original assert_rjs. But under the hood, it
actually lexed the Element.update() call:

ast.pointcut('Element.update()').matches.each do |updater|
updater.grep(RKelly::Nodes::ArgumentsNode).each do |thang|
div_id, html = thang.value

if target and html
div_id = eval(div_id.value)
html = eval(html.value)
if div_id == target.to_s
assert_match matcher, html

(Open question to Aaron - is that the best way to run the query?)

The test actually determines we really got hold of the Element.update('label_7',
....). No other JavaScript line will match.

Here's the assertions to match the text payload:

assert_rjs :replace_html, :label_7, /Top_Ranking/
assert_rjs :replace_html, :label_7, /pet &lt; than a chihuahua/

Ho hum; so far assert_rjs Classic could have done all that. But...

Because I have an exact string, not a rough match, I can now treat it as pure
HTML, and I can drop it into the mighty assert_xhtml()! Now the assertion looks
like this:

assert_rjs :replace_html, :label_7 do
input.Top_Ranking! :type => :checked, :value => :Y
input.cross_sale_1, :type => :hidden, :value => 7
end

From here, no matter how complex that rendered partial, the assertion can keep
up with it, and help make it safe to refactor and upgrade.

BTW Verify and Testy can get on board if they A> import Test::Unit::Assertions
(like certain other test rigs we could mention should), and B> implement
flunk(). Both of those are all a custom assertion should ever need...

--
Phlip
http://www.zerop...

Robert Dober

4/4/2009 9:00:00 AM

0

On Sat, Apr 4, 2009 at 1:14 AM, Tom Cloyd <tomcloyd@comcast.net> wrote:
> Robert Dober wrote:

> But this 1.9 nonsense frustrates me. Much as I want to dive in (it's
> installed and ready to go), I simply don't have time to move code I depend
> upon into an environment where I don't know whether it will fly or not, or
> whether it will splat after 3 days of investment and use. I wish there was
> somewhere I could go to find out what gems run with 1.9 and what do not.
> But, that seems not to be the ruby way. That's plain crazy, say I.
Maybe, indeed I had the very strong intention to write Lab419 to make
my code Ruby1.9 and 1.8 compatible. Too much work? Not enough time? I
dunno, finally I got tired of it and wanted my closure based Verify to
work. This goes without pain in 1.9.
But I agree with what you say.
<snip>
R.
--
There are some people who begin the Zoo at the beginning, called
WAYIN, and walk as quickly as they can past every cage until they get
to the one called WAYOUT, but the nicest people go straight to the
animal they love the most, and stay there. ~ A.A. Milne (from
Winnie-the-Pooh)

Jens Wille

4/4/2009 9:03:00 AM

0

hi tom!

Tom Cloyd [2009-04-04 01:14]:
> I wish there was somewhere I could go to find out what gems run
> with 1.9 and what do not.
there is: <http://isitruby1...

cheers
jens

chris

4/4/2009 12:19:00 PM

0

Without proper announce, I'd like to show that I had something similar
for quite some time now, as part of my knock project:

% cat t.tb
require 'knock'
include Knock

testing "various expectances" do
expect(42) { 6 * 7 }
expect(nil) { nil }
expect(NameError) { abcdefghijk }

is 42, 6*7
ok 42 == 6*7
end

testing "that the universe is ok" do
testing "this only shows in error reports" do
1 / 0
end
end

% ruby t.rb
ok - various expectances - expecting value 42
ok - various expectances - expecting value nil
ok - various expectances - expecting exception NameError
ok - various expectances
ok - various expectances
not ok - /Users/chris/mess/current/t.rb:14 - that the universe is ok - this only shows in error reports - RAISED: divided by 0
# /Users/chris/mess/current/t.rb:15:in `/'
# /Users/chris/mess/current/t.rb:15
# /Users/chris/mess/current/t.rb:14
# /Users/chris/mess/current/t.rb:13

% ruby t.rb | kn-agg
not ok - 6 tests, 1 failed (83.3333% succeeded)

The expect API is a rip-off from http://expectations.ruby...,
but simplified to its core:

% wc -l knock.rb kn-agg
61 knock.rb
10 kn-agg

Sources can be found at
http://github.com/chneukirchen/knock/t...

There are implementations for C, Ruby, sh/bash/zsh, and it is trivial
to implement in any language that supports "puts" in some way.
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

Phlip

4/4/2009 12:45:00 PM

0

Robert Dober wrote:

> Maybe, indeed I had the very strong intention to write Lab419 to make
> my code Ruby1.9 and 1.8 compatible. Too much work? Not enough time? I
> dunno, finally I got tired of it and wanted my closure based Verify to
> work. This goes without pain in 1.9.
> But I agree with what you say.

Here's a snip of my Rakefile, tuned for TDD:

task :default do
sh 'ruby186 test/assert2_rjs_suite.rb'
sh 'ruby187 test/assert2_rjs_suite.rb'
sh 'ruby190 test/assert2_rjs_suite.rb'
sh 'ruby191 test/assert2_rjs_suite.rb'

sh 'ruby186 test/rubynode_reflector_suite.rb'
sh 'ruby187 test/rubynode_reflector_suite.rb'
sh 'ruby190 test/ripper_reflector_suite.rb'
sh 'ruby191 test/ripper_reflector_suite.rb'

sh 'ruby186 test/assert2_suite.rb'
sh 'ruby187 test/assert2_suite.rb'
sh 'ruby190 test/assert2_suite.rb'
sh 'ruby191 test/assert2_suite.rb'
...

I'm implying that, after every couple of edits, I run every test in every Ruby.
This system works great to avoid the "Too much work? Not enough time?" quandary.

Actually, it doesn't. I lied. Most of those are commented out. I cannot figure
out how to get my peesashit Ubuntu to install all of those at the same time, and
I otherwise don't want to give up on the package manager. Debian's packaging for
Ruby sure sucks, huh?

--
Phlip