stacker_bee 2.1.1.pre252 → 2.1.1.pre263
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 +8 -8
- data/.rubocop.yml +0 -3
- data/Rakefile +1 -1
- data/bin/stacker_bee +10 -10
- data/lib/stacker_bee/api.rb +4 -4
- data/lib/stacker_bee/client.rb +24 -24
- data/lib/stacker_bee/configuration.rb +13 -7
- data/lib/stacker_bee/connection.rb +5 -5
- data/lib/stacker_bee/http_middleware/detokenizer.rb +2 -2
- data/lib/stacker_bee/http_middleware/signed_query.rb +3 -3
- data/lib/stacker_bee/middleware/adapter.rb +1 -1
- data/lib/stacker_bee/middleware/base.rb +1 -1
- data/lib/stacker_bee/middleware/clean_response.rb +2 -2
- data/lib/stacker_bee/middleware/cloud_stack_api.rb +2 -2
- data/lib/stacker_bee/middleware/dictionary_flattener.rb +3 -3
- data/lib/stacker_bee/middleware/endpoint_normalizer.rb +2 -2
- data/lib/stacker_bee/middleware/error_message.rb +3 -3
- data/lib/stacker_bee/middleware/log_response.rb +1 -1
- data/lib/stacker_bee/middleware/raise_on_http_error.rb +1 -1
- data/lib/stacker_bee/middleware/remove_nils.rb +1 -1
- data/lib/stacker_bee/rash.rb +3 -3
- data/lib/stacker_bee/version.rb +1 -1
- data/lib/stacker_bee.rb +2 -2
- data/spec/integration/configure_middleware_spec.rb +12 -12
- data/spec/integration/console_spec.rb +4 -4
- data/spec/integration/request_spec.rb +46 -46
- data/spec/spec_helper.rb +4 -4
- data/spec/support/vcr.rb +4 -4
- data/spec/units/stacker_bee/api_spec.rb +11 -11
- data/spec/units/stacker_bee/client_spec.rb +19 -19
- data/spec/units/stacker_bee/configuration_spec.rb +28 -28
- data/spec/units/stacker_bee/connection_spec.rb +18 -18
- data/spec/units/stacker_bee/middleware/adapter_spec.rb +7 -7
- data/spec/units/stacker_bee/middleware/base_spec.rb +17 -17
- data/spec/units/stacker_bee/middleware/cloudstack_api_spec.rb +9 -9
- data/spec/units/stacker_bee/middleware/console_access_spec.rb +10 -10
- data/spec/units/stacker_bee/middleware/dictionary_flattener_spec.rb +22 -22
- data/spec/units/stacker_bee/middleware/endpoint_normalizer_spec.rb +4 -4
- data/spec/units/stacker_bee/middleware/error_message_spec.rb +6 -6
- data/spec/units/stacker_bee/middleware/format_keys_spec.rb +2 -2
- data/spec/units/stacker_bee/middleware/format_values_spec.rb +2 -2
- data/spec/units/stacker_bee/middleware/http_status_spec.rb +2 -2
- data/spec/units/stacker_bee/middleware/log_response_spec.rb +15 -15
- data/spec/units/stacker_bee/middleware/remove_empty_strings_spec.rb +4 -4
- data/spec/units/stacker_bee/middleware/remove_nils_spec.rb +1 -1
- data/spec/units/stacker_bee/rash_spec.rb +41 -41
- data/spec/units/stacker_bee/request_error_spec.rb +7 -7
- data/spec/units/stacker_bee/utilities_spec.rb +30 -30
- data/spec/units/stacker_bee_spec.rb +2 -2
- data/stacker_bee.gemspec +24 -22
- metadata +4 -4
@@ -13,20 +13,20 @@ describe StackerBee::Middleware::Base do
|
|
13
13
|
let(:subclass) { Class.new(described_class, &subclass_body) }
|
14
14
|
let(:subclass_body) { proc {} }
|
15
15
|
|
16
|
-
describe
|
16
|
+
describe '#call' do
|
17
17
|
before do
|
18
18
|
middleware.call env
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.it_calls_its_app_with_the_env
|
22
|
-
it
|
22
|
+
it 'calls its app with the env' do
|
23
23
|
app.should have_received(:call).with(env)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
it_calls_its_app_with_the_env
|
28
28
|
|
29
|
-
context
|
29
|
+
context 'when overriding #before' do
|
30
30
|
let(:subclass_body) do
|
31
31
|
proc do
|
32
32
|
def before(env)
|
@@ -37,12 +37,12 @@ describe StackerBee::Middleware::Base do
|
|
37
37
|
|
38
38
|
it_calls_its_app_with_the_env
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'runs the before hook' do
|
41
41
|
env.before_was_run.should be_true
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
context
|
45
|
+
context 'when overriding #after' do
|
46
46
|
let(:subclass_body) do
|
47
47
|
proc do
|
48
48
|
def after(env)
|
@@ -53,12 +53,12 @@ describe StackerBee::Middleware::Base do
|
|
53
53
|
|
54
54
|
it_calls_its_app_with_the_env
|
55
55
|
|
56
|
-
it
|
56
|
+
it 'runs the after hook' do
|
57
57
|
env.after_was_run.should be_true
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
context
|
61
|
+
context 'when overriding #content_types' do
|
62
62
|
let(:subclass_body) do
|
63
63
|
proc do
|
64
64
|
def after(env)
|
@@ -73,22 +73,22 @@ describe StackerBee::Middleware::Base do
|
|
73
73
|
|
74
74
|
it_calls_its_app_with_the_env
|
75
75
|
|
76
|
-
context
|
76
|
+
context 'when it matches the content type' do
|
77
77
|
let(:content_type) { 'text/html; uft-8' }
|
78
|
-
it
|
78
|
+
it 'runs the after hook' do
|
79
79
|
env.after_was_run.should be_true
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
context "when it doesn't match the content type" do
|
84
84
|
let(:content_type) { 'text/javascript; uft-8' }
|
85
|
-
it
|
85
|
+
it 'runs the after hook' do
|
86
86
|
env.after_was_run.should be_nil
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
context
|
91
|
+
context 'when overriding #params' do
|
92
92
|
let(:subclass_body) do
|
93
93
|
proc do
|
94
94
|
def transform_params(params)
|
@@ -97,17 +97,17 @@ describe StackerBee::Middleware::Base do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
it
|
100
|
+
it 'changes the params' do
|
101
101
|
env.request.params[:params_merged?].should be_true
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
describe
|
106
|
+
describe '#endpoint_name_for' do
|
107
107
|
let(:endpoint_name) { double }
|
108
108
|
let(:normalized_endpoint_name) { double }
|
109
109
|
|
110
|
-
it
|
110
|
+
it 'delegates to its app' do
|
111
111
|
app.should_receive(:endpoint_name_for)
|
112
112
|
.with(endpoint_name)
|
113
113
|
.and_return(normalized_endpoint_name)
|
@@ -117,10 +117,10 @@ describe StackerBee::Middleware::Base do
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
describe
|
121
|
-
describe
|
120
|
+
describe '#matches_content_type?' do
|
121
|
+
describe 'by default' do
|
122
122
|
before { env.response.content_type = '$8^02(324' }
|
123
|
-
it
|
123
|
+
it 'matches anything' do
|
124
124
|
middleware.matches_content_type?(env).should be_true
|
125
125
|
end
|
126
126
|
end
|
@@ -7,31 +7,31 @@ describe StackerBee::Middleware::CloudStackAPI do
|
|
7
7
|
path: path
|
8
8
|
)
|
9
9
|
end
|
10
|
-
let(:middleware) { described_class.new(api_key:
|
10
|
+
let(:middleware) { described_class.new(api_key: 'API-KEY', params: {}) }
|
11
11
|
let(:path) { nil }
|
12
12
|
|
13
13
|
before do
|
14
14
|
middleware.before(env)
|
15
15
|
end
|
16
16
|
|
17
|
-
describe
|
17
|
+
describe 'request' do
|
18
18
|
subject { env.request }
|
19
19
|
|
20
|
-
context
|
20
|
+
context 'when the path is not set' do
|
21
21
|
let(:path) { nil }
|
22
22
|
its(:path) { should == described_class::DEFAULT_PATH }
|
23
23
|
end
|
24
24
|
|
25
|
-
context
|
26
|
-
let(:path) {
|
25
|
+
context 'when the path is already set' do
|
26
|
+
let(:path) { 'already set' }
|
27
27
|
its(:path) { should == path }
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
describe
|
31
|
+
describe 'params' do
|
32
32
|
subject { env.request.params }
|
33
|
-
its([:api_key]) { should eq
|
34
|
-
its([:response]) { should eq
|
35
|
-
its([:command]) { should eq
|
33
|
+
its([:api_key]) { should eq 'API-KEY' }
|
34
|
+
its([:response]) { should eq 'json' }
|
35
|
+
its([:command]) { should eq 'endpoint-name' }
|
36
36
|
end
|
37
37
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe StackerBee::Middleware::ConsoleAccess do
|
4
4
|
let(:env) do
|
@@ -8,15 +8,15 @@ describe StackerBee::Middleware::ConsoleAccess do
|
|
8
8
|
let(:middleware) { described_class.new(app: app) }
|
9
9
|
let(:app) { double(:app) }
|
10
10
|
|
11
|
-
context
|
11
|
+
context 'when it matches the endpoint' do
|
12
12
|
let(:endpoint_name) { described_class::ENDPOINT }
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'adds its path to the env' do
|
15
15
|
middleware.before(env)
|
16
16
|
env.request.path.should == described_class::PATH
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'adds cmd to the parameters' do
|
20
20
|
env.request.params.should_not include described_class::PARAMS
|
21
21
|
end
|
22
22
|
end
|
@@ -35,22 +35,22 @@ describe StackerBee::Middleware::ConsoleAccess do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
39
|
-
middleware.content_types.should =~
|
38
|
+
it 'matches html content typtes' do
|
39
|
+
middleware.content_types.should =~ 'text/html; charset=utf-8'
|
40
40
|
end
|
41
41
|
|
42
|
-
describe
|
43
|
-
context
|
42
|
+
describe '#endpoint_name_for' do
|
43
|
+
context 'given names it reponds to' do
|
44
44
|
%w(consoleAccess console_access CONSOLEACCESS).each do |name|
|
45
45
|
subject { middleware.endpoint_name_for(name) }
|
46
46
|
it { should eq described_class::ENDPOINT }
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
context
|
50
|
+
context 'for other names' do
|
51
51
|
before { app.stub :endpoint_name_for, &:upcase }
|
52
52
|
|
53
|
-
it
|
53
|
+
it 'delegates for other names' do
|
54
54
|
middleware.endpoint_name_for('other-name').should == 'OTHER-NAME'
|
55
55
|
end
|
56
56
|
end
|
@@ -3,20 +3,20 @@ require 'spec_helper'
|
|
3
3
|
describe StackerBee::Middleware::DictionaryFlattener do
|
4
4
|
let(:lb) { described_class::LB }
|
5
5
|
let(:rb) { described_class::RB }
|
6
|
-
let(:string) {
|
6
|
+
let(:string) { 'cool[0].name%21' }
|
7
7
|
let(:tokenized_string) { "cool#{lb}0#{rb}.name%21" }
|
8
8
|
|
9
|
-
describe
|
9
|
+
describe '.detokenize' do
|
10
10
|
subject { described_class.detokenize(tokenized_string) }
|
11
11
|
it { should eq string }
|
12
12
|
end
|
13
13
|
|
14
|
-
describe
|
14
|
+
describe '.tokenize' do
|
15
15
|
subject { described_class.tokenize(string) }
|
16
16
|
it { should eq tokenized_string }
|
17
17
|
end
|
18
18
|
|
19
|
-
describe
|
19
|
+
describe '.new' do
|
20
20
|
subject { described_class.new.transform_params(params) }
|
21
21
|
|
22
22
|
def param(number)
|
@@ -24,38 +24,38 @@ describe StackerBee::Middleware::DictionaryFlattener do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
let(:params) do
|
27
|
-
{
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
{ 'time' => 'long ago',
|
28
|
+
'rebels' => {
|
29
|
+
'r2' => 'd2',
|
30
|
+
'blank' => '',
|
31
|
+
'falsey' => 'false',
|
32
|
+
'false' => false,
|
33
|
+
'droid' => true } }
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
subject["#{param(0)}.name"].should eq
|
38
|
-
subject["#{param(0)}.key"].should eq
|
39
|
-
subject["#{param(0)}.value"].should eq
|
36
|
+
it 'flattens objects in the manner that cloudstack expects' do
|
37
|
+
subject["#{param(0)}.name"].should eq 'r2'
|
38
|
+
subject["#{param(0)}.key"].should eq 'r2'
|
39
|
+
subject["#{param(0)}.value"].should eq 'd2'
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
42
|
+
it 'does not flatten empty hashes' do
|
43
43
|
subject.should_not have_key "#{param(2)}.name"
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
47
|
-
subject["#{param(1)}.name"].should eq
|
46
|
+
it 'handles true booleans' do
|
47
|
+
subject["#{param(1)}.name"].should eq 'droid'
|
48
48
|
subject["#{param(1)}.value"].should be_true
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
52
|
-
subject.should_not have_key
|
51
|
+
it 'removes original map params' do
|
52
|
+
subject.should_not have_key 'rebels'
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
55
|
+
it 'doesnt send false to CloudStack' do
|
56
56
|
# This assumption is based on CloudStack UI behavior
|
57
57
|
subject.values.should_not include false
|
58
|
-
subject.values.should_not include
|
58
|
+
subject.values.should_not include 'false'
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -12,15 +12,15 @@ describe StackerBee::Middleware::EndpointNormalizer do
|
|
12
12
|
let(:api) { {} }
|
13
13
|
let(:endpoint_name) { :some_endpoint }
|
14
14
|
|
15
|
-
describe
|
15
|
+
describe '#endpoint_name_for' do
|
16
16
|
before { app.stub :endpoint_name_for, &:upcase }
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'delegates to its app' do
|
19
19
|
middleware.endpoint_name_for('some-name').should == 'SOME-NAME'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
23
|
+
describe '#before' do
|
24
24
|
before { app.stub endpoint_name_for: nil }
|
25
25
|
|
26
26
|
it "doesn't set the endpoint to nil", :regression do
|
@@ -30,5 +30,5 @@ describe StackerBee::Middleware::EndpointNormalizer do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
context
|
33
|
+
context 'when it matches an endpoint'
|
34
34
|
end
|
@@ -12,22 +12,22 @@ describe StackerBee::Middleware::ErrorMessage do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
let(:body) { { errortext: message } }
|
15
|
-
let(:message) {
|
15
|
+
let(:message) { 'Unable to execute API command deployvirtualmachine ' }
|
16
16
|
let(:is_success?) { true }
|
17
17
|
|
18
18
|
it "doesn't apply to HTML responses" do
|
19
|
-
middleware.content_types.should_not match(
|
19
|
+
middleware.content_types.should_not match('text/html; charset=utf-8')
|
20
20
|
end
|
21
|
-
it
|
22
|
-
middleware.content_types.should match(
|
21
|
+
it 'applies to JSON responses' do
|
22
|
+
middleware.content_types.should match('text/javascript; charset=utf-8')
|
23
23
|
end
|
24
24
|
|
25
|
-
context
|
25
|
+
context 'given an error' do
|
26
26
|
let(:is_success?) { false }
|
27
27
|
its(:error) { should eq message }
|
28
28
|
end
|
29
29
|
|
30
|
-
context
|
30
|
+
context 'given a success' do
|
31
31
|
let(:is_success?) { true }
|
32
32
|
its(:error) { should be_nil }
|
33
33
|
end
|
@@ -10,9 +10,9 @@ describe StackerBee::Middleware::FormatKeys do
|
|
10
10
|
}
|
11
11
|
end
|
12
12
|
|
13
|
-
it { should have_key
|
13
|
+
it { should have_key 'symbol' }
|
14
14
|
it { should_not have_key :symbol }
|
15
15
|
|
16
|
-
it { should have_key
|
16
|
+
it { should have_key 'keyCase' }
|
17
17
|
it { should_not have_key :key_case }
|
18
18
|
end
|
@@ -13,7 +13,7 @@ describe StackerBee::Middleware::HTTPStatus do
|
|
13
13
|
end
|
14
14
|
let(:body) { { errorcode: http_status } }
|
15
15
|
|
16
|
-
context
|
16
|
+
context 'given an error' do
|
17
17
|
let(:http_status) { 431 }
|
18
18
|
let(:success?) { false }
|
19
19
|
|
@@ -21,7 +21,7 @@ describe StackerBee::Middleware::HTTPStatus do
|
|
21
21
|
it { should_not be_success }
|
22
22
|
end
|
23
23
|
|
24
|
-
context
|
24
|
+
context 'given a success' do
|
25
25
|
let(:http_status) { 200 }
|
26
26
|
let(:success?) { true }
|
27
27
|
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe StackerBee::Middleware::LogResponse do
|
3
|
-
describe
|
3
|
+
describe 'after' do
|
4
4
|
let(:logger) { FakeLogger.new }
|
5
5
|
|
6
6
|
let(:env) do
|
7
7
|
env = StackerBee::Middleware::Environment.new(logger: logger)
|
8
|
-
env.raw_response = { body:
|
9
|
-
env.request.params = {
|
10
|
-
env.request.path =
|
8
|
+
env.raw_response = { body: 'some body' }
|
9
|
+
env.request.params = { 'command' => 'some command' }
|
10
|
+
env.request.path = 'some/path'
|
11
11
|
env
|
12
12
|
end
|
13
13
|
|
14
|
-
shared_examples_for
|
15
|
-
it
|
14
|
+
shared_examples_for 'all logs' do
|
15
|
+
it 'logs the details' do
|
16
16
|
logger.logs.length.should eq 1
|
17
17
|
logger.logs.last[:request_path].should eq env.request.path
|
18
18
|
logger.logs.last[:params].should eq env.request.params.to_a
|
@@ -20,30 +20,30 @@ describe StackerBee::Middleware::LogResponse do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
context
|
23
|
+
context 'error response' do
|
24
24
|
before do
|
25
25
|
env.response.success = false
|
26
|
-
env.response.error =
|
26
|
+
env.response.error = 'invalid request'
|
27
27
|
subject.after(env)
|
28
28
|
end
|
29
29
|
|
30
|
-
it_should_behave_like
|
31
|
-
it
|
30
|
+
it_should_behave_like 'all logs'
|
31
|
+
it 'should have logged the details' do
|
32
32
|
logger.logs.last[:short_message].should eq \
|
33
|
-
|
33
|
+
'some command failed: invalid request'
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
context
|
37
|
+
context 'success response' do
|
38
38
|
before do
|
39
39
|
env.response.success = true
|
40
40
|
subject.after(env)
|
41
41
|
end
|
42
42
|
|
43
|
-
it_should_behave_like
|
44
|
-
it
|
43
|
+
it_should_behave_like 'all logs'
|
44
|
+
it 'should have logged the details' do
|
45
45
|
logger.logs.length.should eq 1
|
46
|
-
logger.logs.last[:short_message].should eq
|
46
|
+
logger.logs.last[:short_message].should eq 'some command'
|
47
47
|
end
|
48
48
|
|
49
49
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
# TODO: does this really need to work with nested hashes?
|
4
4
|
describe StackerBee::Middleware::RemoveEmptyStrings do
|
@@ -40,15 +40,15 @@ describe StackerBee::Middleware::RemoveEmptyStrings do
|
|
40
40
|
middleware.call(env)
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'removes empty strings from the input' do
|
44
44
|
params.keys.should =~ [:ok1, :ok2, :ok3, :ok4, :nested]
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
47
|
+
it 'removes empty strings nested in hashes' do
|
48
48
|
params[:nested].keys.should =~ [:ok1, :ok2, :ok3, :ok4, :nested]
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it 'removes empty strings deeply nested in hashes' do
|
52
52
|
params[:nested][:nested].keys.should =~ [:ok1, :ok2, :ok3, :ok4]
|
53
53
|
end
|
54
54
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe StackerBee::Middleware::RemoveNils do
|
4
|
-
it
|
4
|
+
it 'removes pairs with nil values from the params' do
|
5
5
|
subject.transform_params(something: 'something', nothing: nil)
|
6
6
|
.should eq something: 'something'
|
7
7
|
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
shared_examples_for
|
3
|
+
shared_examples_for 'a Rash' do |mapping|
|
4
4
|
mapping.each_pair { |key, value| its([key]) { should == value } }
|
5
5
|
end
|
6
6
|
|
7
7
|
describe StackerBee::Rash do
|
8
8
|
subject { rash }
|
9
9
|
|
10
|
-
let(:wiz) { [{
|
10
|
+
let(:wiz) { [{ 'aB_C' => 'abc' }, { 'X_yZ' => 'xyz' }] }
|
11
11
|
let(:ziz) do
|
12
12
|
{
|
13
|
-
|
14
|
-
|
13
|
+
'M-om' => {
|
14
|
+
'kI_d' => 2
|
15
15
|
}
|
16
16
|
}
|
17
17
|
end
|
18
18
|
let(:hash) do
|
19
19
|
{
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
'foo' => 'foo',
|
21
|
+
'b_iz' => 'biz',
|
22
|
+
'WiZ' => wiz,
|
23
23
|
:ziz => ziz
|
24
24
|
}
|
25
25
|
end
|
26
26
|
let(:similar_hash) do
|
27
27
|
hash.dup.tap do |loud|
|
28
|
-
value = loud.delete
|
29
|
-
loud[
|
28
|
+
value = loud.delete 'foo'
|
29
|
+
loud['FOO'] = value
|
30
30
|
end
|
31
31
|
end
|
32
|
-
let(:dissimilar_hash) { hash.dup.tap { |loud| loud.delete
|
32
|
+
let(:dissimilar_hash) { hash.dup.tap { |loud| loud.delete 'foo' } }
|
33
33
|
let(:rash) { described_class.new(hash) }
|
34
34
|
|
35
|
-
it { should include
|
35
|
+
it { should include 'FOO' }
|
36
36
|
|
37
37
|
it { should == subject }
|
38
38
|
it { should == subject.dup }
|
@@ -41,47 +41,47 @@ describe StackerBee::Rash do
|
|
41
41
|
it { should == similar_hash }
|
42
42
|
it { should_not == dissimilar_hash }
|
43
43
|
|
44
|
-
it_behaves_like
|
45
|
-
|
46
|
-
:foo =>
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
:biz =>
|
51
|
-
|
52
|
-
|
44
|
+
it_behaves_like 'a Rash',
|
45
|
+
'FOO' => 'foo',
|
46
|
+
:foo => 'foo',
|
47
|
+
'foo' => 'foo',
|
48
|
+
'f_oo' => 'foo',
|
49
|
+
'BIZ' => 'biz',
|
50
|
+
:biz => 'biz',
|
51
|
+
'biz' => 'biz',
|
52
|
+
'b_iz' => 'biz'
|
53
53
|
|
54
|
-
context
|
55
|
-
subject { rash[
|
56
|
-
it_behaves_like
|
54
|
+
context 'enumerable value' do
|
55
|
+
subject { rash['wiz'].first }
|
56
|
+
it_behaves_like 'a Rash', 'ab_c' => 'abc'
|
57
57
|
end
|
58
58
|
|
59
|
-
context
|
60
|
-
subject { rash[
|
61
|
-
it_behaves_like
|
59
|
+
context 'nested hash value' do
|
60
|
+
subject { rash['ziz'] }
|
61
|
+
it_behaves_like 'a Rash', 'mom' => { 'kid' => 2 }
|
62
62
|
|
63
|
-
context
|
64
|
-
subject { rash[
|
65
|
-
it_behaves_like
|
63
|
+
context 'deeply nested hash value' do
|
64
|
+
subject { rash['ziz']['mom'] }
|
65
|
+
it_behaves_like 'a Rash', 'kid' => 2
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
describe
|
70
|
-
subject { rash.select { |
|
69
|
+
describe '#select' do
|
70
|
+
subject { rash.select { |_, value| value.is_a? String } }
|
71
71
|
it { should be_a described_class }
|
72
|
-
it { should include
|
73
|
-
it { should_not include
|
72
|
+
it { should include 'FOO' }
|
73
|
+
it { should_not include 'WIZ' }
|
74
74
|
end
|
75
75
|
|
76
|
-
describe
|
77
|
-
subject { rash.reject { |
|
76
|
+
describe '#reject' do
|
77
|
+
subject { rash.reject { |_, value| value.is_a? String } }
|
78
78
|
it { should be_a described_class }
|
79
|
-
it { should include
|
80
|
-
it { should_not include
|
79
|
+
it { should include 'WIZ' }
|
80
|
+
it { should_not include 'FOO' }
|
81
81
|
end
|
82
82
|
|
83
|
-
describe
|
84
|
-
subject { rash.values_at
|
85
|
-
it { should == [
|
83
|
+
describe '#values_at' do
|
84
|
+
subject { rash.values_at 'FOO', 'WIZ', 'WRONG' }
|
85
|
+
it { should == ['foo', wiz, nil] }
|
86
86
|
end
|
87
87
|
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'An error occuring' do
|
4
4
|
let(:env) { double(response: response) }
|
5
5
|
let(:response) { double(status: status, error: error_text) }
|
6
|
-
let(:error_text) {
|
6
|
+
let(:error_text) { 'There was an error!' }
|
7
7
|
let(:status) { 431 }
|
8
8
|
|
9
|
-
describe StackerBee::RequestError,
|
9
|
+
describe StackerBee::RequestError, '.for' do
|
10
10
|
subject { described_class.for(env) }
|
11
11
|
|
12
|
-
context
|
12
|
+
context 'HTTP status in the 400s' do
|
13
13
|
let(:status) { 431 }
|
14
14
|
it { should be_a StackerBee::ClientError }
|
15
15
|
end
|
16
|
-
context
|
16
|
+
context 'HTTP status in the 500s' do
|
17
17
|
let(:status) { 500 }
|
18
18
|
it { should be_a StackerBee::ServerError }
|
19
19
|
end
|
20
|
-
context
|
20
|
+
context 'HTTP status > 599' do
|
21
21
|
let(:status) { 999 }
|
22
22
|
it { should be_a StackerBee::RequestError }
|
23
23
|
end
|