gemsupport 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65900af3e375447e020ac05a186b02598ddce623
4
- data.tar.gz: b09b3c26b86d0c7be0a38129b978692c0ab3a6d3
3
+ metadata.gz: 48d74caf4b4620757a8dc7f06697a66e49c1b16c
4
+ data.tar.gz: 6566dc240c31fe3fe23afc79c85df84ef244fee8
5
5
  SHA512:
6
- metadata.gz: dbf79859c0b17c50703ff891c456a74cb980cb149b9f7207994a40ab8eafb6596c57955e716ed7528ef5e1d500eaf1db91c44e17c6de18c2145a995752083d94
7
- data.tar.gz: 820eb6e1f0cd29a1ac21bfc85cbf788bb2e69d4cae10365010fa5ebf36639f73c5168fa40d889427541771cdf70b8766cd8fc91a315231ba4658dc0eb26edae8
6
+ metadata.gz: 23b1f2fb787800dfea17a0ab9ac673b5c2ccf86b36becd10834caebe3ad63ccb46684718c70f6957fb9fc0ce9efd29fa42e20956e526e42a4f79c205bbf9b24e
7
+ data.tar.gz: 2335126661a157bc5cd5aa4337279cb6abb941b2fdf5a50ece9631b78bb65a354717eefa5d2d052da9ff75747231f1108bd2bc69857dcadf1e9a194f1497dc63
@@ -0,0 +1,20 @@
1
+ module Gemsupport
2
+ module Console
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def capture_console
9
+ old_stdout = $stdout
10
+ old_stderr = $stderr
11
+ $stdout = $stderr = StringIO.new('', 'w')
12
+ yield
13
+ $stdout.string
14
+ ensure
15
+ $stdout = old_stdout
16
+ $stderr = old_stderr
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Gemsupport
2
+ module Error
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def silent_exit
9
+ suppress(SystemExit) { yield }
10
+ end
11
+
12
+ # rubocop:disable HandleExceptions
13
+ def suppress(*exception_classes)
14
+ yield
15
+ rescue *exception_classes
16
+ end
17
+ # rubocop:enable HandleExceptions
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Gemsupport
2
- VERSION = '0.0.1'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/gemsupport.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'gemsupport/version'
2
2
  require 'gemsupport/core_ext'
3
+ require 'gemsupport/console'
4
+ require 'gemsupport/error'
3
5
 
4
6
  module Gemsupport
5
7
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ module Gemsupport
4
+ describe Console do
5
+ let(:dummy_class) { Class.new.send(:include, Console) }
6
+
7
+ describe '.capture_console' do
8
+ # rubocop:disable Output
9
+ it 'captures the console' do
10
+ expect(dummy_class.capture_console { puts 'Trololo' }).to eq("Trololo\n")
11
+ end
12
+ # rubocop:enable Output
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ module Gemsupport
4
+ describe Error do
5
+ let(:dummy_class) { Class.new.send(:include, Error) }
6
+
7
+ describe '.silent_exit' do
8
+ it 'catch SystemExit error' do
9
+ expect { dummy_class.silent_exit { exit(1) } }.to_not raise_error
10
+ end
11
+ end
12
+
13
+ describe '.suppress' do
14
+ it 'catch the given errors' do
15
+ expect { dummy_class.suppress(RuntimeError, StandardError) { fail StandardError.new } }
16
+ .to_not raise_error
17
+ end
18
+
19
+ it 'does not catch an error that not given' do
20
+ expect { dummy_class.suppress(RuntimeError, StandardError) { fail ScriptError.new } }
21
+ .to raise_error(ScriptError)
22
+ end
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemsupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mdouchement
@@ -110,16 +110,20 @@ files:
110
110
  - Rakefile
111
111
  - gemsupport.gemspec
112
112
  - lib/gemsupport.rb
113
+ - lib/gemsupport/console.rb
113
114
  - lib/gemsupport/core_ext.rb
114
115
  - lib/gemsupport/core_ext/blank.rb
115
116
  - lib/gemsupport/core_ext/hash.rb
116
117
  - lib/gemsupport/core_ext/hash_keys.rb
117
118
  - lib/gemsupport/core_ext/string.rb
119
+ - lib/gemsupport/error.rb
118
120
  - lib/gemsupport/version.rb
121
+ - spec/gemsupport/console_spec.rb
119
122
  - spec/gemsupport/core_ext/blank_spec.rb
120
123
  - spec/gemsupport/core_ext/hash_keys_spec.rb
121
124
  - spec/gemsupport/core_ext/hash_spec.rb
122
125
  - spec/gemsupport/core_ext/string_spec.rb
126
+ - spec/gemsupport/error_spec.rb
123
127
  - spec/spec_helper.rb
124
128
  homepage: ''
125
129
  licenses: