hrk 1.0.1 → 1.0.2

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: 82d38e84f36d6da9b58b461882813c680b79eeec
4
- data.tar.gz: b053a4c69d8c8dd28e2d4e1fda5662fb54e66859
3
+ metadata.gz: 71509f19c9d674c923c4fb3d375516d87d9d5593
4
+ data.tar.gz: 4fe443aec8e10bb1f2d22a13dd3d4bd3969056bf
5
5
  SHA512:
6
- metadata.gz: 736aec490d90d32fff6744995a47260ba69b42d27954efdef0489bb938f7ee21b26bcc891d5d0eb1bc795f903957219178404850aa538ebc4601f95b01038508
7
- data.tar.gz: 1f334cd212a2dbf9a5237ce581af3559feba44b14d3cfe7a9dca4f75e51c4b05d0e49d3369a9cbd4c8558a1b20b651b9f58c3b26fde79f4f3f5a153db5a23210
6
+ metadata.gz: 4fc36605682ffc7e8421c39e3a6ed04de752907d5fe422c4e0a8e0da04ff54b3b990ed90e369608d4fbbc4ca28ccee0fb3801de4907d5ccdc9a09183b7c9d2e4
7
+ data.tar.gz: facfef2698ff6257aa58bfbbe9f28856e07da25f183c769f059162ba0b346ca30550742d72a568d1f03fe5f96347247923a8f193634e552e5f8372d0301238db
@@ -1,14 +1,15 @@
1
1
  module Hrk
2
2
  module Execute
3
- autoload :Command, 'hrk/execute/command'
4
- autoload :Help, 'hrk/execute/help'
3
+ autoload :Command, 'hrk/execute/command'
4
+ autoload :Help, 'hrk/execute/help'
5
+ autoload :ErrorTrap, 'hrk/execute/error_trap'
5
6
 
6
7
  def self.call *args
7
8
  executer.call(*args)
8
9
  end
9
10
 
10
11
  def self.executer
11
- Help.new Command.new
12
+ ErrorTrap.new Help.new Command.new
12
13
  end
13
14
  end
14
15
  end
@@ -0,0 +1,22 @@
1
+ module Hrk
2
+ module Execute
3
+ class ErrorTrap
4
+ def initialize callee
5
+ @callee = callee
6
+ end
7
+
8
+ def call *args
9
+ if args.include? '--hrk-testing'
10
+ @callee.call *(args - ['--hrk-testing'])
11
+ else
12
+ begin
13
+ @callee.call *args
14
+ rescue
15
+ puts "Error: #{$!.message}"
16
+ false
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -16,7 +16,7 @@ module Hrk
16
16
  def display
17
17
  puts <<-eos
18
18
  Usage:
19
- hrk command [(-r remote | -a appname)]...
19
+ hrk command [(-r remote | -a appname)] [options]...
20
20
  hrk [h | help | -h | --help]
21
21
 
22
22
  The hrk command remembers the last app you've send a command to on a terminal
@@ -29,9 +29,11 @@ Note that whatever argument and/or options the command is composed of should not
29
29
  be tampered with and passed as is to the heroku toolbelt command.
30
30
 
31
31
  Options:
32
- -h --help Display this screen.
33
- -r remote Sets the remote for this command and the following
34
- -a appname Sets the heroku app name for this command and the following
32
+ -h --help Display this screen.
33
+ -r remote Sets the remote for this command and the following.
34
+ -a appname Sets the heroku app name for this command and the following.
35
+
36
+ --hrk-testing Full exceptions stack trace delivered (testing purposes only).
35
37
 
36
38
  More on the hrk command on the gem's website:
37
39
  https://github.com/Bastes/hrk
@@ -1,3 +1,3 @@
1
1
  module Hrk
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Hrk::Execute::ErrorTrap do
4
+ describe '#call' do
5
+ let(:next_callee) { double }
6
+
7
+ subject(:error_trap) { Hrk::Execute::ErrorTrap.new(next_callee) }
8
+
9
+ context 'no --hrk-testing option' do
10
+ let(:args) { %W(-a b#{rand(1..9)} --cd) }
11
+
12
+ context 'no exception is raised' do
13
+ let(:expected_result) { [true, false].sample }
14
+
15
+ before { allow(next_callee).to receive(:call).and_return(expected_result) }
16
+
17
+ subject!(:result) { error_trap.call(*args) }
18
+
19
+ it { expect(result).to eq expected_result }
20
+ it { expect(next_callee).to have_received(:call).with(*args) }
21
+ end
22
+
23
+ context 'an exception is raised' do
24
+ let(:exception) { ArgumentError.new "blah #{rand(1..9)} blah" }
25
+
26
+ before { allow(next_callee).to receive(:call).and_raise(exception) }
27
+ before { allow(error_trap).to receive(:puts) }
28
+
29
+ it { expect { error_trap.call(*args) }.not_to raise_exception }
30
+ it { expect(error_trap.call(*args)).to eq false }
31
+
32
+ context 'interactions' do
33
+ before { error_trap.call(*args) }
34
+
35
+ it { expect(error_trap).to have_received(:puts).with("Error: #{exception.message}") }
36
+ end
37
+ end
38
+ end
39
+
40
+ context 'an --hrk-testing option' do
41
+ let(:args) { %w(-r remote --hrk-testing logs -t) }
42
+
43
+ context 'no exception is raised' do
44
+ let(:expected_result) { [true, false].sample }
45
+
46
+ before { allow(next_callee).to receive(:call).and_return(expected_result) }
47
+
48
+ subject!(:result) { error_trap.call(*args) }
49
+
50
+ it { expect(result).to eq expected_result }
51
+ it { expect(next_callee).to have_received(:call).with(*%w(-r remote logs -t)) }
52
+ end
53
+
54
+ context 'an exception is raised' do
55
+ let(:exception) { ArgumentError.new "blah #{rand(1..9)} blah" }
56
+
57
+ before { allow(next_callee).to receive(:call).with(*%w(-r remote logs -t)).and_raise(exception) }
58
+ before { allow(error_trap).to receive(:puts) }
59
+
60
+ it { expect { error_trap.call(*args) }.to raise_exception exception }
61
+
62
+ context 'interactions' do
63
+ before { error_trap.call(*args) rescue nil }
64
+
65
+ it { expect(error_trap).not_to have_received(:puts) }
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -18,11 +18,13 @@ RSpec.describe Hrk::Execute do
18
18
  end
19
19
 
20
20
  describe '.executer' do
21
- let(:help) { double(Hrk::Execute::Help) }
22
- let(:command) { double(Hrk::Execute::Command) }
21
+ let(:error_trap) { double(Hrk::Execute::ErrorTrap) }
22
+ let(:help) { double(Hrk::Execute::Help) }
23
+ let(:command) { double(Hrk::Execute::Command) }
24
+ before { allow(Hrk::Execute::ErrorTrap).to receive(:new).with(help).and_return(error_trap) }
23
25
  before { allow(Hrk::Execute::Help).to receive(:new).with(command).and_return(help) }
24
26
  before { allow(Hrk::Execute::Command).to receive(:new).and_return(command) }
25
27
 
26
- it { expect(Hrk::Execute.executer).to eq help }
28
+ it { expect(Hrk::Execute.executer).to eq error_trap }
27
29
  end
28
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hrk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Belleville
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -166,11 +166,13 @@ files:
166
166
  - lib/hrk/env.rb
167
167
  - lib/hrk/execute.rb
168
168
  - lib/hrk/execute/command.rb
169
+ - lib/hrk/execute/error_trap.rb
169
170
  - lib/hrk/execute/help.rb
170
171
  - lib/hrk/heroku.rb
171
172
  - lib/hrk/version.rb
172
173
  - spec/hrk/env_spec.rb
173
174
  - spec/hrk/execute/command_spec.rb
175
+ - spec/hrk/execute/error_trap_spec.rb
174
176
  - spec/hrk/execute/help_spec.rb
175
177
  - spec/hrk/execute_spec.rb
176
178
  - spec/hrk/heroku_spec.rb