td 0.13.2 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,11 +22,11 @@ module TreasureData::Command
22
22
  }
23
23
  db_tables = create_tables.call(db.name)
24
24
 
25
- client.stub(:tables).with(db.name).and_return(db_tables)
25
+ allow(client).to receive(:tables).with(db.name).and_return(db_tables)
26
26
 
27
27
  command = Class.new { include TreasureData::Command }.new
28
- command.stub(:get_client).and_return(client)
29
- command.stub(:get_database).and_return(db)
28
+ allow(command).to receive(:get_client).and_return(client)
29
+ allow(command).to receive(:get_database).and_return(db)
30
30
 
31
31
  op = List::CommandParser.new('table:list', %w[], %w[db], false, %w(full_access_db), true)
32
32
  expect {
@@ -51,14 +51,14 @@ module TreasureData::Command
51
51
  fa_db_tables = create_tables.call(fa_db.name)
52
52
  own_db_tables = create_tables.call(own_db.name)
53
53
 
54
- client.stub(:databases).and_return([qo_db, fa_db, own_db])
54
+ allow(client).to receive(:databases).and_return([qo_db, fa_db, own_db])
55
55
 
56
- client.stub(:tables).with(qo_db.name).and_return(qo_db_tables)
57
- client.stub(:tables).with(fa_db.name).and_return(fa_db_tables)
58
- client.stub(:tables).with(own_db.name).and_return(own_db_tables)
56
+ allow(client).to receive(:tables).with(qo_db.name).and_return(qo_db_tables)
57
+ allow(client).to receive(:tables).with(fa_db.name).and_return(fa_db_tables)
58
+ allow(client).to receive(:tables).with(own_db.name).and_return(own_db_tables)
59
59
 
60
60
  command = Class.new { include TreasureData::Command }.new
61
- command.stub(:get_client).and_return(client)
61
+ allow(command).to receive(:get_client).and_return(client)
62
62
 
63
63
  op = List::CommandParser.new('table:list', %w[], %w[db], false, %w(), true)
64
64
  expect {
@@ -72,8 +72,8 @@ module TreasureData::Command
72
72
  db = TreasureData::Database.new(client, 'import_only_db', nil, 1234, Time.now.to_i, Time.now.to_i, nil, 'import_only')
73
73
 
74
74
  command = Class.new { include TreasureData::Command }.new
75
- command.stub(:get_client).and_return(client)
76
- command.stub(:get_database).and_return(db)
75
+ allow(command).to receive(:get_client).and_return(client)
76
+ allow(command).to receive(:get_database).and_return(db)
77
77
 
78
78
  op = List::CommandParser.new('table:list', %w[], %w[db], false, %w(import_only_db), true)
79
79
  expect {
@@ -99,15 +99,15 @@ module TreasureData::Command
99
99
  fa_db_tables = create_tables.call(fa_db.name)
100
100
  own_db_tables = create_tables.call(own_db.name)
101
101
 
102
- client.stub(:databases).and_return([io_db, qo_db, fa_db, own_db])
102
+ allow(client).to receive(:databases).and_return([io_db, qo_db, fa_db, own_db])
103
103
 
104
- client.stub(:tables).with(io_db.name).and_raise("not permitted")
105
- client.stub(:tables).with(qo_db.name).and_return(qo_db_tables)
106
- client.stub(:tables).with(fa_db.name).and_return(fa_db_tables)
107
- client.stub(:tables).with(own_db.name).and_return(own_db_tables)
104
+ allow(client).to receive(:tables).with(io_db.name).and_raise("not permitted")
105
+ allow(client).to receive(:tables).with(qo_db.name).and_return(qo_db_tables)
106
+ allow(client).to receive(:tables).with(fa_db.name).and_return(fa_db_tables)
107
+ allow(client).to receive(:tables).with(own_db.name).and_return(own_db_tables)
108
108
 
109
109
  command = Class.new { include TreasureData::Command }.new
110
- command.stub(:get_client).and_return(client)
110
+ allow(command).to receive(:get_client).and_return(client)
111
111
 
112
112
  op = List::CommandParser.new('table:list', %w[], %w[db], false, %w(), true)
113
113
  expect {
@@ -122,8 +122,8 @@ module TreasureData::Command
122
122
  let(:db) { TreasureData::Database.new(client, 'full_access_db', nil, 1000, Time.now.to_i, Time.now.to_i, nil, 'full_access') }
123
123
  let(:command) do
124
124
  command = Class.new { include TreasureData::Command }.new
125
- command.stub(:get_client).and_return(client)
126
- command.stub(:get_database).and_return(db)
125
+ allow(command).to receive(:get_client).and_return(client)
126
+ allow(command).to receive(:get_database).and_return(db)
127
127
  command
128
128
  end
129
129
 
@@ -135,7 +135,7 @@ module TreasureData::Command
135
135
  }
136
136
  }
137
137
  db_tables = create_tables.call(db.name)
138
- client.stub(:tables).with(db.name).and_return(db_tables)
138
+ allow(client).to receive(:tables).with(db.name).and_return(db_tables)
139
139
  end
140
140
 
141
141
  subject do
@@ -156,26 +156,26 @@ module TreasureData::Command
156
156
 
157
157
  context "without --format" do
158
158
  let(:options) { [] }
159
- it { should include(number_format) }
160
- it { should_not include(number_raw) }
159
+ it { is_expected.to include(number_format) }
160
+ it { is_expected.not_to include(number_raw) }
161
161
  end
162
162
 
163
163
  context "with --format table" do
164
164
  let(:options) { %w(--format table) }
165
- it { should include(number_format) }
166
- it { should_not include(number_raw) }
165
+ it { is_expected.to include(number_format) }
166
+ it { is_expected.not_to include(number_raw) }
167
167
  end
168
168
 
169
169
  context "with --format csv" do
170
170
  let(:options) { %w(--format csv) }
171
- it { should_not include(number_format) }
172
- it { should include(number_raw) }
171
+ it { is_expected.not_to include(number_format) }
172
+ it { is_expected.to include(number_raw) }
173
173
  end
174
174
 
175
175
  context "with --format tsv" do
176
176
  let(:options) { %w(--format tsv) }
177
- it { should_not include(number_format) }
178
- it { should include(number_raw) }
177
+ it { is_expected.not_to include(number_format) }
178
+ it { is_expected.to include(number_raw) }
179
179
  end
180
180
  end
181
181
  end
@@ -188,8 +188,8 @@ module TreasureData::Command
188
188
 
189
189
  describe 'auto create table' do
190
190
  before do
191
- command.stub(:get_client) { client }
192
- command.stub(:do_table_import)
191
+ allow(command).to receive(:get_client) { client }
192
+ allow(command).to receive(:do_table_import)
193
193
  end
194
194
 
195
195
  context 'set --auto-create-table' do
@@ -198,7 +198,7 @@ module TreasureData::Command
198
198
  }
199
199
 
200
200
  it 'create table' do
201
- command.should_receive(:create_database_and_table_if_not_exist).with(client, db_name, table_name)
201
+ expect(command).to receive(:create_database_and_table_if_not_exist).with(client, db_name, table_name)
202
202
  command.table_import(option)
203
203
  end
204
204
  end
@@ -209,7 +209,7 @@ module TreasureData::Command
209
209
  }
210
210
 
211
211
  it 'not create table' do
212
- command.should_not_receive(:create_database_and_table_if_not_exist)
212
+ expect(command).not_to receive(:create_database_and_table_if_not_exist)
213
213
  command.table_import(option)
214
214
  end
215
215
  end
@@ -217,8 +217,8 @@ module TreasureData::Command
217
217
 
218
218
  describe 'time key' do
219
219
  before do
220
- command.stub(:get_client) { client }
221
- command.stub(:do_table_import)
220
+ allow(command).to receive(:get_client) { client }
221
+ allow(command).to receive(:do_table_import)
222
222
  end
223
223
  let(:input_params) {{
224
224
  db_name: "database",
@@ -237,7 +237,7 @@ module TreasureData::Command
237
237
  end
238
238
 
239
239
  it "with '#{tk_option}' option" do
240
- command.should_receive(:do_table_import).with(client, input_params)
240
+ expect(command).to receive(:do_table_import).with(client, input_params)
241
241
  command.table_import(option)
242
242
  end
243
243
  end
@@ -253,7 +253,7 @@ module TreasureData::Command
253
253
  end
254
254
 
255
255
  it 'without \'-t / --time-key\' option' do
256
- command.should_receive(:do_table_import).with(client, input_params)
256
+ expect(command).to receive(:do_table_import).with(client, input_params)
257
257
  command.table_import(option)
258
258
  end
259
259
  end
@@ -274,19 +274,19 @@ module TreasureData::Command
274
274
  }
275
275
 
276
276
  before do
277
- command.stub(:get_client) { client }
278
- command.stub(:get_database).with(client, db_name).and_return(database)
277
+ allow(command).to receive(:get_client) { client }
278
+ allow(command).to receive(:get_database).with(client, db_name).and_return(database)
279
279
  end
280
280
 
281
281
  context "from table isn't exists" do
282
282
  let(:cmd_args) { [db_name, from_table_name, dest_table_name] }
283
283
 
284
284
  before do
285
- database.stub(:table).with(from_table_name).and_return { raise }
285
+ allow(database).to receive(:table).with(from_table_name) { raise }
286
286
  end
287
287
 
288
288
  it "can't rename table" do
289
- command.should_receive(:exit).with(1).and_return { raise CallSystemExitError }
289
+ expect(command).to receive(:exit).with(1) { raise CallSystemExitError }
290
290
 
291
291
  expect { command.table_rename(option) }.to raise_error
292
292
  expect(stderr_io.string).to include(from_table_name)
@@ -298,18 +298,18 @@ module TreasureData::Command
298
298
  let(:cmd_args) { [db_name, from_table_name, dest_table_name] }
299
299
 
300
300
  before do
301
- database.stub(:table).with(from_table_name).and_return
301
+ allow(database).to receive(:table).with(from_table_name)
302
302
  end
303
303
 
304
304
  context "dest_table isn't exists" do
305
305
  before do
306
- database.stub(:table).with(dest_table_name).and_return { raise }
306
+ allow(database).to receive(:table).with(dest_table_name) { raise }
307
307
  end
308
308
 
309
309
  it 'create dest table and rename table' do
310
- client.should_receive(:create_log_table).with(db_name, dest_table_name)
311
- client.should_receive(:swap_table).with(db_name, from_table_name, dest_table_name)
312
- client.should_receive(:delete_table).with(db_name, from_table_name)
310
+ expect(client).to receive(:create_log_table).with(db_name, dest_table_name)
311
+ expect(client).to receive(:swap_table).with(db_name, from_table_name, dest_table_name)
312
+ expect(client).to receive(:delete_table).with(db_name, from_table_name)
313
313
 
314
314
  command.table_rename(option)
315
315
 
@@ -320,11 +320,11 @@ module TreasureData::Command
320
320
 
321
321
  context "dest_tableis is exist" do
322
322
  before do
323
- database.stub(:table).with(dest_table_name).and_return
323
+ allow(database).to receive(:table).with(dest_table_name)
324
324
  end
325
325
 
326
326
  it "can't rename table" do
327
- command.should_receive(:exit).with(1).and_return { raise CallSystemExitError }
327
+ expect(command).to receive(:exit).with(1) { raise CallSystemExitError }
328
328
 
329
329
  expect { command.table_rename(option) }.to raise_error
330
330
  expect(stderr_io.string).not_to include(from_table_name)
@@ -337,18 +337,18 @@ module TreasureData::Command
337
337
  let(:cmd_args) { [db_name, from_table_name, dest_table_name, '--overwrite'] }
338
338
 
339
339
  before do
340
- database.stub(:table).with(from_table_name).and_return
340
+ allow(database).to receive(:table).with(from_table_name)
341
341
  end
342
342
 
343
343
  context "dest_table isn't exists" do
344
344
  before do
345
- database.stub(:table).with(dest_table_name).and_return { raise }
345
+ allow(database).to receive(:table).with(dest_table_name) { raise }
346
346
  end
347
347
 
348
348
  it 'create dest table and rename table' do
349
- client.should_receive(:create_log_table).with(db_name, dest_table_name)
350
- client.should_receive(:swap_table).with(db_name, from_table_name, dest_table_name)
351
- client.should_receive(:delete_table).with(db_name, from_table_name)
349
+ expect(client).to receive(:create_log_table).with(db_name, dest_table_name)
350
+ expect(client).to receive(:swap_table).with(db_name, from_table_name, dest_table_name)
351
+ expect(client).to receive(:delete_table).with(db_name, from_table_name)
352
352
 
353
353
  command.table_rename(option)
354
354
  expect(stderr_io.string).to include(from_table_name)
@@ -358,12 +358,12 @@ module TreasureData::Command
358
358
 
359
359
  context "dest_tableis is exist" do
360
360
  before do
361
- database.stub(:table).with(dest_table_name).and_return
361
+ allow(database).to receive(:table).with(dest_table_name)
362
362
  end
363
363
 
364
364
  it 'overwrite dest table' do
365
- client.should_receive(:swap_table).with(db_name, from_table_name, dest_table_name)
366
- client.should_receive(:delete_table).with(db_name, from_table_name)
365
+ expect(client).to receive(:swap_table).with(db_name, from_table_name, dest_table_name)
366
+ expect(client).to receive(:delete_table).with(db_name, from_table_name)
367
367
 
368
368
  command.table_rename(option)
369
369
  expect(stderr_io.string).to include(from_table_name)
@@ -8,14 +8,14 @@ module TreasureData::Command
8
8
  values = [0, 1, 10, 1023]
9
9
  values.each {|v|
10
10
  it "uses B as label and has no suffix (#{v})" do
11
- TreasureData::Command::humanize_bytesize(v, 1).should == "#{v} B"
11
+ expect(TreasureData::Command::humanize_bytesize(v, 1)).to eq("#{v} B")
12
12
  end
13
13
  }
14
14
  end
15
15
 
16
16
  describe 'for 1024' do
17
17
  it 'uses kB and does not have a suffix' do
18
- TreasureData::Command::humanize_bytesize(1024).should == "1 kB"
18
+ expect(TreasureData::Command::humanize_bytesize(1024)).to eq("1 kB")
19
19
  end
20
20
  end
21
21
  describe 'for values between 1025 and (1024^2 - 1)' do
@@ -35,7 +35,7 @@ module TreasureData::Command
35
35
 
36
36
  describe 'for 1024^2' do
37
37
  it 'uses MB and does not have a suffix' do
38
- TreasureData::Command::humanize_bytesize(1024 ** 2).should == "1 MB"
38
+ expect(TreasureData::Command::humanize_bytesize(1024 ** 2)).to eq("1 MB")
39
39
  end
40
40
  end
41
41
  describe 'for values between (1024^2 + 1) and (1024^3 - 1)' do
@@ -55,7 +55,7 @@ module TreasureData::Command
55
55
 
56
56
  describe 'for 1024^3' do
57
57
  it 'uses GB and does not have a suffix' do
58
- TreasureData::Command::humanize_bytesize(1024 ** 3).should == "1 GB"
58
+ expect(TreasureData::Command::humanize_bytesize(1024 ** 3)).to eq("1 GB")
59
59
  end
60
60
  end
61
61
  describe 'for values between (1024^3 + 1) and (1024^4 - 1)' do
@@ -75,7 +75,7 @@ module TreasureData::Command
75
75
 
76
76
  describe 'for 1024^4' do
77
77
  it 'uses TB and does not have a suffix' do
78
- TreasureData::Command::humanize_bytesize(1024 ** 4).should == "1 TB"
78
+ expect(TreasureData::Command::humanize_bytesize(1024 ** 4)).to eq("1 TB")
79
79
  end
80
80
  end
81
81
  describe 'for values between (1024^4 + 1) and (1024^5 - 1)' do
@@ -95,7 +95,7 @@ module TreasureData::Command
95
95
 
96
96
  describe 'for 1024^5' do
97
97
  it 'uses TB and does not have a suffix' do
98
- TreasureData::Command::humanize_bytesize(1024 ** 5).should == "1024 TB"
98
+ expect(TreasureData::Command::humanize_bytesize(1024 ** 5)).to eq("1024 TB")
99
99
  end
100
100
  end
101
101
  describe 'for values between (1024^5 + 1) and (1024^6 - 1)' do
@@ -183,8 +183,8 @@ module TreasureData::Command
183
183
  ret = indicator.update
184
184
  if ret == true
185
185
  diff = curr_time - last_time
186
- diff.should be >= 2
187
- diff.should be < 3
186
+ expect(diff).to be >= 2
187
+ expect(diff).to be < 3
188
188
  last_time = curr_time
189
189
  end
190
190
  sleep(0.5)
@@ -202,8 +202,8 @@ module TreasureData::Command
202
202
  while (curr_time = Time.now.to_i) < end_time do
203
203
  ret = indicator.update
204
204
  if ret == true
205
- (curr_time - last_time).should be >= periodicity
206
- (curr_time - last_time).should be < (periodicity + 1)
205
+ expect(curr_time - last_time).to be >= periodicity
206
+ expect(curr_time - last_time).to be < (periodicity + 1)
207
207
  last_time = curr_time
208
208
  end
209
209
  sleep(0.5)
@@ -235,13 +235,13 @@ module TreasureData::Command
235
235
 
236
236
  describe 'create database' do
237
237
  before do
238
- client.stub(:create_log_table)
238
+ allow(client).to receive(:create_log_table)
239
239
  end
240
240
 
241
241
  context 'client.database success' do
242
242
  it 'not call client.create_database' do
243
- client.should_receive(:database).with(database_name)
244
- client.should_not_receive(:create_database)
243
+ expect(client).to receive(:database).with(database_name)
244
+ expect(client).not_to receive(:create_database)
245
245
 
246
246
  call_create_database_and_table_if_not_exist
247
247
  expect(stderr_io.string).not_to include "Database '#{database_name}'"
@@ -250,12 +250,12 @@ module TreasureData::Command
250
250
 
251
251
  context 'client.database raise NotFoundError' do
252
252
  before do
253
- client.should_receive(:database).with(database_name).and_return { raise TreasureData::NotFoundError }
253
+ expect(client).to receive(:database).with(database_name) { raise TreasureData::NotFoundError }
254
254
  end
255
255
 
256
256
  context 'craet_database success' do
257
257
  it 'call client.create_database' do
258
- client.should_receive(:create_database).with(database_name)
258
+ expect(client).to receive(:create_database).with(database_name)
259
259
 
260
260
  call_create_database_and_table_if_not_exist
261
261
  expect(stderr_io.string).to include "Database '#{database_name}'"
@@ -264,7 +264,7 @@ module TreasureData::Command
264
264
 
265
265
  context 'craet_database raise AlreadyExistsError' do
266
266
  it 'resuce in method' do
267
- client.should_receive(:create_database).with(database_name).and_return { raise TreasureData::AlreadyExistsError }
267
+ expect(client).to receive(:create_database).with(database_name) { raise TreasureData::AlreadyExistsError }
268
268
 
269
269
  expect {
270
270
  call_create_database_and_table_if_not_exist
@@ -277,8 +277,8 @@ module TreasureData::Command
277
277
 
278
278
  context 'client.database raise ForbiddenError' do
279
279
  it 'not call client.create_database' do
280
- client.should_receive(:database).with(database_name).and_return { raise TreasureData::ForbiddenError }
281
- client.should_not_receive(:create_database)
280
+ expect(client).to receive(:database).with(database_name) { raise TreasureData::ForbiddenError }
281
+ expect(client).not_to receive(:create_database)
282
282
 
283
283
  call_create_database_and_table_if_not_exist
284
284
  expect(stderr_io.string).not_to include "Database '#{database_name}'"
@@ -288,12 +288,12 @@ module TreasureData::Command
288
288
 
289
289
  describe 'create table' do
290
290
  before do
291
- client.stub(:database)
291
+ allow(client).to receive(:database)
292
292
  end
293
293
 
294
294
  context 'create_log_table success' do
295
295
  it 'show message' do
296
- client.should_receive(:create_log_table).with(database_name, table_name)
296
+ expect(client).to receive(:create_log_table).with(database_name, table_name)
297
297
 
298
298
  call_create_database_and_table_if_not_exist
299
299
  expect(stderr_io.string).to include "Table '#{database_name}.#{table_name}'"
@@ -302,7 +302,7 @@ module TreasureData::Command
302
302
 
303
303
  context 'create_log_table raise AlreadyExistsError' do
304
304
  it 'resuce in method' do
305
- client.should_receive(:create_log_table).with(database_name, table_name).and_return { raise TreasureData::AlreadyExistsError }
305
+ expect(client).to receive(:create_log_table).with(database_name, table_name) { raise TreasureData::AlreadyExistsError }
306
306
 
307
307
  expect {
308
308
  call_create_database_and_table_if_not_exist
@@ -21,9 +21,9 @@ module TreasureData::Updater
21
21
 
22
22
  describe 'endpoints methods' do
23
23
  it 'use the default root path' do
24
- TreasureData::Updater.endpoint_root.should == default_toolbelt_url
25
- TreasureData::Updater.version_endpoint.should =~ Regexp.new(default_toolbelt_url)
26
- TreasureData::Updater.update_package_endpoint.should =~ Regexp.new(default_toolbelt_url)
24
+ expect(TreasureData::Updater.endpoint_root).to eq(default_toolbelt_url)
25
+ expect(TreasureData::Updater.version_endpoint).to match(Regexp.new(default_toolbelt_url))
26
+ expect(TreasureData::Updater.update_package_endpoint).to match(Regexp.new(default_toolbelt_url))
27
27
  end
28
28
  end
29
29
  end
@@ -34,9 +34,9 @@ module TreasureData::Updater
34
34
  end
35
35
  describe 'endpoints methods' do
36
36
  it 'use the custom root path' do
37
- TreasureData::Updater.endpoint_root.should == ENV['TD_TOOLBELT_UPDATE_ROOT']
38
- TreasureData::Updater.version_endpoint.should =~ Regexp.new(ENV['TD_TOOLBELT_UPDATE_ROOT'])
39
- TreasureData::Updater.update_package_endpoint.should =~ Regexp.new(ENV['TD_TOOLBELT_UPDATE_ROOT'])
37
+ expect(TreasureData::Updater.endpoint_root).to eq(ENV['TD_TOOLBELT_UPDATE_ROOT'])
38
+ expect(TreasureData::Updater.version_endpoint).to match(Regexp.new(ENV['TD_TOOLBELT_UPDATE_ROOT']))
39
+ expect(TreasureData::Updater.update_package_endpoint).to match(Regexp.new(ENV['TD_TOOLBELT_UPDATE_ROOT']))
40
40
  end
41
41
  end
42
42
  after do
@@ -137,13 +137,13 @@ module TreasureData::Updater
137
137
  subject { updater.kick }
138
138
 
139
139
  context "not updated" do
140
- before { updater.stub(:existent_jar_updated_time).and_return(Time.now) }
140
+ before { allow(updater).to receive(:existent_jar_updated_time).and_return(Time.now) }
141
141
 
142
142
  it_behaves_like "jar_update behavior"
143
143
  end
144
144
 
145
145
  context "updated" do
146
- before { updater.stub(:existent_jar_updated_time).and_return(Time.at(0)) }
146
+ before { allow(updater).to receive(:existent_jar_updated_time).and_return(Time.at(0)) }
147
147
 
148
148
  it_behaves_like "jar_update behavior"
149
149
  end