test/test_hugs.rb in hugs-1.1.0 vs test/test_hugs.rb in hugs-1.2.0
- old
+ new
@@ -12,19 +12,19 @@
:host => "example.com",
:port => 80,
:scheme => "https",
}
- @instance = Hugs.new @valid_options
+ @instance = ::Hugs.new @valid_options
end
describe "#response_for" do
before do
@http = mock(:request => mock(:body => :body))
- @request = Net::HTTP::Get
+ @request = ::Net::HTTP::Get
- Net::HTTP::Persistent.stubs :new => @http
+ ::Net::HTTP::Persistent.stubs :new => @http
end
it "generates a path" do
@instance.send :response_for, @request, "/", {}
@@ -54,48 +54,57 @@
@instance.instance_variable_get(:@request).body.must_be_nil
end
describe "headers" do
- Json_Headers_Matcher = %r{#{"application/json"}}
-
it "has authentication" do
@instance.send :response_for, @request, "/", {}
@instance.instance_variable_get(:@request).get_fields("authorization").join.
- must_match %r{Basic #{Base64.encode64("#{@user}:#{@password}").delete("\r\n")}}
+ must_match %r{Basic #{::Base64.encode64("#{@user}:#{@password}").delete("\r\n")}}
end
[:user, :password].each do |option|
it "doesn't authenticate when '#{option}' missing" do
invalid_options = @valid_options.reject { |k,v| k == option }
- @instance = Hugs.new invalid_options
+ @instance = ::Hugs.new invalid_options
@instance.send :response_for, @request, "/", {}
@instance.instance_variable_get(:@request).get_fields("authorization").must_be_nil
end
end
- [Net::HTTP::Post, Net::HTTP::Put].each do |clazz|
- it "has content-type and accept for '#{clazz}'" do
- @instance.send :response_for, clazz, "/", {}
+ [
+ { :json => "application/json" },
+ { :xml => "application/xml" },
+ ].each do |pair|
+ pair.each_pair do |type, subtype|
+ [::Net::HTTP::Post, ::Net::HTTP::Put].each do |clazz|
+ it "has '#{subtype}' content-type and accept for '#{clazz}'" do
+ @instance = ::Hugs.new @valid_options.merge(:type => type)
- @instance.instance_variable_get(:@request).get_fields("content-type").join.
- must_match Json_Headers_Matcher
- @instance.instance_variable_get(:@request).get_fields("accept").join.
- must_match Json_Headers_Matcher
- end
- end
+ @instance.send :response_for, clazz, "/", {}
- [Net::HTTP::Get, Net::HTTP::Delete].each do |clazz|
- it "has accept for '#{clazz}'" do
- @instance.send :response_for, clazz, "/", {}
+ @instance.instance_variable_get(:@request).get_fields("content-type").join.
+ must_match %r{#{subtype}}
+ @instance.instance_variable_get(:@request).get_fields("accept").join.
+ must_match %r{#{subtype}}
+ end
+ end
- @instance.instance_variable_get(:@request).get_fields("accept").join.
- must_match Json_Headers_Matcher
- @instance.instance_variable_get(:@request).get_fields("content-type").
- must_be_nil
+ [::Net::HTTP::Get, ::Net::HTTP::Delete].each do |clazz|
+ it "has '#{subtype}' accept for '#{clazz}'" do
+ @instance = ::Hugs.new @valid_options.merge(:type => type)
+
+ @instance.send :response_for, clazz, "/", {}
+
+ @instance.instance_variable_get(:@request).get_fields("accept").join.
+ must_match %r{#{subtype}}
+ @instance.instance_variable_get(:@request).get_fields("content-type").
+ must_be_nil
+ end
+ end
end
end
end
end
end