Closed jarl-dk closed 12 years ago
Here is a patch just copy-paste and apply git am
From e4a5c5c53ceeefb2feb6c952d8502ff0bcdc587a Mon Sep 17 00:00:00 2001
From: Jarl Friis <jarl@softace.dk>
Date: Tue, 7 Feb 2012 13:48:55 +0100
Subject: [PATCH] Added support for HTTP HEAD method
---
lib/capybara/rack_test/driver.rb | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/lib/capybara/rack_test/driver.rb b/lib/capybara/rack_test/driver.rb
index 15a19b7..9ca8aca 100644
--- a/lib/capybara/rack_test/driver.rb
+++ b/lib/capybara/rack_test/driver.rb
@@ -76,5 +76,7 @@ class Capybara::RackTest::Driver < Capybara::Driver::Base
def post(*args, &block); browser.post(*args, &block); end
def put(*args, &block); browser.put(*args, &block); end
def delete(*args, &block); browser.delete(*args, &block); end
+ def head(*args, &block); browser.head(*args, &block); end
+
def header(key, value); browser.header(key, value); end
end
--
1.7.5.4
There you go.
That's not an official API at all. If you want to issue HEAD requests, use a library like rack-test, which was actually built for that. Capybara is an acceptance/integration testing library, it doesn't concern itself with low-level HTTP stuff.
Thanks for the reply ...
Does that mean you completely discourage any kind of use of cucumber-api-steps (https://github.com/jayzes/cucumber-api-steps) which exploits these areas of capybara?
cucumber-api-steps cannot support HEAD (like it does for GET, POST, DELETE, PUT, etc.) because of this one line missing in capybara.
Jarl
I'd never seen that library before. I wouldn't use it. Not only does it excessively use private APIs inside Capybara, which are liable to change and break in the future, but it's also fundamentally flawed in concept. I wrote a blog post a while ago about why I think that is: http://elabs.se/blog/15
I completely agree with you (regarding your blog), but your blog is addressing using cucumber with internally known ids and strings. What cucumber-api-steps is addressing is using cucumber for black box testing public (to the application users) HTTP APIs. You may think that
1) Cucumber is not the right tool for testing public http APIs. 2) Cucumber could be a tool for testing public http APIs, but using capybara to implement such cucumber steps (as in cucumber-api-steps) is not the right tool for implementing such steps.
I may agree with you on (2) as capybara is not intended to be used on HTTP protocol level, but merely on visual (browser) user experience level.
I still think that Cucumber is not so bad for testing public http API, though the features might be very technical, because they describe use cases on a HTTP level. But that is more a result of the fact that feature descriptions (when describing a http API) are very technical. As long as cucumber is used for black-box testing I find it not too bad, not for white-box testing as your examples do on your blog.
So as I understand you; If I would like to use cucumber for back box testing public APIs, I should implement cucumber steps using Rack::Test in stead of using capybara, right?
Anyway thanks for your comment and reason for closing this issue, I respect it.
When I use capybara in a cucumber step like this
Then it fails with
I'll attach a patch