The APE is a tool to test AtomPub servers, as defined into RFC5023 Saddly, the APE itself isn't tested. Here are some though on how that could be fixed.
We should test every test_*
methods. Let's take test_entry_posts(entry_collection)
as an example.
This methods checks that (more or less) :
After a POST :-
After a PUT :-
After a DELETE :-
The methods also set a lot of message: good
, info
, warning
, depending on the result of the test. Those messages should also be tested.
We need an AtomPub server whose behaviour could be modified on the fly. I see two possible solution to achieve that: -
Implement a dumb AtomPub server using any lightweight Ruby web framework like Camping or Rack. However it may result in slow test execution.
Mock it. Create an object responding to all the HTTP verbs. To achieve that, we'd need to be able to pass an object
to APE which would be used to perform HTTP operations. Ape::Invoker
?
Here is some code to illustrate the general idea :
describe 'The APE' do
describe 'when testing entry posting' do
before(:each) do
@server = AtomPubServerMock.new
@ape = APE.new
end
it "should set an error if the request isn't successful" do
@server.unsuccessful_post_request!
@ape.should_receive(:error).with("Can't POST new entry: 500")
@ape.check(@server)
end
# More sexy
it "should set an error if the request isn't successful" do
ape_test(:unsuccessful_post_request!) do
@ape.should_receive(:error).with("Can't POST new entry: 500")
end
end
it 'should set an error if the returned entry is not well-formed' do
@server.return_malformed_entry!
@ape.should_receive(:error).with('New entry is not well-formed: foo')
@ape.check(@server)
end
describe 'Location header testing' do
it "should set an error if the Location header isn't present in response" do
ape_test(:no_location_header!) do
@ape.should_receive(:error).with("No Location header upon POST creation")
end
end
it "should set an 'ok message' if the Location header is present" do
ape_test do
@ape.should_receive(:good).with("Posting of new entry to the Entries collection " +
"reported success, Location: #{@server.location}")
end
end
end
end
end
Simon Rozet, 2008-01-28