gemsupport 0.0.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/lib/gemsupport/console.rb +20 -0
- data/lib/gemsupport/error.rb +20 -0
- data/lib/gemsupport/version.rb +1 -1
- data/lib/gemsupport.rb +2 -0
- data/spec/gemsupport/console_spec.rb +15 -0
- data/spec/gemsupport/error_spec.rb +25 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48d74caf4b4620757a8dc7f06697a66e49c1b16c
|
4
|
+
data.tar.gz: 6566dc240c31fe3fe23afc79c85df84ef244fee8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/gemsupport/version.rb
CHANGED
data/lib/gemsupport.rb
CHANGED
@@ -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
|
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:
|