About testing HTTP::Engine-based app.

作者:   發佈於:  

So a few days ago I wrote a page on wikibook about HTTP::Engine , telling people why having a abstraction layer is a good thing. These days I'm in a superposition states of thoughts.

As I read through the documentation that I wrote I figured that it isn't obvious enough to see why it's easy to write tests with HTTP::Engine. First of all, it's still very verbose. I guess it'll be much better to write tests in with DSL.

Since I also code ruby / rails, here's a piece of testing code that tests rails app:

class HelloTest < ActionController::IntegrationTest
  test "hello should response" do
    get "/hello"
    assert_response :success

The get and assert_response there are both using an instance variable @response, but I don't really have to know it.

It would be very charming if I can be just put something like

get "/";
is_response("Hello World");

instead of that long verbose piece of code with all the initialization and configurations that HTTP::Engine needs. That's likely the minimum code required to describe the test. I guess there are already some similar works on CPAN that I can find as references.

It would also read nicely if the tests code is like:

get "/"
    should response "Hello World";
post "/blogs" with { content => "hello" }
    should be redirected_to qr[/blogs/\d+];

Where the should keyword implies an ok test.