« Playing with a Testing Library | Main | Complex and Rational are now built-in to 1.9 »

March 14, 2008

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83451c41c69e200e55130c73e8834

Listed below are links to weblogs that reference Source Code for that Testing Library:

Comments

expect(1 != 1) ?

Of course, now I look at your library and see- that's now how it's meant to be used at all.

I've put this up on github to watch what forks or releases develop around it.

git clone git://github.com/rsanheim/prag_dave_testing.git

Why not: expect { 1 == 1 }? Would also enable you to rescue Exceptions raised by the code.

Apeiros:

Having expect{ 1 == 1 } wouldn't give me access to the individual values when reporting errors--I can only change the meaning of == after the code being tested has run.

Dave

If SCRIPT_LINES__ is a hash, it will hold all sources parsed after it was set. See lib/debug.rb.

Nobo-san:

I thought about SCRIPT_LINES__, but decided against it because I'd need to ensure that the testing library got control early. I was also nervous that with a large application I'd always be loading in a lot of code that I may never use. Reopening the source is a fairly small overhead for something that happens infrequently.


Dave

The library also has a problem if an individual test is continued on multiple lines. The report line that begins "the code was:" is incorrect. Correctly identifying the code for the test is an interesting problem.

I've forked this from rsanheims github and worked a little bit on it. I've patched the negation issue und started to write some tests and a run helper for testing itself.

For example:

require 'test_helper'

testing "negated comparison with !=" do

result = run { expect(1) != 1 }
expect(result) =~ /but\s1\s==\s1/

end

You can get it here:

git://github.com/mhennemeyer/prag_dave_testing.git

Matthias

A few more notes:

I had a long night hacking all the features together i would like
this framework to have.

While its still very experimental and not well tested I
can frankly say that it turned out as really nice.

(got it? git clone git://github.com/mhennemeyer/prag_dave_testing.git)


This are the features:

1. Upgraded transactional behavior:

testing "Transactional db testing" do
Model.destroy_all
testing "Create a model" do
Model.create
expect(Model.count) == 1
end
expect(Model.count) == 0
end

(This works only with sqlite3 and if the test db file
is named db/test.sqlite3)

2. Macro style testing block reuse:

testing "macro" do
@var = 1
testing "var should eql 1" do
expect(@var) == 1
end
# the testing block can be reused:
# 'expect_' + testing block name joined with underscores
expect_var_should_eql_1
end

This macro thing, together with the transactional behavior
lets you evaluate a testing block in different environments.
The environments will not be touched by the testing code:


testing "macros should behave transactional too" do
@var = 1
testing "change var to 5" do
@var = 5
end
expect_change_var_to_5
expect(@var) == 1
end


3. Rails Integration Testing:

integration_test do
testing "I can use the Integration::Session methods" do
post "/models", 'model' => {}
expect(@resonse.response_code)
end
end
What do you think?

Matthias

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Now in Beta

  • Programming Ruby, 3rd Edition
    Third Edition, Covering Ruby 1.9, now available
My Photo

Pragmatic Stuff

Photos

  • www.flickr.com
    This is a Flickr badge showing public photos from pragdave tagged with pragdave_badge. Make your own badge here.

Site Search

  • Google Search

    The web
    PragDave