Skip to content
This repository
Browse code

Use Net::HTTP instead of curl

There was some problem with command line parsing with a special character.
  • Loading branch information...
commit bb22be301a783b2e2ab58f7904231ffd8211766c 1 parent 88a8af9
Prem Sichanugrist authored December 12, 2011
14  test/helper.rb
@@ -161,3 +161,17 @@ def with_exitstatus_returning(code)
161 161
 def fixture_file(filename)
162 162
  File.join(File.dirname(__FILE__), 'fixtures', filename)
163 163
 end
  164
+
  165
+def assert_success_response(url)
  166
+  Net::HTTP.get_response(URI.parse(url)) do |response|
  167
+    assert_equal "200", response.code,
  168
+      "Expected HTTP response code 200, got #{response.code}"
  169
+  end
  170
+end
  171
+
  172
+def assert_not_found_response(url)
  173
+  Net::HTTP.get_response(URI.parse(url)) do |response|
  174
+    assert_equal "404", response.code,
  175
+      "Expected HTTP response code 404, got #{response.code}"
  176
+  end
  177
+end
10  test/storage/s3_live_test.rb
@@ -91,13 +91,13 @@ class S3LiveTest < Test::Unit::TestCase
91 91
       end
92 92
 
93 93
       should "be accessible" do
94  
-        assert_match /200 OK/, `curl -I #{@dummy.avatar.url}`
  94
+        assert_success_response @dummy.avatar.url
95 95
       end
96 96
 
97 97
       should "be destoryable" do
98 98
         url = @dummy.avatar.url
99 99
         @dummy.destroy
100  
-        assert_match /404 Not Found/, `curl -I #{url}`
  100
+        assert_not_found_response url
101 101
       end
102 102
     end
103 103
 
@@ -125,17 +125,17 @@ class S3LiveTest < Test::Unit::TestCase
125 125
       end
126 126
 
127 127
       should "be accessible" do
128  
-        assert_match /200 OK/, `curl -I "#{@dummy.avatar.url}"`
  128
+        assert_success_response @dummy.avatar.url
129 129
       end
130 130
 
131 131
       should "be accessible with an expiring url" do
132  
-        assert_match /200 OK/, `curl -I "#{@dummy.avatar.expiring_url}"`
  132
+        assert_success_response @dummy.avatar.expiring_url
133 133
       end
134 134
 
135 135
       should "be destroyable" do
136 136
         url = @dummy.avatar.url
137 137
         @dummy.destroy
138  
-        assert_match /404 Not Found/, `curl -I "#{url}"`
  138
+        assert_not_found_response url
139 139
       end
140 140
     end
141 141
   end

0 notes on commit bb22be3

Please sign in to comment.
Something went wrong with that request. Please try again.