mikehale-rat-hole 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,7 @@
1
+ = 0.1.9
2
+
3
+ * test tidy
4
+
1
5
  = 0.1.8
2
6
 
3
7
  * bug fixes
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 8
4
+ :patch: 9
@@ -44,11 +44,12 @@ class RatHole
44
44
  code = response.code.to_i
45
45
  headers = response.to_hash
46
46
  body = response.body || ''
47
- body = tidy_html(body) if @tidy
48
47
  headers.delete('Transfer-Encoding')
49
48
 
50
49
  server_response = Rack::Response.new(body, code, headers)
51
50
  whack_array(server_response)
51
+ tidy_html(body) if server_response["Content-Type"] =~ /text\/html/ && @tidy
52
+
52
53
  process_server_response(server_response, source_request)
53
54
  server_response.finish
54
55
  end
@@ -67,12 +68,13 @@ class RatHole
67
68
  $stderr.puts "tidy not found in path"
68
69
  return
69
70
  end
70
- tidied = Open3.popen3('tidy -ascii') do |stdin, stdout, stderr|
71
+ tidied, errors = Open3.popen3('tidy -ascii') do |stdin, stdout, stderr|
71
72
  stdin.print body
72
73
  stdin.close
73
- stdout.read
74
+ [stdout.read, stderr.read]
74
75
  end
75
- body.replace(tidied)
76
+ $stderr.puts errors if $DEBUG
77
+ body.replace(tidied) if tidied != ""
76
78
  end
77
79
 
78
80
  def request_headers(env)
@@ -53,9 +53,9 @@ class TestRatHole < Test::Unit::TestCase
53
53
  MockRequest.new(@io.written)
54
54
  end
55
55
 
56
- def send_get_request(rack_env={}, uri='/someuri')
56
+ def send_get_request(rack_env={}, uri='/someuri', tidy=false)
57
57
  opts = {:lint=>true}.merge(rack_env)
58
- rh = RatHole.new('127.0.0.1')
58
+ rh = RatHole.new('127.0.0.1', tidy)
59
59
  Rack::MockRequest.new(rh).get(uri, opts)
60
60
  end
61
61
 
@@ -182,6 +182,19 @@ class TestRatHole < Test::Unit::TestCase
182
182
  send_post_request('', '/uri?with=param')
183
183
  assert_equal('/uri?with=param', proxied_request.uri)
184
184
  end
185
+
186
+ def test_tidy_fails
187
+ body = '<something tidy <will </barf on'
188
+ mock_server(:body => body)
189
+ response = send_get_request({}, '/', true)
190
+ assert_equal(response.body, body)
191
+ end
192
+
193
+ def test_tidy_tidies
194
+ mock_server(:body => 'tidy me')
195
+ response = send_get_request({:lint=>false}, '/', true)
196
+ assert response.body =~ /html/i
197
+ end
185
198
  end
186
199
 
187
200
  class TestEmptyRatHole < RatHoleTest
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mikehale-rat-hole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Hale