ucnv-chainsaw 0.0.2 → 0.0.3

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.
data/ChangeLog ADDED
@@ -0,0 +1,8 @@
1
+ == 0.0.3 / 2009-07-02
2
+
3
+ * Fix some bugs
4
+
5
+ == 0.0.1 / 2009-02-27
6
+
7
+ * initial release
8
+
data/README.rdoc CHANGED
@@ -32,8 +32,8 @@ A Ruby library for spidering web resources.
32
32
 
33
33
  == Installation
34
34
 
35
- * gem source -a http://gems.github.com
36
- * gem install ucnv-chainsaw
35
+ gem source -a http://gems.github.com
36
+ gem install ucnv-chainsaw
37
37
 
38
38
  == Copyright
39
39
 
data/lib/chainsaw.rb CHANGED
@@ -17,7 +17,7 @@ Nokogiri::XML::Element.module_eval do
17
17
  end
18
18
 
19
19
  module Chainsaw
20
- VERSION = '0.0.2'
20
+ VERSION = '0.0.3'
21
21
 
22
22
  #
23
23
  # Return a instance of the Chainsaw::Browser class.
@@ -1,4 +1,5 @@
1
-
1
+ require 'ostruct'
2
+ require 'tempfile'
2
3
 
3
4
  module Chainsaw
4
5
 
@@ -78,10 +79,10 @@ module Chainsaw
78
79
 
79
80
  def submit_with(button_name, image_x = -1, image_y = -1)
80
81
  uri, form = prepare_next
81
- raise TypeError, 'No form found.' unless form
82
+ raise TypeError, 'No form found.' if form.nil?
82
83
  unless button_name
83
84
  s = form.xpath('.//input[@type="submit"]')
84
- button_name = s.first['name'] if s.length
85
+ button_name = s.first['name'] if s.length and !s.first.nil?
85
86
  end
86
87
  query = form.serialize_form(button_name, image_x, image_y)
87
88
  method = (form['method'] || 'get').downcase
@@ -108,7 +109,6 @@ module Chainsaw
108
109
  end
109
110
 
110
111
  def back
111
- require 'ostruct'
112
112
  cleanup
113
113
  @history.shift
114
114
  back = @history.first
@@ -207,7 +207,7 @@ module Chainsaw
207
207
  end
208
208
 
209
209
  # history
210
- set_history uri.to_s, r.contenttype, r.content
210
+ set_history r.uri.to_s, r.contenttype, r.content
211
211
  r
212
212
  end
213
213
 
@@ -219,9 +219,10 @@ module Chainsaw
219
219
  end
220
220
 
221
221
  set.each_with_index do |e, index|
222
+ pos = @history.size
222
223
  set_next(e)
223
224
  with_index ? yield(self, index) : yield(self)
224
- back
225
+ back if @history.size == pos + 1
225
226
  end
226
227
  self
227
228
  end
data/test/test_browser.rb CHANGED
@@ -144,7 +144,7 @@ class TestBrowser < Test::Unit::TestCase
144
144
  assert_equal index, count
145
145
  count += 1
146
146
  cs.open { |cs|
147
- if count == 4
147
+ if index == 3
148
148
  x = YAML.load cs.res.content
149
149
  assert_equal TEST_URL + '01.html', x['env']['HTTP_REFERER']
150
150
  end
@@ -152,6 +152,53 @@ class TestBrowser < Test::Unit::TestCase
152
152
  }
153
153
  end
154
154
 
155
+ def test_each_next
156
+ count = 0
157
+ Chainsaw.launch(TEST_URL + '01.html').open { |cs|
158
+ cs.set_next cs.doc.xpath('//a')
159
+ }.each_with_index { |cs, i|
160
+ assert_equal i, count
161
+ count += 1
162
+ cs.open { |cs|
163
+ break if i != 3
164
+ assert_equal i, 3
165
+ x = YAML.load cs.res.content
166
+ assert_equal TEST_URL + '01.html', x['env']['HTTP_REFERER']
167
+ }
168
+ }
169
+ end
170
+
171
+ def test_each_next2
172
+ count = 0
173
+ Chainsaw.launch(TEST_URL + '01.html').open { |cs|
174
+ cs.set_next cs.doc.xpath('//a')
175
+ }.each_with_index { |cs, i|
176
+ assert_equal i, count
177
+ count += 1
178
+ next if i != 3
179
+ assert_equal i, 3
180
+ cs.open { |c|
181
+ x = YAML.load c.res.content
182
+ assert_equal TEST_URL + '01.html', x['env']['HTTP_REFERER']
183
+ }
184
+ }
185
+ end
186
+
187
+ def test_each_break
188
+ count = 0
189
+ Chainsaw.launch(TEST_URL + '01.html').open { |cs|
190
+ cs.set_next cs.doc.xpath('//a')
191
+ }.each { |cs|
192
+ next if count == 0
193
+ break if count == 1
194
+ count += 1
195
+ cs.open {|cs|
196
+ flunk 'Must not pass here.'
197
+ }
198
+ }
199
+
200
+ end
201
+
155
202
  def test_referer
156
203
  Chainsaw.launch(TEST_URL + '01.html').
157
204
  open { |cs|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ucnv-chainsaw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ucnv
@@ -9,7 +9,7 @@ autorequire: ""
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-07 00:00:00 -08:00
12
+ date: 2009-07-02 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency