Skip to content

Commit 0f47ff0

Browse files
author
Stefanni Brasil
authored
Fix rubocop updates (#2708)
* Bump rubocop-minitest to 0.27.0 * fix rubocop-minitest offenses and improve test readibility * bump rubocop to 1.45.1 * Fix rubocop offence * Raises ArgumentError when receiving invalid arguments
1 parent 01e4c1e commit 0f47ff0

File tree

5 files changed

+50
-31
lines changed

5 files changed

+50
-31
lines changed

Gemfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ GEM
1717
method_source (1.0.0)
1818
minitest (5.17.0)
1919
parallel (1.22.1)
20-
parser (3.2.0.0)
20+
parser (3.2.1.0)
2121
ast (~> 2.4.1)
2222
power_assert (2.0.2)
2323
pry (0.14.2)
2424
coderay (~> 1.1)
2525
method_source (~> 1.0)
2626
rainbow (3.1.1)
2727
rake (13.0.6)
28-
regexp_parser (2.6.2)
28+
regexp_parser (2.7.0)
2929
rexml (3.2.5)
30-
rubocop (1.44.1)
30+
rubocop (1.45.1)
3131
json (~> 2.3)
3232
parallel (~> 1.10)
3333
parser (>= 3.2.0.0)
@@ -39,7 +39,7 @@ GEM
3939
unicode-display_width (>= 2.4.0, < 3.0)
4040
rubocop-ast (1.24.1)
4141
parser (>= 3.1.1.0)
42-
rubocop-minitest (0.25.1)
42+
rubocop-minitest (0.27.0)
4343
rubocop (>= 0.90, < 2.0)
4444
rubocop-rake (0.6.0)
4545
rubocop (~> 1.0)
@@ -66,8 +66,8 @@ DEPENDENCIES
6666
minitest (= 5.17.0)
6767
pry (= 0.14.2)
6868
rake (= 13.0.6)
69-
rubocop (= 1.44.1)
70-
rubocop-minitest (= 0.25.1)
69+
rubocop (= 1.45.1)
70+
rubocop-minitest (= 0.27.0)
7171
rubocop-rake (= 0.6.0)
7272
simplecov (= 0.22.0)
7373
test-unit (= 3.5.7)

faker.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Gem::Specification.new do |spec|
3232
spec.add_development_dependency('minitest', '5.17.0')
3333
spec.add_development_dependency('pry', '0.14.2')
3434
spec.add_development_dependency('rake', '13.0.6')
35-
spec.add_development_dependency('rubocop', '1.44.1')
36-
spec.add_development_dependency('rubocop-minitest', '0.25.1')
35+
spec.add_development_dependency('rubocop', '1.45.1')
36+
spec.add_development_dependency('rubocop-minitest', '0.27.0')
3737
spec.add_development_dependency('rubocop-rake', '0.6.0')
3838
spec.add_development_dependency('simplecov', '0.22.0')
3939
spec.add_development_dependency('test-unit', '3.5.7')

lib/faker/travel/airport.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class << self
1919
# @faker.version next
2020
def name(size:, region:)
2121
fetch("airport.#{region}.#{size}")
22-
rescue I18n::MissingTranslationData
23-
p 'valid arguments are size && region -> US has size large medium small, EU has size large medium -- united_states || european_union'
2422
end
2523

2624
##
@@ -38,8 +36,6 @@ def name(size:, region:)
3836
# @faker.version next
3937
def iata(size:, region:)
4038
fetch("airport.#{region}.iata_code.#{size}")
41-
rescue I18n::MissingTranslationData
42-
p 'valid arguments are size && region -> US has size large medium small, EU has size large medium -- united_states || european_union'
4339
end
4440
end
4541
end

test/faker/default/test_faker_json.rb

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,39 @@
33
class TestFakerJson < Test::Unit::TestCase
44
require 'json'
55

6-
def setup
7-
@tester = Faker::Json
6+
def test_simple_json_lenght
7+
expected_result_length = JSON.parse(simple_json).flatten.length
8+
9+
assert_same(expected_result_length, 6)
810
end
911

10-
def test_shallow_json
11-
json = Faker::Json.shallow_json(width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
12+
def test_nested_json_length
13+
result = Faker::Json.add_depth_to_json(json: simple_json, options: { key: 'Name.first_name', value: 'Name.first_name' })
14+
15+
first_json_length = JSON.parse(result).flatten[1].flatten.length
16+
second_json_length = JSON.parse(result).flatten[3].flatten.length
17+
third_json_length = JSON.parse(result).flatten[5].flatten.length
1218

13-
assert JSON.parse(json).flatten.length.equal?(6)
19+
assert_same(first_json_length, 6)
20+
assert_same(second_json_length, 6)
21+
assert_same(third_json_length, 6)
1422
end
1523

16-
def test_add_depth_to_json
17-
json = Faker::Json.shallow_json(width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
18-
json = Faker::Json.add_depth_to_json(json: json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
24+
def test_nested_json_width_length
25+
json = Faker::Json.add_depth_to_json(json: nested_json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
1926

20-
assert JSON.parse(json).flatten[1].flatten.length.equal?(6)
21-
assert JSON.parse(json).flatten[3].flatten.length.equal?(6)
22-
assert JSON.parse(json).flatten[5].flatten.length.equal?(6)
27+
first_json_length = JSON.parse(json).flatten[1].flatten[1].flatten.length
28+
second_json_length = JSON.parse(json).flatten[3].flatten[3].flatten.length
2329

24-
json = Faker::Json.add_depth_to_json(json: json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
30+
assert_same(first_json_length, 6)
31+
assert_same(second_json_length, 6)
32+
end
33+
34+
def simple_json
35+
Faker::Json.shallow_json(options: { key: 'Name.first_name', value: 'Name.first_name' })
36+
end
2537

26-
assert JSON.parse(json).flatten[1].flatten[1].flatten.length.equal?(6)
27-
assert JSON.parse(json).flatten[3].flatten[3].flatten.length.equal?(6)
28-
assert JSON.parse(json).flatten[5].flatten[5].flatten.length.equal?(6)
38+
def nested_json
39+
Faker::Json.add_depth_to_json(json: simple_json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
2940
end
3041
end

test/faker/travel/test_faker_airports.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,23 @@ def setup
77
@tester = Faker::Travel::Airport
88
end
99

10-
def name
11-
assert_match(/\w+/, @tester.name)
10+
def test_name
11+
assert_match(/\w+/, @tester.name(size: 'small', region: 'united_states'))
1212
end
1313

14-
def iata
15-
assert_match(/\w+/, @tester.iata)
14+
def test_iata
15+
assert_match(/\w+/, @tester.iata(size: 'small', region: 'united_states'))
16+
end
17+
18+
def test_name_with_invalid_arguments
19+
assert_raises ArgumentError do
20+
@tester.name(cats: 'meow', dogs: 'woof')
21+
end
22+
end
23+
24+
def test_iata_with_invalid_arguments
25+
assert_raises ArgumentError do
26+
@tester.iata(cats: 'meow', dogs: 'woof')
27+
end
1628
end
1729
end

0 commit comments

Comments
 (0)