Permalink
Browse files

update the spec

  • Loading branch information...
1 parent bfe2ec4 commit 87ca64f833c6eb43dc5397eb820a0fb731239098 @mislav committed Jun 30, 2008
Showing with 25 additions and 24 deletions.
  1. +11 −8 curly.rb
  2. +14 −16 curly_spec.rb
View
@@ -59,14 +59,6 @@ def doc
Hpricot body_unicode
end
- def body_unicode
- body = body_str
- if encoding and encoding != 'utf-8'
- body = Iconv.conv('UTF-8', encoding, body)
- end
- body
- end
-
def encoding
return @encoding unless @encoding == false
@encoding = if body_str =~ /;\s*charset=([\w-]+)\s*['"]/
@@ -92,6 +84,17 @@ def elements
@node.search('input, button, select, textarea')
end
end
+
+ protected
+
+ def body_unicode
+ body = body_str
+ if encoding and encoding != 'utf-8'
+ body = Iconv.conv('UTF-8', encoding, body)
+ end
+ body
+ end
+
end
Hpricot::Doc.class_eval do
View
@@ -1,3 +1,5 @@
+require 'rubygems'
+require 'curly'
require 'spec'
describe Curly do
@@ -16,25 +18,21 @@
@curly.should_receive(:http_post).with(field_arg, field_arg)
@curly.post(:foo => 'bar', :baz => 'foo')
end
-end
-
-describe Curly, "class methods" do
- it "should post" do
- curly = mock('Curly')
- Curly.should_receive(:new).with('example.com').and_return(curly)
- curly.should_receive(:post).with(:foo => 'bar')
-
- Curly.post('example.com', :foo => 'bar')
- end
it "should get document" do
- curly = mock('Curly')
- Curly.should_receive(:new).with('example.com').and_return(curly)
- curly.should_receive(:get).with().and_return(true)
- curly.should_receive(:body_str).and_return("<html><body>You are being <a href=\"http://localhost:3000/login\">redirected</a>.</body></html>")
+ @curly.should_receive(:http_get).with().and_return(true)
+ @curly.stub!(:response_code).and_return(200)
+ @curly.stub!(:body_str).and_return(<<-HTML)
+ <html>
+ <body>You are being
+ <a href=\"http://localhost:3000/login\">redirected</a>.
+ </body>
+ </html>
+ HTML
- doc = Curly.get_document('example.com')
+ doc = @curly.get('http://example.com').doc
+ @curly.url.should == 'http://example.com'
doc.class.should == Hpricot::Doc
doc.at('a[@href]').inner_text.should == 'redirected'
end
-end
+end

0 comments on commit 87ca64f

Please sign in to comment.