rfauxfactory 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -11
- data/.travis.yml +0 -2
- data/Gemfile +3 -4
- data/Rakefile +8 -6
- data/bin/console +4 -3
- data/lib/rfauxfactory.rb +44 -5
- data/lib/rfauxfactory/constants.rb +43 -4
- data/lib/rfauxfactory/version.rb +3 -1
- data/rfauxfactory.gemspec +9 -7
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 665d98cd9b690f1248ad51f2802d7d9bd23559f1
|
4
|
+
data.tar.gz: cb5b01de4f84d47b93945d77ded8e9e303079d86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f458c9b26f2962f15ffe753ddfb1c9c29407f3b0fc89f692224998cc044f98018e6685f2c159c6c9dda4810d5a77053688cdf7f0f4051a5452a0e85d89bf6af7
|
7
|
+
data.tar.gz: 002d1a8bf527b3a197deb9aa422b9451453c05811401f79cb0b846d9f63c2c1171069312e7976cfb52c0f0a91c6a35b18244ec1b0401aef0d527d01469de2967
|
data/.rubocop.yml
CHANGED
@@ -1,14 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
SpaceInsideHashLiteralBraces:
|
8
|
-
Enabled: false
|
9
|
-
|
10
|
-
Encoding:
|
11
|
-
Enabled: false
|
1
|
+
AllCops:
|
2
|
+
UseCache: false
|
3
|
+
DefaultFormatter: progress
|
4
|
+
DisplayStyleGuide: true
|
5
|
+
DisplayCopNames: true
|
6
|
+
TargetRubyVersion: 2.3
|
12
7
|
|
13
8
|
LineLength:
|
14
9
|
Max: 119
|
@@ -25,3 +20,8 @@ ModuleLength:
|
|
25
20
|
NumericLiterals:
|
26
21
|
Enabled: false
|
27
22
|
|
23
|
+
NumericPredicate:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Metrics/AbcSize:
|
27
|
+
Max: 25
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
gemspec
|
4
6
|
|
5
7
|
group :development, :test do
|
6
8
|
gem 'coveralls'
|
7
|
-
gem 'minitest'
|
8
9
|
gem 'pry'
|
9
|
-
gem 'rake'
|
10
10
|
gem 'rubocop-checkstyle_formatter'
|
11
11
|
gem 'simplecov'
|
12
|
-
gem 'test-unit'
|
13
12
|
end
|
data/Rakefile
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
3
5
|
|
4
6
|
begin
|
5
7
|
require 'rubocop/rake_task'
|
6
8
|
RuboCop::RakeTask.new
|
7
9
|
rescue LoadError
|
8
|
-
puts
|
10
|
+
puts 'Rubocop not loaded'
|
9
11
|
end
|
10
12
|
|
11
13
|
Rake::TestTask.new(:test) do |t|
|
12
|
-
t.libs <<
|
13
|
-
t.libs <<
|
14
|
-
t.test_files = FileList[
|
14
|
+
t.libs << 'test'
|
15
|
+
t.libs << 'lib'
|
16
|
+
t.test_files = FileList['test/**/*_test.rb']
|
15
17
|
end
|
16
18
|
|
17
19
|
task :default do
|
data/bin/console
CHANGED
data/lib/rfauxfactory.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rfauxfactory/version'
|
4
|
+
require 'rfauxfactory/constants'
|
3
5
|
|
4
6
|
# The python FauxFactory port
|
5
7
|
module RFauxFactory
|
@@ -38,11 +40,11 @@ module RFauxFactory
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def positive_int_or_range!(length)
|
41
|
-
raise TypeError,
|
43
|
+
raise TypeError, 'length must be Integer or Range' unless length.is_a?(Integer) || length.is_a?(Range)
|
42
44
|
if length.is_a?(Integer)
|
43
45
|
positive_int! length
|
44
46
|
else
|
45
|
-
raise ArgumentError,
|
47
|
+
raise ArgumentError, 'Bad length range' if length.size.nil? || length.size.zero?
|
46
48
|
positive_int! length.first, name: 'length.first'
|
47
49
|
positive_int! length.last, name: 'length.last'
|
48
50
|
end
|
@@ -113,7 +115,7 @@ module RFauxFactory
|
|
113
115
|
# Generates a list of different input strings.
|
114
116
|
def gen_strings(length = 10, exclude: [])
|
115
117
|
positive_int_or_range! length
|
116
|
-
raise TypeError,
|
118
|
+
raise TypeError, 'exclude must be an Array' unless exclude.is_a?(Array)
|
117
119
|
str_types = RFauxFactory::STRING_TYPES.keys.reject { |str_type| exclude.include?(str_type) }
|
118
120
|
str_types.map do |str_type|
|
119
121
|
str_length = length.is_a?(Range) ? rand(length) : length
|
@@ -125,5 +127,42 @@ module RFauxFactory
|
|
125
127
|
def gen_boolean
|
126
128
|
[true, false].sample
|
127
129
|
end
|
130
|
+
|
131
|
+
# Generates a random IP address.
|
132
|
+
def gen_ipaddr(protocol: :ip4, prefix: [])
|
133
|
+
raise ArgumentError, "#{protocol} is not valid protocol" unless IP_BLOCKS.key?(protocol)
|
134
|
+
sections = IP_BLOCKS[protocol]
|
135
|
+
prefix.map(&:to_s).compact
|
136
|
+
sections -= prefix.length
|
137
|
+
raise ArgumentError, "Prefix #{prefix} is too long for this configuration" if sections <= 0
|
138
|
+
random_fields = if protocol == :ipv6
|
139
|
+
Array.new(sections) { rand(0..2**16 - 1).to_s(16) }
|
140
|
+
else
|
141
|
+
Array.new(sections) { rand(0..255) }
|
142
|
+
end
|
143
|
+
ipaddr = (prefix + random_fields).join(IP_SEPARATOR[protocol])
|
144
|
+
ipaddr += '.0' if protocol == :ip3
|
145
|
+
ipaddr
|
146
|
+
end
|
147
|
+
|
148
|
+
# Generates a random MAC address.
|
149
|
+
def gen_mac(delimiter: ':', multicast: nil, locally: nil)
|
150
|
+
raise ArgumentError, "#{delimiter} is not valid delimiter" unless %w[: -].include?(delimiter)
|
151
|
+
multicast = gen_boolean if multicast.nil?
|
152
|
+
locally = gen_boolean if locally.nil?
|
153
|
+
first_octet = rand(0..255)
|
154
|
+
multicast ? first_octet |= 0b00000001 : first_octet &= 0b11111110
|
155
|
+
locally ? first_octet |= 0b00000010 : first_octet &= 0b11111101
|
156
|
+
octets = [first_octet]
|
157
|
+
octets += (Array.new(5) { rand(0..255) })
|
158
|
+
octets.map { |octet| format('%02x', octet) }.join(delimiter)
|
159
|
+
end
|
160
|
+
|
161
|
+
# Generates a random netmask.
|
162
|
+
def gen_netmask(min_cidr: 1, max_cidr: 31)
|
163
|
+
raise ArgumentError, "min_cidr must be 0 or greater, but is #{min_cidr}" if min_cidr < 0
|
164
|
+
raise ArgumentError, "max_cidr must be 0 or greater, but is #{max_cidr}" if max_cidr >= VALID_NETMASKS.length
|
165
|
+
VALID_NETMASKS[rand(min_cidr..max_cidr)]
|
166
|
+
end
|
128
167
|
end
|
129
168
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RFauxFactory
|
2
4
|
MAX_INT = 2**(1.size * 8 - 2) - 1
|
3
5
|
MIN_INT = -MAX_INT - 1
|
4
|
-
ASCII_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz'
|
5
|
-
ASCII_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
6
|
-
PUNCTUATION = %q(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)
|
6
|
+
ASCII_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz'
|
7
|
+
ASCII_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
8
|
+
PUNCTUATION = %q(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)
|
7
9
|
ASCII_LETTERS = ASCII_LOWERCASE + ASCII_UPPERCASE
|
8
|
-
DIGITS = '0123456789'
|
10
|
+
DIGITS = '0123456789'
|
9
11
|
ALPHANUMERIC = ASCII_LETTERS + DIGITS
|
10
12
|
HTML_TAGS = %w[
|
11
13
|
a abbr acronym address applet area b
|
@@ -612,4 +614,41 @@ module RFauxFactory
|
|
612
614
|
codepoint.chr(Encoding::UTF_8)
|
613
615
|
end
|
614
616
|
end.flatten
|
617
|
+
IP_BLOCKS = { ip3: 3, ip4: 4, ipv6: 8 }.freeze
|
618
|
+
IP_SEPARATOR = { ip3: '.', ip4: '.', ipv6: ':' }.freeze
|
619
|
+
VALID_NETMASKS = %w[
|
620
|
+
0.0.0.0
|
621
|
+
128.0.0.0
|
622
|
+
192.0.0.0
|
623
|
+
224.0.0.0
|
624
|
+
240.0.0.0
|
625
|
+
248.0.0.0
|
626
|
+
252.0.0.0
|
627
|
+
254.0.0.0
|
628
|
+
255.0.0.0
|
629
|
+
255.128.0.0
|
630
|
+
255.192.0.0
|
631
|
+
255.224.0.0
|
632
|
+
255.240.0.0
|
633
|
+
255.248.0.0
|
634
|
+
255.252.0.0
|
635
|
+
255.254.0.0
|
636
|
+
255.255.0.0
|
637
|
+
255.255.128.0
|
638
|
+
255.255.192.0
|
639
|
+
255.255.224.0
|
640
|
+
255.255.240.0
|
641
|
+
255.255.248.0
|
642
|
+
255.255.252.0
|
643
|
+
255.255.254.0
|
644
|
+
255.255.255.0
|
645
|
+
255.255.255.128
|
646
|
+
255.255.255.192
|
647
|
+
255.255.255.224
|
648
|
+
255.255.255.240
|
649
|
+
255.255.255.248
|
650
|
+
255.255.255.252
|
651
|
+
255.255.255.254
|
652
|
+
255.255.255.255
|
653
|
+
].freeze
|
615
654
|
end
|
data/lib/rfauxfactory/version.rb
CHANGED
data/rfauxfactory.gemspec
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'rfauxfactory/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'rfauxfactory'
|
8
9
|
spec.version = RFauxFactory::VERSION
|
9
10
|
spec.authors = ['Og Maciel']
|
10
11
|
spec.email = ['omaciel@ogmaciel.com']
|
@@ -16,11 +17,12 @@ Gem::Specification.new do |spec|
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
18
|
f.match(%r{^(test|spec|features)/})
|
18
19
|
end
|
19
|
-
spec.bindir =
|
20
|
+
spec.bindir = 'exe'
|
20
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
spec.required_ruby_version = '>= 2.3'
|
22
24
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
26
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
27
|
+
spec.add_development_dependency 'rake'
|
26
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rfauxfactory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Og Maciel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
description: Generates random data for your tests. Ruby port for https://github.com/omaciel/fauxfactory.
|
56
56
|
email:
|
57
57
|
- omaciel@ogmaciel.com
|
@@ -84,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
84
|
requirements:
|
85
85
|
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: '
|
87
|
+
version: '2.3'
|
88
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
90
|
- - ">="
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.6.14
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Generates random data for your tests.
|