Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gem 'benchmark'
gem 'minitest', '5.25.5'
gem 'pry', '0.15.2'
gem 'rake', '13.3.1'
gem 'rubocop', '1.75.4'
gem 'rubocop', '1.81.7'
gem 'rubocop-minitest', '0.38.2'
gem 'rubocop-rake', '0.7.1'
gem 'simplecov', '0.22.0'
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ GEM
rainbow (3.1.1)
rake (13.3.1)
regexp_parser (2.11.3)
rubocop (1.75.4)
rubocop (1.81.7)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.44.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.48.0)
Expand Down Expand Up @@ -78,7 +78,7 @@ DEPENDENCIES
minitest (= 5.25.5)
pry (= 0.15.2)
rake (= 13.3.1)
rubocop (= 1.75.4)
rubocop (= 1.81.7)
rubocop-minitest (= 0.38.2)
rubocop-rake (= 0.7.1)
simplecov (= 0.22.0)
Expand Down
2 changes: 1 addition & 1 deletion lib/faker/books/lovecraft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def paragraph_by_chars(characters: 256)

paragraph += " #{paragraph(sentence_count: 3)}" while paragraph.length < characters

"#{paragraph[0...characters - 1]}."
"#{paragraph[0...(characters - 1)]}."
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/faker/default/boolean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class << self
# Faker::Boolean.boolean(true_ratio: 0.2) #=> false
#
# @faker.version 1.6.2
def boolean(true_ratio: 0.5)
#
def boolean(true_ratio: 0.5) # rubocop:disable Naming/PredicateMethod
(rand < true_ratio)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/faker/default/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def collect_regon_sum(array)

def weight_sum(array, weights)
sum = 0
(0..weights.size - 1).each do |index|
(0..(weights.size - 1)).each do |index|
sum += (array[index] * weights[index])
end
sum
Expand Down
2 changes: 1 addition & 1 deletion lib/faker/default/hipster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def paragraph_by_chars(characters: 256, supplemental: false)

paragraph += " #{paragraph(sentence_count: 3, supplemental: supplemental)}" while paragraph.length < characters

"#{paragraph[0...characters - 1]}."
"#{paragraph[0...(characters - 1)]}."
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/faker/default/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def element(tag: 'div', content: Lorem.sentence(word_count: 3), attributes: { cl
def random(exclude: [])
method_list = available_methods
exclude.each { |ex| method_list.delete_if { |meth| meth == ex.to_sym } }
send(method_list[Faker::Config.random.rand(0..method_list.length - 1)])
send(method_list[Faker::Config.random.rand(0..(method_list.length - 1))])
end

##
Expand Down
2 changes: 1 addition & 1 deletion lib/faker/default/lorem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def paragraph_by_chars(number: 256, supplemental: false)

paragraph += " #{paragraph(sentence_count: 3, supplemental: supplemental)}" while paragraph.length < number

"#{paragraph[0...number - 1]}."
"#{paragraph[0...(number - 1)]}."
end

##
Expand Down
4 changes: 2 additions & 2 deletions lib/faker/default/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def headers
def emphasis
paragraph = Faker::Lorem.paragraph(sentence_count: 3)
words = paragraph.split
position = rand(0..words.length - 1)
position = rand(0..(words.length - 1))
formatting = fetch('markdown.emphasis')
words[position] = "#{formatting}#{words[position]}#{formatting}"
words.join(' ')
Expand Down Expand Up @@ -133,7 +133,7 @@ def table
def random(*args)
method_list = available_methods
args&.each { |ex| method_list.delete_if { |meth| meth == ex.to_sym } }
send(method_list[Faker::Config.random.rand(0..method_list.length - 1)])
send(method_list[Faker::Config.random.rand(0..(method_list.length - 1))])
end

##
Expand Down
4 changes: 2 additions & 2 deletions lib/faker/default/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def rb_array(len: 1, type: -> { random_type })
#
# @faker.version 1.8.6
def random_type
type_to_use = SIMPLE_TYPES[rand(0..SIMPLE_TYPES.length - 1)]
type_to_use = SIMPLE_TYPES[rand(0..(SIMPLE_TYPES.length - 1))]
case type_to_use
when :string
rb_string
Expand All @@ -136,7 +136,7 @@ def random_type
# @faker.version 1.8.6
def random_complex_type
types = SIMPLE_TYPES + COMPLEX_TYPES
type_to_use = types[rand(0..types.length - 1)]
type_to_use = types[rand(0..(types.length - 1))]
case type_to_use
when :string
rb_string
Expand Down
6 changes: 3 additions & 3 deletions test/faker/default/test_faker_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ def test_imei_regexp
end

def test_imei_luhn_value
assert luhn_checksum_valid(@tester.imei)
assert luhn_checksum_valid?(@tester.imei)
end

def test_sin
assert_match(/\d{9}/, @tester.sin)
assert_equal(9, @tester.sin.length)
assert luhn_checksum_valid(@tester.sin)
assert luhn_checksum_valid?(@tester.sin)
end

def luhn_checksum_valid(numbers)
def luhn_checksum_valid?(numbers)
sum = 0
i = 0

Expand Down
4 changes: 2 additions & 2 deletions test/faker/default/test_faker_company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def test_spanish_b_algorithm
end

def text_indian_gst_number
assert_match(/^([0-2][0-9]|[3][0-7])[A-Z]{3}[ABCFGHLJPTK][A-Z]\d{4}[A-Z][A-Z0-9][Z][A-Z0-9]$/i, @tester.indian_gst_number)
assert_match(/^([0-2][0-9]|3[0-7])[A-Z]{3}[ABCFGHLJPTK][A-Z]\d{4}[A-Z][A-Z0-9]Z[A-Z0-9]$/i, @tester.indian_gst_number)
end

def test_state_code_in_indian_gst_number
Expand All @@ -264,7 +264,7 @@ def test_state_code_in_indian_gst_number
end

def test_indian_gst_number_with_state_code
assert_match(/^(22)[A-Z]{3}[ABCFGHLJPTK][A-Z]\d{4}[A-Z][A-Z0-9][Z][A-Z0-9]$/i, @tester.indian_gst_number(state_code: '22'))
assert_match(/^(22)[A-Z]{3}[ABCFGHLJPTK][A-Z]\d{4}[A-Z][A-Z0-9]Z[A-Z0-9]$/i, @tester.indian_gst_number(state_code: '22'))
end

private
Expand Down
14 changes: 7 additions & 7 deletions test/faker/default/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_email_against_name_generator
deterministically_verify -> { @tester.email(name: Faker::Name.unique.name) } do |email|
# reject emails with duplicated punctuation
# e.g.: "mr._faker.jr.@example.com"
refute_match(/[\p{Punct}]{2,}/, email)
refute_match(/\p{Punct}{2,}/, email)
end
end

Expand Down Expand Up @@ -108,7 +108,7 @@ def test_username
end

def test_username_with_apostrophes
assert_match(/\A[a-z]+([_\.][a-z]+)*\z/, @tester.username(specifier: "Alexis O'Connell"))
assert_match(/\A[a-z]+([_.][a-z]+)*\z/, @tester.username(specifier: "Alexis O'Connell"))
end

def test_user_name_alias
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_username_with_closed_range_arg

def test_username_with_open_range_arg
(1..32).each do |min_length|
(min_length + 1..33).each do |max_length|
((min_length + 1)..33).each do |max_length|
l = @tester.username(specifier: (min_length...max_length)).length

assert_operator l, :>=, min_length
Expand All @@ -165,7 +165,7 @@ def test_username_with_open_range_arg

def test_username_with_range_and_separators
(1..32).each do |min_length|
(min_length + 1..33).each do |max_length|
((min_length + 1)..33).each do |max_length|
u = @tester.username(specifier: (min_length...max_length), separators: %w[=])

assert u.length.between? min_length, max_length - 1
Expand Down Expand Up @@ -270,14 +270,14 @@ def test_password_with_special_chars_and_mixed_case
password = @tester.password(min_length: 4, max_length: 6, mix_case: true, special_characters: true)

assert_match(/[!@#$%\^&*]+/, password)
assert_match(/[A-z]+/, password)
assert_match(/[A-Za-z]+/, password)
end
end

def test_deterministic_password_with_special_chars_and_mixed_case
deterministically_verify -> { @tester.password(min_length: 4, max_length: 6, mix_case: true, special_characters: true) }, depth: 4 do |password|
assert_match(/[!@#$%\^&*]+/, password)
assert_match(/[A-z]+/, password)
assert_match(/[A-Za-z]+/, password)
end
end

Expand All @@ -286,7 +286,7 @@ def test_password_with_special_chars_and_mixed_case_on_3chars_password
password = @tester.password(min_length: 3, max_length: 6, mix_case: true, special_characters: true)

assert_match(/[!@#$%\^&*]+/, password)
assert_match(/[A-z]+/, password)
assert_match(/[A-Za-z]+/, password)
end
end

Expand Down
12 changes: 6 additions & 6 deletions test/faker/default/test_faker_lorem_flickr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_image_with_search_terms_and_match_all
end

def test_grayscale_image
@tester.grayscale_image == 'https://loremflickr.com/g/300/300/all'
assert_equal('https://loremflickr.com/g/300/300/all', @tester.grayscale_image)
end

def test_grayscale_image_with_incorrect_size
Expand All @@ -45,7 +45,7 @@ def test_grayscale_image_with_incorrect_size
end

def test_grayscale_image_without_search_terms
@tester.grayscale_image(size: '50x60') == 'https://loremflickr.com/g/50/60/all'
assert_equal('https://loremflickr.com/g/50/60/all', @tester.grayscale_image(size: '50x60'))
end

def test_grayscale_image_with_single_search_term
Expand All @@ -61,7 +61,7 @@ def test_grayscale_image_with_search_terms_and_match_all
end

def test_pixelated_image
@tester.pixelated_image == 'https://loremflickr.com/p/300/300/all'
assert_equal('https://loremflickr.com/p/300/300/all', @tester.pixelated_image)
end

def test_pixelated_image_with_incorrect_size
Expand All @@ -71,7 +71,7 @@ def test_pixelated_image_with_incorrect_size
end

def test_pixelated_image_without_search_terms
@tester.pixelated_image(size: '50x60') == 'https://loremflickr.com/p/50/60/all'
assert_equal('https://loremflickr.com/p/50/60/all', @tester.pixelated_image(size: '50x60'))
end

def test_pixelated_image_with_single_search_term
Expand All @@ -87,7 +87,7 @@ def test_pixelated_image_with_search_terms_and_match_all
end

def test_colorized_image
@tester.colorized_image == 'https://loremflickr.com/red/300/300/all'
assert_equal('https://loremflickr.com/red/300/300/all', @tester.colorized_image)
end

def test_colorized_image_with_incorrect_size
Expand All @@ -97,7 +97,7 @@ def test_colorized_image_with_incorrect_size
end

def test_colorized_image_without_search_terms
@tester.colorized_image(size: '50x60', color: 'red') == 'https://loremflickr.com/red/50/60/all'
assert_equal('https://loremflickr.com/red/50/60/all', @tester.colorized_image(size: '50x60', color: 'red'))
end

def test_colorized_image_with_unsupported_colorization
Expand Down
2 changes: 1 addition & 1 deletion test/faker/default/test_faker_markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ def test_sandwich

def random_method
method_list = Faker::Markdown.public_methods(false) - Faker::Base.methods
method_list[rand(0..method_list.length - 1)]
method_list[rand(0..(method_list.length - 1))]
end
end
10 changes: 5 additions & 5 deletions test/faker/default/test_faker_vehicle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def setup
end

def test_vin
assert valid_vin('11111111111111111') # known valid test string
assert valid_vin('FAKERGEM5FAKERGEM') # valid checksum
refute valid_vin('ABCDEFGH123456789') # invalid checksum
assert valid_vin?('11111111111111111') # known valid test string
assert valid_vin?('FAKERGEM5FAKERGEM') # valid checksum
refute valid_vin?('ABCDEFGH123456789') # invalid checksum

deterministically_verify -> { @tester.vin }, depth: 4 do |vin|
assert valid_vin(vin)
assert valid_vin?(vin)
end
end

Expand Down Expand Up @@ -117,7 +117,7 @@ def doors_condition(doors)
assert_kind_of Integer, doors
end

def valid_vin(vin)
def valid_vin?(vin)
if vin && vin =~ VIN_REGEX
total = 0
vin.chars.each_with_index do |char, index|
Expand Down
1 change: 1 addition & 0 deletions test/helpers/test_faker_deprecator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ def self.say
end

include Faker::Deprecator

deprecate_generator('Dogs', Cats)
end
4 changes: 2 additions & 2 deletions test/test_da_dk_locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_da_dk_phone_number_methods

def test_da_dk_counrty_code
assert_equal '+45', Faker::PhoneNumber.country_code
assert_match(/(\+45)[\s](\d\d[\s-]?){4}$/, Faker::PhoneNumber.phone_number_with_country_code)
assert_match(/(\+45)[\s](\d\d[\s-]?){4}$/, Faker::PhoneNumber.cell_phone_with_country_code)
assert_match(/(\+45)\s(\d\d[\s-]?){4}$/, Faker::PhoneNumber.phone_number_with_country_code)
assert_match(/(\+45)\s(\d\d[\s-]?){4}$/, Faker::PhoneNumber.cell_phone_with_country_code)
end
end