From 3f61f48025272b7542d7d4862c01582cbbf9a80e Mon Sep 17 00:00:00 2001 From: Jessica Dillon & Jessica Lynn Suttles Date: Mon, 1 Jul 2013 17:34:15 -0700 Subject: [PATCH] adds parser specs --- lib/microformats2/parser.rb | 2 +- spec/lib/microformats2/parser_spec.rb | 41 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 spec/lib/microformats2/parser_spec.rb diff --git a/lib/microformats2/parser.rb b/lib/microformats2/parser.rb index 6ee4e6e..8f9383b 100644 --- a/lib/microformats2/parser.rb +++ b/lib/microformats2/parser.rb @@ -19,7 +19,7 @@ module Microformats2 end @http_body rescue Errno::ENOENT, Errno::ENAMETOOLONG => e - html + @http_body = html end end end diff --git a/spec/lib/microformats2/parser_spec.rb b/spec/lib/microformats2/parser_spec.rb new file mode 100644 index 0000000..56cea33 --- /dev/null +++ b/spec/lib/microformats2/parser_spec.rb @@ -0,0 +1,41 @@ +require "spec_helper" +require "microformats2" + +describe Microformats2::Parser do + let(:parser) { Microformats2::Parser.new } + + describe "#http_headers" do + it "starts as a blank hash" do + parser.http_headers.should eq({}) + end + + describe "open file" do + before do + parser.parse("spec/support/lib/microformats2/simple.html") + end + + it "doesn't save #http_headers" do + parser.http_headers.should eq({}) + end + it "saves #http_body" do + parser.http_body.should include "" + end + end + + describe "http response" do + before do + stub_request(:get, "http://www.example.com/"). + with(:headers => {"Accept"=>"*/*", "User-Agent"=>"Ruby"}). + to_return(:status => 200, :body => "abc", :headers => {"Content-Length" => 3}) + parser.parse("http://www.example.com") + end + + it "saves #http_headers" do + parser.http_headers.should eq({"content-length" => "3"}) + end + it "saves #http_body" do + parser.http_body.should eq("abc") + end + end + end +end