rescue_each 1.1.4 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create 1.9.2@rescue_each
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source :gemcutter
2
+
3
+ gem 'activesupport', '>= 2.3'
4
+
5
+ group :development do
6
+ gem 'activerecord'
7
+ gem 'i18n'
8
+ gem 'jeweler'
9
+ gem 'test-unit'
10
+ gem 'rcov'
11
+ gem 'sqlite3'
12
+ end
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rubygems'
2
- require 'rake'
2
+ require 'bundler/setup'
3
3
  require 'rake/testtask'
4
+ require 'jeweler'
5
+ require 'rcov/rcovtask'
4
6
 
5
7
  desc 'Default: run unit tests.'
6
8
  task :default => :test
@@ -13,48 +15,34 @@ Rake::TestTask.new(:test) do |t|
13
15
  t.verbose = true
14
16
  end
15
17
 
16
- task :test => :check_dependencies
18
+ Jeweler::Tasks.new do |gem|
19
+ gem.name = "rescue_each"
20
+ gem.summary = "Rescue multiple exceptions when enumerating over Enumerable or ActiveRecord objects"
21
+ gem.email = "jason@jasoncodes.com"
22
+ gem.homepage = "http://github.com/jasoncodes/rescue_each"
23
+ gem.authors = ["Jason Weathered"]
24
+ gem.has_rdoc = false
25
+ end
26
+ Jeweler::GemcutterTasks.new
17
27
 
18
- begin
19
- require 'jeweler'
20
- Jeweler::Tasks.new do |gem|
21
- gem.name = "rescue_each"
22
- gem.summary = "Rescue multiple exceptions when enumerating over Enumerable or ActiveRecord objects"
23
- gem.email = "jason@jasoncodes.com"
24
- gem.homepage = "http://github.com/jasoncodes/rescue_each"
25
- gem.authors = ["Jason Weathered"]
26
- gem.has_rdoc = false
27
- gem.add_dependency 'activesupport'
28
- gem.add_development_dependency 'activerecord'
29
- end
30
- Jeweler::GemcutterTasks.new
31
- rescue LoadError
32
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
28
+ task :lib do
29
+ $: << 'lib'
30
+ require 'rescue_each'
33
31
  end
32
+ task :console => :lib
34
33
 
35
- desc "Open an IRB session with this library loaded"
36
- task :console do
37
- sh "irb -rrubygems -I lib -r rescue_each.rb"
34
+ Rcov::RcovTask.new do |t|
35
+ t.libs << "test"
36
+ t.rcov_opts = [
37
+ "--exclude '^(?!lib)'"
38
+ ]
39
+ t.test_files = FileList[
40
+ 'test/**/*_test.rb'
41
+ ]
42
+ t.output_dir = 'coverage'
43
+ t.verbose = true
38
44
  end
39
45
 
40
- begin
41
- require 'rcov/rcovtask'
42
- Rcov::RcovTask.new do |t|
43
- t.libs << "test"
44
- t.rcov_opts = [
45
- "--exclude '^(?!lib)'"
46
- ]
47
- t.test_files = FileList[
48
- 'test/**/*_test.rb'
49
- ]
50
- t.output_dir = 'coverage'
51
- t.verbose = true
52
- end
53
- task :rcov do
54
- system "open coverage/index.html"
55
- end
56
- rescue LoadError
57
- task :rcov do
58
- raise "You must install the 'rcov' gem"
59
- end
46
+ task :rcov do
47
+ system "open coverage/index.html"
60
48
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.4
1
+ 1.1.6
@@ -17,6 +17,7 @@ module RescueEach
17
17
  def title
18
18
  "#{exception.message} (#{exception.class})"
19
19
  end
20
+
20
21
  def args_short
21
22
  args_str = args.map do |arg|
22
23
  str = arg.inspect
@@ -29,11 +30,17 @@ module RescueEach
29
30
  end
30
31
  "args: " + args_str.join(", ")
31
32
  end
33
+
32
34
  def args_full
33
35
  "args: #{args.inspect}"
34
36
  end
37
+
38
+ def backtrace_lines
39
+ exception.backtrace.take_while { |line| !line.index(__FILE__) }
40
+ end
41
+
35
42
  def backtrace_s
36
- "\t#{exception.backtrace.join "\n\t"}"
43
+ "\t#{backtrace_lines.join "\n\t"}"
37
44
  end
38
45
 
39
46
  def short_message
@@ -64,6 +71,10 @@ module RescueEach
64
71
 
65
72
  end
66
73
 
74
+ def self.pass_through_exception?(exception)
75
+ %w(Interrupt IRB::Abort SignalException).include? exception.class.name
76
+ end
77
+
67
78
  module CoreExt
68
79
 
69
80
  module Object
@@ -79,7 +90,7 @@ module RescueEach
79
90
  errors = []
80
91
  retval = __send__ options[:method], *options[:args] do |*args|
81
92
  begin
82
- block.call *args.dup
93
+ block.call(*args.dup)
83
94
  rescue Exception => e
84
95
 
85
96
  item = RescueEach::Error::Item.new e, args
@@ -89,8 +100,8 @@ module RescueEach
89
100
  $stderr.puts "rescue_each error: #{item.short_message}"
90
101
  end
91
102
 
92
- # should fail immediately on Interrupt exceptions (i.e. Ctrl-C)
93
- if %w(Interrupt IRB::Abort).include? e.class.name
103
+ # should fail immediately on interrupt exceptions (i.e. Ctrl-C)
104
+ if RescueEach.pass_through_exception? e
94
105
  if errors.empty?
95
106
  raise
96
107
  else
@@ -114,8 +125,8 @@ module RescueEach
114
125
 
115
126
  args = args.dup
116
127
  options = args.extract_options!
117
- rescue_options = options.slice *RESCUE_EACH_OPTIONS
118
- options.except! *RESCUE_EACH_OPTIONS
128
+ rescue_options = options.slice(*RESCUE_EACH_OPTIONS)
129
+ options.except!(*RESCUE_EACH_OPTIONS)
119
130
  args << options unless options.empty?
120
131
 
121
132
  rescue_options[:method] = method
@@ -12,7 +12,7 @@ class RescueEachTest < ActiveSupport::TestCase
12
12
  (1..5).rescue_each do |x|
13
13
  output << x
14
14
  end
15
- assert_equal (1..5).collect, output
15
+ assert_equal((1..5).to_a, output)
16
16
  end
17
17
 
18
18
  test "continues after an error" do
@@ -26,9 +26,9 @@ class RescueEachTest < ActiveSupport::TestCase
26
26
  rescue RescueEach::Error => e
27
27
  error_object = e
28
28
  end
29
- assert_equal (1..5).collect, output
29
+ assert_equal((1..5).to_a, output)
30
30
  assert_false error_object.aborted
31
- assert_no_match /and then aborted/, error_object.to_s.lines.collect.last
31
+ assert_no_match(/and then aborted/, error_object.to_s.lines.to_a.last)
32
32
  end
33
33
 
34
34
  test "stops after error limit" do
@@ -42,9 +42,9 @@ class RescueEachTest < ActiveSupport::TestCase
42
42
  rescue RescueEach::Error => e
43
43
  error_object = e
44
44
  end
45
- assert_equal (1..6).collect, output
45
+ assert_equal((1..6).to_a, output)
46
46
  assert_true error_object.aborted
47
- assert_match /and then aborted/, error_object.to_s.lines.collect.last
47
+ assert_match(/and then aborted/, error_object.to_s.lines.to_a.last)
48
48
  end
49
49
 
50
50
  test "empty array doesn't call block" do
@@ -117,7 +117,7 @@ class RescueEachTest < ActiveSupport::TestCase
117
117
  test "error object contains args for Symbol#to_proc sugar" do
118
118
  error_object = nil
119
119
  begin
120
- [42].rescue_each &:foo
120
+ [42].rescue_each(&:foo)
121
121
  rescue RescueEach::Error => e
122
122
  error_object = e
123
123
  end
@@ -150,8 +150,33 @@ class RescueEachTest < ActiveSupport::TestCase
150
150
  assert_equal 'baz', the_exception.message
151
151
 
152
152
  assert_true the_exception.backtrace.size > 2
153
- assert_match /:in `bar_def'\Z/, the_exception.backtrace[0]
154
- assert_match /:in `foo_abc'\Z/, the_exception.backtrace[1]
153
+ assert_match(/:in `bar_def'\Z/, the_exception.backtrace[0])
154
+ assert_match(/:in `foo_abc'\Z/, the_exception.backtrace[1])
155
+
156
+ end
157
+
158
+ test "backtrace in message should not duplicate main exception lines" do
159
+
160
+ error_object = nil
161
+ begin
162
+ [42].rescue_each do |i|
163
+ foo_abc
164
+ end
165
+ rescue RescueEach::Error => e
166
+ error_object = e
167
+ end
168
+
169
+ assert_match(/foo_abc/, error_object.message)
170
+ assert_match(/bar_def/, error_object.message)
171
+
172
+ assert_no_match(/foo_abc/, error_object.backtrace.join("\n"))
173
+ assert_no_match(/bar_def/, error_object.backtrace.join("\n"))
174
+
175
+ assert_match(/rescue_each\.rb/, error_object.backtrace.join("\n"))
176
+ assert_no_match(/rescue_each\.rb/, error_object.message)
177
+
178
+ assert_match(/activesupport/, error_object.backtrace.join("\n"))
179
+ assert_no_match(/activesupport/, error_object.message)
155
180
 
156
181
  end
157
182
 
@@ -175,8 +200,8 @@ class RescueEachTest < ActiveSupport::TestCase
175
200
 
176
201
  assert_equal [1,3,4], output
177
202
  assert_kind_of ::IRB::Abort, error_object
178
- assert_match /abort then interrupt/, error_object.message
179
- assert_match /foo bar/, error_object.message
203
+ assert_match(/abort then interrupt/, error_object.message)
204
+ assert_match(/foo bar/, error_object.message)
180
205
 
181
206
  end
182
207
 
@@ -196,10 +221,21 @@ class RescueEachTest < ActiveSupport::TestCase
196
221
 
197
222
  assert_equal [1,3,4], output
198
223
  assert_kind_of ::Interrupt, error_object
199
- assert_match /foo bar/, error_object.message
224
+ assert_match(/foo bar/, error_object.message)
200
225
 
201
226
  end
202
227
 
228
+ test "signal should break out of loop" do
229
+ output = []
230
+ assert_raise SignalException do
231
+ (1..5).rescue_each do |i|
232
+ raise SignalException.new('TERM') if i == 3
233
+ output << i
234
+ end
235
+ end
236
+ assert_equal [1,2], output
237
+ end
238
+
203
239
  test "no stderr option doesn't output to stderr" do
204
240
  err = capture_stderr do
205
241
  assert_raise RescueEach::Error do
@@ -219,7 +255,7 @@ class RescueEachTest < ActiveSupport::TestCase
219
255
  end
220
256
  end
221
257
  end
222
- assert_match /foo bar/, err
258
+ assert_match(/foo bar/, err)
223
259
  end
224
260
 
225
261
  test "stderr output truncates long args" do
@@ -236,8 +272,8 @@ class RescueEachTest < ActiveSupport::TestCase
236
272
  end
237
273
 
238
274
  test "rescue_send passes through args" do
239
- assert_true (1..5).rescue_send :include?, 3
240
- assert_false (1..5).rescue_send :include?, 6
275
+ assert_true((1..5).rescue_send(:include?, 3))
276
+ assert_false((1..5).rescue_send(:include?, 6))
241
277
  end
242
278
 
243
279
  test "rescue_send handles rescue_each options" do
@@ -248,7 +284,7 @@ class RescueEachTest < ActiveSupport::TestCase
248
284
  end
249
285
  end
250
286
  end
251
- assert_match /lorem ipsum/, err
287
+ assert_match(/lorem ipsum/, err)
252
288
  end
253
289
 
254
290
  test "rescue_map returns output of proxied method" do
@@ -259,13 +295,13 @@ class RescueEachTest < ActiveSupport::TestCase
259
295
  test "rescue_send calls correct method and returns result" do
260
296
  odds = (1..5).rescue_send(:reject) { |i| i%2 == 0 }
261
297
  assert_false odds.empty?
262
- assert_true odds.all? &:odd?
298
+ assert_true odds.all?(&:odd?)
263
299
  end
264
300
 
265
301
  test "rescued find methods exist on active record objects" do
266
302
  [:find_each, :find_in_batches].each do |method_base|
267
303
  ["#{method_base}", "rescue_#{method_base}"].each do |method|
268
- [ActiveRecord::Base, ActiveRecord::Base.scoped(:limit => 42)].each do |object|
304
+ [Post, Post.scoped(:limit => 42)].each do |object|
269
305
  assert_true object.respond_to? method
270
306
  end
271
307
  end
@@ -15,3 +15,10 @@ def capture_stderr
15
15
  ensure
16
16
  $stderr = oldstderr
17
17
  end
18
+
19
+ class Post < ActiveRecord::Base
20
+ establish_connection :adapter => 'sqlite3', :database => ':memory:'
21
+ connection.create_table :post do |t|
22
+ t.string :name
23
+ end
24
+ end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rescue_each
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 1
9
- - 4
10
- version: 1.1.4
4
+ prerelease:
5
+ version: 1.1.6
11
6
  platform: ruby
12
7
  authors:
13
8
  - Jason Weathered
@@ -15,37 +10,86 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2010-07-10 00:00:00 +10:00
13
+ date: 2011-03-24 00:00:00 +10:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
22
17
  name: activesupport
23
- prerelease: false
24
18
  requirement: &id001 !ruby/object:Gem::Requirement
25
19
  none: false
26
20
  requirements:
27
21
  - - ">="
28
22
  - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
23
+ version: "2.3"
33
24
  type: :runtime
25
+ prerelease: false
34
26
  version_requirements: *id001
35
27
  - !ruby/object:Gem::Dependency
36
28
  name: activerecord
37
- prerelease: false
38
29
  requirement: &id002 !ruby/object:Gem::Requirement
39
30
  none: false
40
31
  requirements:
41
32
  - - ">="
42
33
  - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
34
  version: "0"
47
35
  type: :development
36
+ prerelease: false
48
37
  version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: i18n
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: test-unit
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: rcov
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: sqlite3
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
49
93
  description:
50
94
  email: jason@jasoncodes.com
51
95
  executables: []
@@ -56,7 +100,8 @@ extra_rdoc_files:
56
100
  - LICENSE
57
101
  - README.markdown
58
102
  files:
59
- - .gitignore
103
+ - .rvmrc
104
+ - Gemfile
60
105
  - LICENSE
61
106
  - README.markdown
62
107
  - Rakefile
@@ -69,8 +114,8 @@ homepage: http://github.com/jasoncodes/rescue_each
69
114
  licenses: []
70
115
 
71
116
  post_install_message:
72
- rdoc_options:
73
- - --charset=UTF-8
117
+ rdoc_options: []
118
+
74
119
  require_paths:
75
120
  - lib
76
121
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -78,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
123
  requirements:
79
124
  - - ">="
80
125
  - !ruby/object:Gem::Version
81
- hash: 3
126
+ hash: -1762151594371980548
82
127
  segments:
83
128
  - 0
84
129
  version: "0"
@@ -87,14 +132,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
132
  requirements:
88
133
  - - ">="
89
134
  - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
135
  version: "0"
94
136
  requirements: []
95
137
 
96
138
  rubyforge_project:
97
- rubygems_version: 1.3.7
139
+ rubygems_version: 1.6.2
98
140
  signing_key:
99
141
  specification_version: 3
100
142
  summary: Rescue multiple exceptions when enumerating over Enumerable or ActiveRecord objects
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- *.gemspec
2
- pkg
3
- coverage