Skip to content

Commit

Permalink
Fix for rubocop-rspec 0.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkn committed Dec 7, 2017
1 parent ff7cb07 commit ff598d9
Show file tree
Hide file tree
Showing 22 changed files with 103 additions and 102 deletions.
4 changes: 2 additions & 2 deletions spec/daru/io/exporters/avro_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
)
end

include_context 'exporter setup'
include_context 'with exporter setup'

let(:filename) { 'test.avro' }

before { described_class.new(df, schema).write(tempfile.path) }

context 'writes DataFrame to an Avro file' do
context 'when writes DataFrame to an Avro file' do
context 'when schema is Hash' do
let(:schema) do
{
Expand Down
14 changes: 7 additions & 7 deletions spec/daru/io/exporters/csv_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
RSpec.describe Daru::IO::Exporters::CSV do
subject { File.open(tempfile.path, &:readline).chomp.split(',', -1) }

include_context 'exporter setup'
include_context 'with exporter setup'

let(:filename) { 'test.csv' }

before { described_class.new(df, opts).write(tempfile.path) }

context 'writes DataFrame to a CSV file' do
context 'when writes DataFrame to a CSV file' do
subject { Daru::DataFrame.rows content[1..-1].map { |x| x.map { |y| convert(y) } }, order: content[0] }

let(:opts) { {} }
Expand All @@ -25,20 +25,20 @@
]
end

context 'writes headers unless headers=false' do
context 'when writes headers unless headers=false' do
it { is_expected.to be_an(Array) }
it { is_expected.to eq(df.vectors.to_a) }
end

context 'does not write headers when headers=false' do
context 'when does not write headers when headers=false' do
let(:headers) { false }
let(:opts) { {headers: headers} }

it { is_expected.to be_an(Array) }
it { is_expected.to eq(df.head(1).map { |v| (v.first || '').to_s }) }
end

context 'writes convert_comma only on float values' do
context 'when writes convert_comma only on float values' do
subject { CSV.read(tempfile.path, col_sep: ';') }

let(:df) { Daru::DataFrame.new('a' => [1, 4.4, nil, 'Sr. Arthur']) }
Expand All @@ -47,7 +47,7 @@
it { is_expected.to eq([['a'], ['1'], ['4,4'], [''], ['Sr. Arthur']]) }
end

context 'writes into .csv.gz format' do
context 'when writes into .csv.gz format' do
subject { Zlib::GzipReader.new(open(tempfile.path)).read.split("\n") }

let(:opts) { {compression: :gzip} }
Expand All @@ -57,7 +57,7 @@
it { is_expected.to eq(['a,b,c,d', '1,11,a,', '2,22,g,23', '3,33,4,4', '4,44,5,a', '5,55,addadf,ff']) }
end

context 'writes into .csv.gz format with only order' do
context 'when writes into .csv.gz format with only order' do
subject { Zlib::GzipReader.new(open(tempfile.path)).read.split("\n") }

let(:df) { Daru::DataFrame.new('a' => [], 'b' => [], 'c' => [], 'd' => []) }
Expand Down
12 changes: 6 additions & 6 deletions spec/daru/io/exporters/excel_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
RSpec.describe Daru::IO::Exporters::Excel do
include_context 'exporter setup'
include_context 'with exporter setup'

let(:filename) { 'test_write.xls' }
let(:content) { Spreadsheet.open tempfile.path }
let(:opts) { {header: {color: :blue}, data: {color: :red}, index: {color: :green}} }

before { described_class.new(df, **opts).write(tempfile.path) }

context 'writes to excel spreadsheet' do
context 'when writes to excel spreadsheet' do
subject do
Daru::DataFrame.rows(
Spreadsheet.open(tempfile.path).worksheet(0).rows[1..-1].map(&:to_a),
Expand All @@ -29,25 +29,25 @@
]
end

context 'writes to excel spreadsheet with header formatting' do
context 'when writes to excel spreadsheet with header formatting' do
subject { Spreadsheet.open(tempfile.path).worksheet(0).rows[0].format(0).font.color }

it { is_expected.to eq(:blue) }
end

context 'writes to excel spreadsheet with index formatting' do
context 'when writes to excel spreadsheet with index formatting' do
subject { Spreadsheet.open(tempfile.path).worksheet(0).rows[1].format(0).font.color }

it { is_expected.to eq(:green) }
end

context 'writes to excel spreadsheet with data formatting' do
context 'when writes to excel spreadsheet with data formatting' do
subject { Spreadsheet.open(tempfile.path).worksheet(0).rows[1].format(1).font.color }

it { is_expected.to eq(:red) }
end

context 'writes to excel spreadsheet with multi-index' do
context 'when writes to excel spreadsheet with multi-index' do
subject { Spreadsheet.open(tempfile.path).worksheet(0).rows }

let(:df) do
Expand Down
16 changes: 8 additions & 8 deletions spec/daru/io/exporters/json_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RSpec.describe Daru::IO::Exporters::JSON do
include_context 'exporter setup'
include_context 'with exporter setup'

subject { JSON.parse(File.read(tempfile.path)) }

Expand All @@ -21,37 +21,37 @@

before { described_class.new(df, pretty: pretty, orient: orient, **opts).write(tempfile.path) }

context 'writes DataFrame with default jsonpath options' do
context 'when writes DataFrame with default jsonpath options' do
it { is_expected.to be_an(Array).and all be_a(Hash) }
its(:count) { is_expected.to eq(3) }
its('first.keys') { is_expected.to match_array(%w[name age sex]) }
end

context 'writes DataFrame with orient: :values' do
context 'when writes DataFrame with orient: :values' do
let(:orient) { :values }

it { is_expected.to be_an(Array).and all be_an(Array) }
its(:count) { is_expected.to eq(3) }
its(:first) { is_expected.to eq(['Jon Snow', 'Rhaegar Targaryen', 'Lyanna Stark']) }
end

context 'writes DataFrame with orient: :split' do
context 'when writes DataFrame with orient: :split' do
let(:orient) { :split }

it { is_expected.to be_a(Hash).and all be_an(Array) }
its(:count) { is_expected.to eq(3) }
its(:keys) { is_expected.to eq(%w[vectors index data]) }
end

context 'writes DataFrame with orient: :index' do
context 'when writes DataFrame with orient: :index' do
let(:orient) { :index }

it { is_expected.to be_an(Array).and all be_a(Hash) }
its(:count) { is_expected.to eq(3) }
its(:first) { is_expected.to eq('child' => {'sex' => 'Male', 'age' => 18, 'name' => 'Jon Snow'}) }
end

context 'writes DataFrame with nested jsonpath options' do
context 'when writes DataFrame with nested jsonpath options' do
let(:opts) { {name: '$.person.name', age: '$.person.age', sex: '$.gender', index: '$.relation'} }

it { is_expected.to be_an(Array).and all be_a(Hash) }
Expand All @@ -64,14 +64,14 @@
end
end

context 'writes DataFrame with dynamic jsonpath options' do
context 'when writes DataFrame with dynamic jsonpath options' do
let(:opts) { {age: '$.{index}.{name}.age', sex: '$.{index}.{name}.gender'} }

it { is_expected.to be_an(Array).and all be_a(Hash) }
its(:first) { is_expected.to eq('child' => {'Jon Snow' => {'age' => 18, 'gender' => 'Male'}}) }
end

context 'writes DataFrame with block manipulation' do
context 'when writes DataFrame with block manipulation' do
before do
described_class.new(df, orient: orient, pretty: pretty) do |json|
json.map { |j| [j.keys.first, j.values.first] }.to_h
Expand Down
6 changes: 3 additions & 3 deletions spec/daru/io/exporters/r_data_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
RSpec.describe Daru::IO::Exporters::RData do
subject { Daru::DataFrame.new(instance.send(variables[0].to_sym)) }

include_context 'exporter setup'
include_context 'with exporter setup'

let(:instance) { RSRuby.instance }
let(:filename) { 'test.RData' }
let(:variables) { instance.eval_R("load('#{tempfile.path}')") }

before { described_class.new(**opts).write(tempfile.path) }

context 'writes DataFrame to a RData file' do
let(:opts) { {:'first.df' => df, :'last.df' => df} }
context 'when writes DataFrame to a RData file' do
let(:opts) { {:'first.df' => df, :'last.df' => df} }

it_behaves_like 'exact daru dataframe',
ncols: 4,
Expand Down
4 changes: 2 additions & 2 deletions spec/daru/io/exporters/rds_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
RSpec.describe Daru::IO::Exporters::RDS do
subject { Daru::DataFrame.new(RSRuby.instance.eval_R("readRDS('#{tempfile.path}')")) }

include_context 'exporter setup'
include_context 'with exporter setup'

let(:variable) { 'test.dataframe' }
let(:filename) { 'test.rds' }

before { described_class.new(df, variable).write(tempfile.path) }

context 'writes DataFrame to a RDS file' do
context 'when writes DataFrame to a RDS file' do
it_behaves_like 'exact daru dataframe',
ncols: 4,
nrows: 5,
Expand Down
2 changes: 1 addition & 1 deletion spec/daru/io/exporters/sql_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RSpec.describe Daru::IO::Exporters::SQL do
include_context 'exporter setup'
include_context 'with exporter setup'

let(:dbh) { double }
let(:table) { 'test' }
Expand Down
3 changes: 2 additions & 1 deletion spec/daru/io/importers/active_record_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RSpec.describe Daru::IO::Importers::ActiveRecord do
include_context 'sqlite3 database setup'
include_context 'with sqlite3 database setup'

context 'without specifying field names' do
let(:fields) { [] }

Expand Down
6 changes: 3 additions & 3 deletions spec/daru/io/importers/avro_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

let(:path) { '' }

context 'on complex numbers avro file' do
context 'when on complex numbers avro file' do
let(:path) { 'spec/fixtures/avro/one_complex.avro' }

it_behaves_like 'exact daru dataframe',
Expand All @@ -13,7 +13,7 @@
data: [[100],[200]]
end

context 'on twitter avro file' do
context 'when on twitter avro file' do
let(:path) { 'spec/fixtures/avro/twitter.avro' }

it_behaves_like 'exact daru dataframe',
Expand Down Expand Up @@ -41,7 +41,7 @@
]
end

context 'on users avro file' do
context 'when on users avro file' do
let(:path) { 'spec/fixtures/avro/users.avro' }

it_behaves_like 'exact daru dataframe',
Expand Down
22 changes: 11 additions & 11 deletions spec/daru/io/importers/csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
let(:path) { 'spec/fixtures/csv/matrix_test.csv' }
let(:opts) { {col_sep: ' ', headers: true} }

context 'loads from a CSV file' do
context 'when loads from a CSV file' do
let('subject.vectors') { %I[image_resolution mls true_transform].to_index }

it_behaves_like 'exact daru dataframe',
Expand All @@ -31,7 +31,7 @@
',-0.3027024,4262.65,0,0,0,1'
end

context 'works properly for repeated headers' do
context 'when works properly for repeated headers' do
let(:path) { 'spec/fixtures/csv/repeated_fields.csv' }
let(:opts) { {header_converters: :symbol} }

Expand All @@ -42,7 +42,7 @@
age_2: Daru::Vector.new([3, 4, 5, 6, nil, 8])
end

context 'accepts scientific notation as float' do
context 'when accepts scientific notation as float' do
let(:path) { 'spec/fixtures/csv/scientific_notation.csv' }
let(:opts) { {order: %w[x y]} }
let(:df) { subject }
Expand All @@ -64,7 +64,7 @@
end
end

context 'follows the order of columns given in CSV' do
context 'when follows the order of columns given in CSV' do
let(:path) { 'spec/fixtures/csv/sales-funnel.csv' }
let(:opts) { {} }

Expand All @@ -74,7 +74,7 @@
order: %w[Account Name Rep Manager Product Quantity Price Status]
end

context 'parses empty dataframe from CSV with only headers' do
context 'when parses empty dataframe from CSV with only headers' do
let(:path) { 'spec/fixtures/csv/column_headers_only.csv' }
let(:opts) { {} }

Expand All @@ -84,7 +84,7 @@
order: %w[col0 col1 col2]
end

context 'skips rows from CSV files with headers option' do
context 'when skips rows from CSV files with headers option' do
let(:path) { 'spec/fixtures/csv/sales-funnel.csv' }
let(:opts) { {skiprows: 8, headers: true} }

Expand All @@ -94,7 +94,7 @@
order: %i[account manager name price product quantity rep status]
end

context 'skips rows from CSV files without headers option' do
context 'when skips rows from CSV files without headers option' do
let(:path) { 'spec/fixtures/csv/sales-funnel.csv' }
let(:opts) { {skiprows: 8} }

Expand All @@ -104,7 +104,7 @@
order: %w[Account Name Rep Manager Product Quantity Price Status]
end

context 'checks for boolean converter' do
context 'when checks for boolean converter' do
let(:path) { 'spec/fixtures/csv/boolean_converter_test.csv' }
let(:opts) { {converters: [:boolean]} }

Expand All @@ -114,15 +114,15 @@
its('Domestic.to_a') { is_expected.to all be_boolean }
end

context 'checks for skip_blanks option to skip empty rows' do
context 'when checks for skip_blanks option to skip empty rows' do
let(:path) { 'spec/fixtures/csv/empty_rows_test.csv' }

it_behaves_like 'exact daru dataframe',
ncols: 3,
nrows: 13
end

context 'checks for equal parsing of csv and csv.gz files' do
context 'when checks for equal parsing of csv and csv.gz files' do
ALL_CSV_FILES.each do |file|
before { Zlib::GzipWriter.open(path) { |gz| gz.write File.read(csv_path) } }

Expand All @@ -137,7 +137,7 @@
end
end

context 'checks for equal parsing of local CSV files and remote CSV files' do
context 'when checks for equal parsing of local CSV files and remote CSV files' do
ALL_CSV_FILES.each do |file|
let(:local) { described_class.read("spec/fixtures/csv/#{file}.csv").call }
let(:path) { "http://dummy-remote-url/#{file}.csv" }
Expand Down
2 changes: 1 addition & 1 deletion spec/daru/io/importers/excel_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RSpec.describe Daru::IO::Importers::Excel do
context 'loads from excel spreadsheet' do
context 'when loads from excel spreadsheet' do
subject { described_class.read(path).call }

let(:path) { 'spec/fixtures/excel/test_xls.xls' }
Expand Down
2 changes: 1 addition & 1 deletion spec/daru/io/importers/excelx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
end
end

context 'checks for equal parsing of local XLSX files and remote XLSX files' do
context 'when checks for equal parsing of local XLSX files and remote XLSX files' do
%w[LOBSTAHS_rt.windows Microcode Stock-counts-sheet].each do |file|
let(:local) { described_class.read("spec/fixtures/excelx/#{file}.xlsx").call }
let(:path) { "http://dummy-remote-url/#{file}.xlsx" }
Expand Down
Loading

0 comments on commit ff598d9

Please sign in to comment.