esp_sdk 1.0.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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +15 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +1185 -0
  9. data/Rakefile +9 -0
  10. data/esp_sdk.gemspec +33 -0
  11. data/lib/esp_sdk/api.rb +29 -0
  12. data/lib/esp_sdk/client.rb +59 -0
  13. data/lib/esp_sdk/configure.rb +36 -0
  14. data/lib/esp_sdk/end_points/base.rb +86 -0
  15. data/lib/esp_sdk/end_points/contact_requests.rb +6 -0
  16. data/lib/esp_sdk/end_points/custom_signatures.rb +41 -0
  17. data/lib/esp_sdk/end_points/dashboard.rb +30 -0
  18. data/lib/esp_sdk/end_points/external_accounts.rb +9 -0
  19. data/lib/esp_sdk/end_points/organizations.rb +6 -0
  20. data/lib/esp_sdk/end_points/reports.rb +6 -0
  21. data/lib/esp_sdk/end_points/services.rb +6 -0
  22. data/lib/esp_sdk/end_points/signatures.rb +39 -0
  23. data/lib/esp_sdk/end_points/sub_organizations.rb +6 -0
  24. data/lib/esp_sdk/end_points/teams.rb +6 -0
  25. data/lib/esp_sdk/end_points/users.rb +6 -0
  26. data/lib/esp_sdk/exceptions.rb +7 -0
  27. data/lib/esp_sdk/extensions/rest_client/request.rb +9 -0
  28. data/lib/esp_sdk/version.rb +3 -0
  29. data/lib/esp_sdk.rb +45 -0
  30. data/test/esp_sdk/api_test.rb +36 -0
  31. data/test/esp_sdk/client_test.rb +119 -0
  32. data/test/esp_sdk/configure_test.rb +49 -0
  33. data/test/esp_sdk/end_points/.keep +0 -0
  34. data/test/esp_sdk/end_points/base_test.rb +175 -0
  35. data/test/esp_sdk/end_points/custom_signatures_test.rb +90 -0
  36. data/test/esp_sdk/end_points/dashboard_test.rb +55 -0
  37. data/test/esp_sdk/end_points/external_accounts_test.rb +20 -0
  38. data/test/esp_sdk/end_points/signatures_test.rb +83 -0
  39. data/test/esp_sdk/exceptions_test.rb +35 -0
  40. data/test/esp_sdk_test.rb +70 -0
  41. data/test/test_helper.rb +20 -0
  42. metadata +264 -0
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class ConfigureTest < ActiveSupport::TestCase
4
+ context 'Configure' do
5
+ setup do
6
+ # Stub the setup token method
7
+ EspSdk::Configure.any_instance.expects(:token_setup).returns(nil).at_least_once
8
+ @config = EspSdk::Configure.new({email: 'test@test.com', token: 'token'})
9
+ end
10
+
11
+ context '#initialize' do
12
+ should 'set a default version of v1' do
13
+ assert_equal 'v1', @config.version
14
+ end
15
+ end
16
+
17
+ context '#uri' do
18
+ should 'return the production URI when the environment is production' do
19
+ EspSdk.expects(:production?).returns(true)
20
+ assert_equal 'https://api.evident.io/api', @config.uri
21
+ end
22
+
23
+ should 'return the release URI when the environment is release' do
24
+ EspSdk.expects(:production?).returns(false)
25
+ EspSdk.expects(:release?).returns(true)
26
+ assert_equal 'https://api-rel.evident.io/api', @config.uri
27
+ end
28
+
29
+ should 'return the development URI when the environment is not release or production' do
30
+ EspSdk.expects(:production?).returns(false)
31
+ EspSdk.expects(:release?).returns(false)
32
+ assert_equal 'http://0.0.0.0:3001/api', @config.uri
33
+ end
34
+ end
35
+
36
+ context '#token_setup' do
37
+ setup { EspSdk::Configure.any_instance.unstub(:token_setup) }
38
+
39
+ should 'should set the token and token and expires at' do
40
+ FakeWeb.register_uri(:get, /api\/v1\/token\/new/,
41
+ :body => { authentication_token: 'token',
42
+ token_expires_at: 1.hour.from_now }.to_json)
43
+ @config.send(:token_setup, { password: 'password1234' })
44
+ assert_not_nil @config.token
45
+ assert_not_nil @config.token_expires_at
46
+ end
47
+ end
48
+ end
49
+ end
File without changes
@@ -0,0 +1,175 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class BaseTest < ActiveSupport::TestCase
4
+ context 'Base' do
5
+ setup do
6
+ # Stub the token setup for our configuration object
7
+ EspSdk::Configure.any_instance.expects(:token_setup).returns(nil).at_least_once
8
+ @config = EspSdk::Configure.new(email: 'test@evident.io')
9
+ @base = EspSdk::EndPoints::Base.new(@config)
10
+ end
11
+
12
+ context '#next_page' do
13
+ setup do
14
+ # Setup fakeweb
15
+ FakeWeb.register_uri(:get, /api\/v1\/base/,
16
+ :body => { stub: 'Stub' }.to_json)
17
+ end
18
+
19
+ should 'call list if @current_page is blank' do
20
+ @base.expects(:list)
21
+ @base.next_page
22
+ end
23
+
24
+ should "return the current page if @page_links['links']' are blank" do
25
+ @base.expects(:current_page)
26
+ @base.next_page
27
+ end
28
+ end
29
+
30
+ context '#prev_page' do
31
+ setup do
32
+ # Setup fakeweb
33
+ FakeWeb.register_uri(:get, /api\/v1\/base/,
34
+ :body => { stub: 'Stub' }.to_json)
35
+ end
36
+
37
+ should 'call list if @current_page is blank' do
38
+ @base.expects(:list)
39
+ @base.prev_page
40
+ end
41
+
42
+ should "return the current page if @page_links['links']' are blank" do
43
+ @base.expects(:current_page)
44
+ @base.prev_page
45
+ end
46
+ end
47
+
48
+ context '#list' do
49
+ setup do
50
+ # Setup fakeweb
51
+ FakeWeb.register_uri(:get, /api\/v1\/base/,
52
+ :body => { stub: 'Stub' }.to_json)
53
+ end
54
+
55
+ should 'set the current page and setup link pagination' do
56
+ @base.expects(:pagination_links)
57
+ response = @base.list
58
+ assert response.key?('stub')
59
+ assert_equal response, @base.current_page
60
+ end
61
+ end
62
+
63
+ context '#show' do
64
+ setup do
65
+ # Setup fakeweb
66
+ FakeWeb.register_uri(:get, /api\/v1\/base\/1/,
67
+ :body => { stub: 'Stub' }.to_json)
68
+ end
69
+
70
+ should 'call validate id and return the stub response, and set the current_record' do
71
+ payload = { id: 1 }
72
+ @base.expects(:validate_id).with(payload)
73
+ response = @base.show(payload)
74
+ assert response.key?('stub')
75
+ assert_equal response, @base.current_record
76
+ end
77
+ end
78
+
79
+ context '#update' do
80
+ setup do
81
+ # Setup fakeweb
82
+ FakeWeb.register_uri(:get, /api\/v1\/base\/1/,
83
+ :body => { stub: 'Stub' }.to_json)
84
+ end
85
+
86
+ should 'call validate id and return the stub response, and set the current_record' do
87
+ payload = { id: 1, name: 'Test' }
88
+ @base.expects(:validate_id).with(payload)
89
+ response = @base.show(payload)
90
+ assert response.key?('stub')
91
+ assert_equal response, @base.current_record
92
+ end
93
+ end
94
+
95
+ context '#destroy' do
96
+ setup do
97
+ # Setup fakeweb
98
+ FakeWeb.register_uri(:get, /api\/v1\/base\/1/,
99
+ :body => { success: 'Stub has been destroyed' }.to_json)
100
+ end
101
+
102
+ should 'call validate id and return the stub response, and set the current_record' do
103
+ payload = { id: 1 }
104
+ @base.expects(:validate_id).with(payload)
105
+ response = @base.show(payload)
106
+ assert response.key?('success')
107
+ assert_equal response, @base.current_record
108
+ end
109
+ end
110
+
111
+ context '#validate_id' do
112
+ should 'return nil when an ID is present' do
113
+ assert_nil @base.send(:validate_id, { id: 1 })
114
+ end
115
+
116
+ should 'raise EspSdk::MissingAttribute for a missing id' do
117
+ e = assert_raises EspSdk::MissingAttribute do
118
+ @base.send(:validate_id, {})
119
+ end
120
+
121
+ assert_equal 'Missing required attribute id', e.message
122
+ end
123
+ end
124
+
125
+ context '#id_url' do
126
+ should 'return a valid id url for the test environment' do
127
+ # Test through a different endpoint to get a valid URL
128
+ EspSdk.instance_variable_set(:@env, :development)
129
+ external_account = EspSdk::EndPoints::ExternalAccounts.new(@config)
130
+ assert_equal 'http://0.0.0.0:3001/api/v1/external_accounts/1', external_account.send(:id_url, 1)
131
+ end
132
+
133
+ should 'return a valid id url for the release environment' do
134
+ EspSdk.instance_variable_set(:@env, :release)
135
+ config = EspSdk::Configure.new(email: 'test@evident.io')
136
+ # Test through a different endpoint to get a valid URL
137
+ external_account = EspSdk::EndPoints::ExternalAccounts.new(config)
138
+ assert_equal 'https://api-rel.evident.io/api/v1/external_accounts/1', external_account.send(:id_url, 1)
139
+ end
140
+
141
+ should 'return a valid id url for the production environment' do
142
+ EspSdk.instance_variable_set(:@env, :production)
143
+ config = EspSdk::Configure.new(email: 'test@evident.io')
144
+ # Test through a different endpoint to get a valid URL
145
+ external_account = EspSdk::EndPoints::ExternalAccounts.new(config)
146
+ assert_equal 'https://api.evident.io/api/v1/external_accounts/1', external_account.send(:id_url, 1)
147
+ end
148
+ end
149
+
150
+ context '#base_url' do
151
+ should 'return a valid base url for the development environment' do
152
+ # Test through a different endpoint to get a valid URL
153
+ EspSdk.instance_variable_set(:@env, :development)
154
+ external_account = EspSdk::EndPoints::ExternalAccounts.new(@config)
155
+ assert_equal 'http://0.0.0.0:3001/api/v1/external_accounts', external_account.send(:base_url)
156
+ end
157
+
158
+ should 'return a valid base url for the release environment' do
159
+ EspSdk.expects(:release?).returns(true)
160
+ config = EspSdk::Configure.new(email: 'test@evident.io')
161
+ # Test through a different endpoint to get a valid URL
162
+ external_account = EspSdk::EndPoints::ExternalAccounts.new(config)
163
+ assert_equal 'https://api-rel.evident.io/api/v1/external_accounts', external_account.send(:base_url)
164
+ end
165
+
166
+ should 'return a valid base url for the production environment' do
167
+ EspSdk.expects(:production?).returns(true)
168
+ config = EspSdk::Configure.new(email: 'test@evident.io')
169
+ # Test through a different endpoint to get a valid URL
170
+ external_account = EspSdk::EndPoints::ExternalAccounts.new(config)
171
+ assert_equal 'https://api.evident.io/api/v1/external_accounts', external_account.send(:base_url)
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,90 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class CustomSignaturesTest < ActiveSupport::TestCase
4
+ context 'CustomSignatures' do
5
+ setup do
6
+ # Stub the token setup for our configuration object
7
+ EspSdk::Configure.any_instance.expects(:token_setup).returns(nil).at_least_once
8
+ @config = EspSdk::Configure.new(email: 'test@evident.io')
9
+ @custom_signatures = EspSdk::EndPoints::CustomSignatures.new(@config)
10
+ end
11
+
12
+ context '#run' do
13
+ should 'call validate_run_params and submit' do
14
+ params = { id: 1, regiond: [:us_east_1], external_account_id: 1 }
15
+ valid_params = @custom_signatures.send(:valid_run_params)
16
+ @custom_signatures.expects(:validate_run_params).with(valid_params, params.keys)
17
+ run_url = @custom_signatures.send(:run_url)
18
+ @custom_signatures.expects(:submit).with(run_url, :post, params)
19
+ @custom_signatures.run(params)
20
+ end
21
+ end
22
+
23
+ context '#run_raw' do
24
+ should 'call validate_run_params and submit' do
25
+ params = { signature: 'test', regiond: [:us_east_1], external_account_id: 1 }
26
+ valid_params = @custom_signatures.send(:valid_run_raw_params)
27
+ @custom_signatures.expects(:validate_run_params).with(valid_params, params.keys)
28
+ run_url = @custom_signatures.send(:run_url)
29
+ @custom_signatures.expects(:submit).with(run_url, :post, params)
30
+ @custom_signatures.run_raw(params)
31
+ end
32
+ end
33
+
34
+ context '#run_url' do
35
+ should 'have the correct run_url for development environment' do
36
+ EspSdk.instance_variable_set(:@env, :development)
37
+ assert_equal 'http://0.0.0.0:3001/api/v1/custom_signatures/run', @custom_signatures.send(:run_url)
38
+ end
39
+
40
+ should 'have the correct run_url for the release environment' do
41
+ EspSdk.instance_variable_set(:@env, :release)
42
+ assert_equal 'https://api-rel.evident.io/api/v1/custom_signatures/run', @custom_signatures.send(:run_url)
43
+ end
44
+
45
+ should 'have the correct run_url for the production environment' do
46
+ EspSdk.instance_variable_set(:@env, :production)
47
+ assert_equal 'https://api.evident.io/api/v1/custom_signatures/run', @custom_signatures.send(:run_url)
48
+ end
49
+ end
50
+
51
+ context '#valid_run_params' do
52
+ should 'have the correct keys' do
53
+ valid_params = @custom_signatures.send(:valid_run_params)
54
+
55
+ [:id, :regions, :external_account_id].each do |key|
56
+ assert_includes valid_params, key
57
+ end
58
+ end
59
+ end
60
+
61
+ context '#valid_run_raw_params' do
62
+ should 'have the correct keys' do
63
+ valid_params = @custom_signatures.send(:valid_run_raw_params)
64
+ [:signature, :regions, :external_account_id].each do |key|
65
+ assert_includes valid_params, key
66
+ end
67
+ end
68
+ end
69
+
70
+ context '#validate_run_params' do
71
+ setup { @valid_params = @custom_signatures.send(:valid_run_params) }
72
+ should 'raise an error for a missing param' do
73
+ e = assert_raises EspSdk::MissingAttribute do
74
+ @custom_signatures.send(:validate_run_params, @valid_params, { id: 1, regions: [:us_east_1] })
75
+ end
76
+
77
+ assert_equal 'Missing required attribute external_account_id', e.message
78
+ end
79
+
80
+ should 'raise an error for an unknown attribute' do
81
+ e = assert_raises EspSdk::UnknownAttribute do
82
+ @custom_signatures.send(:validate_run_params, @valid_params, { id: 1, regions: [:us_east_1],
83
+ external_account_id: 1, bad_param: 1}.keys)
84
+ end
85
+
86
+ assert_equal 'Unknown attribute bad_param', e.message
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,55 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class DashboardTest < ActiveSupport::TestCase
4
+ context 'Dashboard' do
5
+ setup do
6
+ # Stub the token setup for our configuration object
7
+ EspSdk::Configure.any_instance.expects(:token_setup).returns(nil).at_least_once
8
+ @config = EspSdk::Configure.new(email: 'test@evident.io')
9
+ @dashboard = EspSdk::EndPoints::Dashboard.new(@config)
10
+ end
11
+
12
+ context '#timewarp' do
13
+ should 'call validate_timewarp_params and submit' do
14
+ params = { time: 1.hour.ago.to_i }
15
+ url = @dashboard.send(:timewarp_url)
16
+ @dashboard.expects(:validate_timewarp_params).with(params.keys)
17
+ @dashboard.expects(:submit).with(url, :post, params)
18
+ @dashboard.timewarp(params)
19
+ end
20
+ end
21
+
22
+ context '#timewarp_url' do
23
+ should 'have the correct run_url for development environment' do
24
+ EspSdk.instance_variable_set(:@env, :development)
25
+ assert_equal 'http://0.0.0.0:3001/api/v1/dashboard/timewarp', @dashboard.send(:timewarp_url)
26
+ end
27
+
28
+ should 'have the correct run_url for the release environment' do
29
+ EspSdk.instance_variable_set(:@env, :release)
30
+ assert_equal 'https://api-rel.evident.io/api/v1/dashboard/timewarp', @dashboard.send(:timewarp_url)
31
+ end
32
+
33
+ should 'have the correct run_url for the production environment' do
34
+ EspSdk.instance_variable_set(:@env, :production)
35
+ assert_equal 'https://api.evident.io/api/v1/dashboard/timewarp', @dashboard.send(:timewarp_url)
36
+ end
37
+ end
38
+
39
+ context '#validate_timewarp_params' do
40
+ should 'raise a MissingAttribute error for missing the time attribute' do
41
+ e = assert_raises EspSdk::MissingAttribute do
42
+ @dashboard.send(:validate_timewarp_params, [])
43
+ end
44
+ assert_equal 'Missing required attribute time', e.message
45
+ end
46
+
47
+ should 'raise a UnknownAttribute for an invalid attribute' do
48
+ e = assert_raises EspSdk::UnknownAttribute do
49
+ @dashboard.send(:validate_timewarp_params, [:time, :invalid])
50
+ end
51
+ assert_equal 'Unknown attribute invalid', e.message
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class ExternalAccountsTest < ActiveSupport::TestCase
4
+ context 'ExternalAccounts' do
5
+ setup do
6
+ # Stub the token setup for our configuration object
7
+ EspSdk::Configure.any_instance.expects(:token_setup).returns(nil).at_least_once
8
+ @config = EspSdk::Configure.new(email: 'test@evident.io')
9
+ @external_accounts = EspSdk::EndPoints::ExternalAccounts.new(@config)
10
+ end
11
+
12
+
13
+ context '#generate_external_id' do
14
+ should 'call SecureRandom.uuid' do
15
+ SecureRandom.expects(:uuid)
16
+ @external_accounts.generate_external_id
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,83 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class SignaturesTest < ActiveSupport::TestCase
4
+ context 'Signatures' do
5
+ setup do
6
+ # Stub the token setup for our configuration object
7
+ EspSdk::Configure.any_instance.expects(:token_setup).returns(nil).at_least_once
8
+ @config = EspSdk::Configure.new(email: 'test@evident.io')
9
+ @signatures = EspSdk::EndPoints::Signatures.new(@config)
10
+ end
11
+
12
+ context '#run' do
13
+ should 'call validate_run_params and submit' do
14
+ params = { signature_name: 'test', regions: [:us_east_1], external_account_id: 1 }
15
+ run_url = @signatures.send(:run_url)
16
+ @signatures.expects(:validate_run_params).with(params)
17
+ @signatures.expects(:submit).with(run_url, :post, params)
18
+ @signatures.run(params)
19
+ end
20
+ end
21
+
22
+ context '#names' do
23
+ should 'call submit' do
24
+ name_url = @signatures.send(:name_url)
25
+ @signatures.expects(:submit).with(name_url, :get)
26
+ @signatures.names
27
+ end
28
+ end
29
+
30
+ context '#run_url' do
31
+ should 'have the correct run_url for development environment' do
32
+ EspSdk.instance_variable_set(:@env, :development)
33
+ assert_equal 'http://0.0.0.0:3001/api/v1/signatures/run', @signatures.send(:run_url)
34
+ end
35
+
36
+ should 'have the correct run_url for the release environment' do
37
+ EspSdk.instance_variable_set(:@env, :release)
38
+ assert_equal 'https://api-rel.evident.io/api/v1/signatures/run', @signatures.send(:run_url)
39
+ end
40
+
41
+ should 'have the correct run_url for the production environment' do
42
+ EspSdk.instance_variable_set(:@env, :production)
43
+ assert_equal 'https://api.evident.io/api/v1/signatures/run', @signatures.send(:run_url)
44
+ end
45
+ end
46
+
47
+ context '#name_url' do
48
+ should 'have the correct run_url for development environment' do
49
+ EspSdk.instance_variable_set(:@env, :development)
50
+ assert_equal 'http://0.0.0.0:3001/api/v1/signatures/signature_names', @signatures.send(:name_url)
51
+ end
52
+
53
+ should 'have the correct run_url for the release environment' do
54
+ EspSdk.instance_variable_set(:@env, :release)
55
+ assert_equal 'https://api-rel.evident.io/api/v1/signatures/signature_names', @signatures.send(:name_url)
56
+ end
57
+
58
+ should 'have the correct run_url for the production environment' do
59
+ EspSdk.instance_variable_set(:@env, :production)
60
+ assert_equal 'https://api.evident.io/api/v1/signatures/signature_names', @signatures.send(:name_url)
61
+ end
62
+ end
63
+
64
+ context '#validate_run_params' do
65
+ should 'raise an error for a missing param' do
66
+ e = assert_raises EspSdk::MissingAttribute do
67
+ @signatures.send(:validate_run_params, { signature_name: 'test', regions: [:us_east_1] })
68
+ end
69
+
70
+ assert_equal 'Missing required attribute external_account_id', e.message
71
+ end
72
+
73
+ should 'raise an error for an unknown attribute' do
74
+ e = assert_raises EspSdk::UnknownAttribute do
75
+ @signatures.send(:validate_run_params, { signature_name: 'test', regions: [:us_east_1],
76
+ external_account_id: 1, bad_param: 1})
77
+ end
78
+
79
+ assert_equal 'Unknown attribute bad_param', e.message
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class ExceptionsTest < ActiveSupport::TestCase
4
+ context 'Exceptions' do
5
+ context 'MissingAttribute' do
6
+ should 'be a StandardError' do
7
+ assert EspSdk::MissingAttribute.new.is_a?(StandardError)
8
+ end
9
+ end
10
+
11
+ context 'UnknownAttribute' do
12
+ should 'be a StandardError' do
13
+ assert EspSdk::UnknownAttribute.new.is_a?(StandardError)
14
+ end
15
+ end
16
+
17
+ context 'TokenExpired' do
18
+ should 'be a StandardError' do
19
+ assert EspSdk::TokenExpired.new.is_a?(StandardError)
20
+ end
21
+ end
22
+
23
+ context 'RecordNotFound' do
24
+ should 'be a StandardError' do
25
+ assert EspSdk::RecordNotFound.new.is_a?(StandardError)
26
+ end
27
+ end
28
+
29
+ context 'Exception' do
30
+ should 'be a StandardError' do
31
+ assert EspSdk::Exception.new.is_a?(StandardError)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class EspSdkTest < ActiveSupport::TestCase
4
+ context 'EspSdk' do
5
+ context '#env' do
6
+ setup do
7
+ EspSdk.instance_variable_set(:@env, nil)
8
+ ENV['ESP_ENV'] = nil
9
+ end
10
+
11
+ should 'return :production when ENV is not set' do
12
+ ENV.expects(:[]).returns(nil).at_least_once
13
+ assert_equal :production, EspSdk.env
14
+ end
15
+
16
+ should 'return :release when ENV[ESP_ENV] is set to release' do
17
+ ENV.expects(:[]).returns('release').at_least_once
18
+ assert_equal :release, EspSdk.env
19
+ end
20
+ end
21
+
22
+ context '#production?' do
23
+ should 'return true when the environment is :production' do
24
+ EspSdk.expects(:env).returns(:production)
25
+ assert EspSdk.production?
26
+ end
27
+
28
+ should 'return false when the environment is not :production' do
29
+ EspSdk.expects(:env).returns(:release)
30
+ refute EspSdk.production?
31
+ end
32
+ end
33
+
34
+ context '#release?' do
35
+ should 'return true when the environment is :release' do
36
+ EspSdk.expects(:env).returns(:release)
37
+ assert EspSdk.release?
38
+ end
39
+
40
+ should 'return false when the environment is not :release' do
41
+ EspSdk.expects(:env).returns(:test)
42
+ refute EspSdk.release?
43
+ end
44
+ end
45
+
46
+ context '#development?' do
47
+ should 'return true when the environment is :development' do
48
+ EspSdk.expects(:env).returns(:development)
49
+ assert EspSdk.development?
50
+ end
51
+
52
+ should 'return false when the environment is not :development' do
53
+ EspSdk.expects(:env).returns(:test)
54
+ refute EspSdk.development?
55
+ end
56
+ end
57
+
58
+ context '#test?' do
59
+ should 'return true when the environment is :test' do
60
+ EspSdk.expects(:env).returns(:test)
61
+ assert EspSdk.test?
62
+ end
63
+
64
+ should 'return false when the environment is not :test' do
65
+ EspSdk.expects(:env).returns(:production)
66
+ refute EspSdk.test?
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,20 @@
1
+ ENV['ESP_ENV'] = 'test'
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+
5
+ require 'esp_sdk'
6
+ require 'minitest/autorun'
7
+ require 'minitest/reporters'
8
+ require 'shoulda'
9
+ require 'mocha'
10
+ require 'fakeweb'
11
+ require 'awesome_print'
12
+
13
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
14
+
15
+ class ActiveSupport::TestCase
16
+ setup do
17
+ # Clear stubs
18
+ FakeWeb.clean_registry
19
+ end
20
+ end