Permalink
Browse files

making sure that the return of fopen() has a read() method (like a Fi…

…le instance would)
  • Loading branch information...
1 parent b74b565 commit 1607d9e0a07a9948131aaf00268ffce71acae4c3 @jmettraux jmettraux committed Apr 10, 2008
Showing with 20 additions and 2 deletions.
  1. +2 −0 CHANGELOG.txt
  2. +1 −0 CREDITS.txt
  3. +2 −0 README.txt
  4. +8 −2 lib/rufus/verbs.rb
  5. +7 −0 test/fopen_test.rb
View
@@ -4,6 +4,8 @@
== rufus-verbs - 0.9 released 2008/04/xx
+- bug #19408 : fopen now returns a instance that has a read() method.
+ problem pointed at by Scott Sproule.
- bug #19234 : cookie path checking broken - Fixed.
- todo #19202 : EndPoint.cookies now readable
- bug #19201 : :params not respected when specified in request
View
@@ -3,5 +3,6 @@
== Feedback
+Scott Sproule : fopen() result didn't have a read() method
Maik Schmidt : missing 'rufus-lru'
View
@@ -163,6 +163,8 @@ The Rufus::Verbs module provides as well a <tt>fopen</tt> method, which mostly f
But it follows redirections (has all the rufus-verbs features). It's provided for when targets are local files or URIs.
+This fopen() method makes sure to return an object that has a read() method (like a File instance has).
+
The tests may provide good intel as on 'rufus-verbs' usage as well : http://rufus.rubyforge.org/svn/trunk/verbs/test/
View
@@ -113,9 +113,15 @@ def fopen (uri, *args, &block)
if block
block.call r
return
- else
- return r
end
+
+ class << r
+ def read
+ self.body
+ end
+ end unless r.respond_to?(:read)
+
+ return r
end
raise "can't handle scheme '#{u.scheme}' for #{u.to_s}"
View
@@ -50,4 +50,11 @@ def test_0
assert_equal "{}", res.body.strip
end
end
+
+ def test_1
+
+ assert_kind_of String, fopen("CHANGELOG.txt").read
+ assert_kind_of String, fopen("file:CHANGELOG.txt").read
+ assert_kind_of String, fopen("http://localhost:7777/items").read
+ end
end

0 comments on commit 1607d9e

Please sign in to comment.