much-factory 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA512:
3
- metadata.gz: ce3cb7efa49ac5ee256b00d1753f72c15ac20e91a24b51d8f4c178150e587baa6d25ca74ebd01a87d1d2abc6675708c2d3737254df9bddb1c808a806ad1db783
4
- data.tar.gz: 52ebb73ac36e7bd3a2238bb8e16f772aaa85c0a2365bf27dfa6f90d720095411db18e2b79be63423d6d67fd7440543ab374a2590eb684c12c3d44104f17bdd0e
5
- SHA1:
6
- metadata.gz: 444f3b8521b9c5caa52a3ee6eff9075f6f955ac5
7
- data.tar.gz: 26af4aec07d3cbfd2c2c4c3cd265f7dd116e3828
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 724bcba5bca34b1c458a9a96a63e3b2f5add77642cc6bdb10c68636a8c2f2e3e
4
+ data.tar.gz: 1619a18b41368f44345ae3cfd91f28003aa9ffd035eb1840d2d4bcc953100b89
5
+ SHA512:
6
+ metadata.gz: 7205c437919dcd3f1cc9b203ca81b53887a8a2c87a6c5c64821c901b09ccd453ded45fff8279df3c4bb6eca343909f2e8f70884477d54c4893fd333469121114
7
+ data.tar.gz: f4109ebebecb364f1b41da0038bb71ad7dc787a334d612d5d368eb8684dfc4f64b20f28b7d52c2e32250e3e0b8ed2b9746ae1901aa952b2f6d669a9c58e35780
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ ruby "~> 2.5"
4
+
3
5
  gemspec
4
6
 
5
- gem 'pry', "~> 0.9.0"
7
+ gem "pry"
data/README.md CHANGED
@@ -7,7 +7,7 @@ Note: this was originally implemented in and extracted from [Assert](https://git
7
7
  ## Usage
8
8
 
9
9
  ```ruby
10
- require 'much-factory'
10
+ require "much-factory"
11
11
 
12
12
  MuchFactory.integer #=> 15742
13
13
  MuchFactory.integer(3) #=> 2
@@ -20,6 +20,8 @@ MuchFactory.datetime #=> #<DateTime: 302518290593/43200,0,2299161>
20
20
 
21
21
  MuchFactory.string #=> "boxsrbazeq"
22
22
  MuchFactory.string(3) #=> "rja"
23
+ MuchFactory.symbol #=> :sfdhortksj
24
+ MuchFactory.symbol(3) #=> :emh
23
25
  MuchFactory.text #=> "khcwyizmymajfzzxlfwz"
24
26
  MuchFactory.text(3) #=> "qcy"
25
27
  MuchFactory.slug #=> "licia"
@@ -54,7 +56,7 @@ end
54
56
 
55
57
  Add this line to your application's Gemfile:
56
58
 
57
- gem 'much-factory'
59
+ gem "much-factory"
58
60
 
59
61
  And then execute:
60
62
 
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "much-factory/version"
2
4
 
3
- require 'date'
4
- require 'time'
5
+ require "date"
6
+ require "time"
5
7
 
6
8
  module MuchFactory
7
9
  extend self
@@ -36,6 +38,10 @@ module MuchFactory
36
38
  self.type_cast(Random.string(length || 10), :string)
37
39
  end
38
40
 
41
+ def symbol(*args)
42
+ self.string(*args).to_sym
43
+ end
44
+
39
45
  def text(length = nil)
40
46
  self.type_cast(Random.string(length || 20), :string)
41
47
  end
@@ -82,21 +88,22 @@ module MuchFactory
82
88
  self.type_converter.send(type, value)
83
89
  end
84
90
 
85
- def type_converter; TypeConverter; end
91
+ def type_converter
92
+ TypeConverter
93
+ end
86
94
 
87
95
  module TypeConverter
88
- def self.string(input); input.to_s; end
89
- def self.integer(input); input.to_i; end
90
- def self.float(input); input.to_f; end
91
- def self.datetime(input); DateTime.parse(input.to_s); end
92
- def self.time(input); Time.parse(input.to_s); end
93
- def self.date(input); Date.parse(input.to_s); end
94
- def self.boolean(input); !!input; end
95
- def self.binary(input); input; end
96
+ def self.string(input); input.to_s; end
97
+ def self.integer(input); input.to_i; end
98
+ def self.float(input); input.to_f; end
99
+ def self.datetime(input); DateTime.parse(input.to_s); end
100
+ def self.time(input); Time.parse(input.to_s); end
101
+ def self.date(input); Date.parse(input.to_s); end
102
+ def self.boolean(input); !!input; end
103
+ def self.binary(input); input; end
96
104
  end
97
105
 
98
106
  module Random
99
-
100
107
  # rand given a max int value returns integers between 0 and max-1
101
108
  def self.integer(max = nil)
102
109
  rand(max || 32_766) + 1
@@ -119,14 +126,14 @@ module MuchFactory
119
126
  Time.now.strftime("%H:%M:%S")
120
127
  end
121
128
 
122
- DICTIONARY = [*'a'..'z'].freeze
129
+ DICTIONARY = [*"a".."z"].freeze
123
130
  def self.string(length = nil)
124
131
  [*0..((length || 10) - 1)].map{ |n| DICTIONARY[rand(DICTIONARY.size)] }.join
125
132
  end
126
133
 
127
134
  def self.hex_string(length = nil)
128
135
  length ||= 10
129
- self.integer(("f" * length).hex - 1).to_s(16).rjust(length, '0')
136
+ self.integer(("f" * length).hex - 1).to_s(16).rjust(length, "0")
130
137
  end
131
138
 
132
139
  def self.file_name_string(length = nil)
@@ -153,9 +160,7 @@ module MuchFactory
153
160
  end
154
161
 
155
162
  def self.binary
156
- [ self.integer(10000) ].pack('N*')
163
+ [ self.integer(10000) ].pack("N*")
157
164
  end
158
-
159
165
  end
160
-
161
166
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MuchFactory
2
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
3
5
  end
File without changes
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
4
+ lib = File.expand_path("../lib", __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require "much-factory/version"
5
7
 
@@ -11,13 +13,14 @@ Gem::Specification.new do |gem|
11
13
  gem.summary = "An API for generating randomized data."
12
14
  gem.description = "An API for generating randomized data."
13
15
  gem.homepage = "https://github.com/redding/much-factory"
14
- gem.license = 'MIT'
16
+ gem.license = "MIT"
15
17
 
16
18
  gem.files = `git ls-files`.split($/)
17
19
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
20
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
21
  gem.require_paths = ["lib"]
20
22
 
21
- gem.add_development_dependency("assert", ["~> 2.16.4"])
23
+ gem.required_ruby_version = "~> 2.5"
22
24
 
25
+ gem.add_development_dependency("assert", ["~> 2.19.0"])
23
26
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # this file is automatically required when you run `assert`
2
4
  # put any test helpers here
3
5
 
@@ -5,15 +7,6 @@
5
7
  $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
6
8
 
7
9
  # require pry for debugging (`binding.pry`)
8
- require 'pry'
9
-
10
- require 'test/support/factory'
11
-
12
- # 1.8.7 backfills
10
+ require "pry"
13
11
 
14
- # Array#sample
15
- if !(a = Array.new).respond_to?(:sample) && a.respond_to?(:choice)
16
- class Array
17
- alias_method :sample, :choice
18
- end
19
- end
12
+ require "test/support/factory"
@@ -1,4 +1,6 @@
1
- require 'assert/factory'
1
+ # frozen_string_literal: true
2
+
3
+ require "assert/factory"
2
4
 
3
5
  module Factory
4
6
  extend Assert::Factory
File without changes
@@ -1,170 +1,179 @@
1
- require 'assert'
2
- require 'much-factory'
1
+ # frozen_string_literal: true
3
2
 
4
- require 'test/support/factory'
3
+ require "assert"
4
+ require "much-factory"
5
5
 
6
- module MuchFactory
6
+ require "test/support/factory"
7
7
 
8
+ module MuchFactory
8
9
  class UnitTests < Assert::Context
9
10
  desc "MuchFactory"
10
11
  subject{ MuchFactory }
11
12
 
12
13
  should have_imeths :integer, :float
13
14
  should have_imeths :date, :time, :datetime
14
- should have_imeths :string, :text, :slug, :hex
15
+ should have_imeths :string, :symbol, :text, :slug, :hex
15
16
  should have_imeths :file_name, :dir_path, :file_path
16
17
  should have_imeths :path, :url, :email
17
18
  should have_imeths :binary, :boolean
18
19
  should have_imeths :type_cast, :type_converter
19
20
 
20
21
  should "return a random integer using `integer`" do
21
- assert_kind_of Integer, subject.integer
22
+ assert_that(subject.integer).is_kind_of(Integer)
22
23
  end
23
24
 
24
25
  should "allow passing a maximum value using `integer`" do
25
- assert_includes subject.integer(2), [1, 2]
26
+ assert_that([1, 2]).includes(subject.integer(2))
26
27
  end
27
28
 
28
29
  should "return a random float using `float`" do
29
- assert_kind_of Float, subject.float
30
+ assert_that(subject.float).is_kind_of(Float)
30
31
  end
31
32
 
32
33
  should "allow passing a maximum value using `float`" do
33
34
  float = subject.float(2)
34
- assert float <= 2
35
- assert float >= 0
35
+ assert_that(float <= 2).is_true
36
+ assert_that(float >= 0).is_true
36
37
 
37
38
  float = subject.float(0)
38
- assert_equal 0.0, float
39
+ assert_that(float).equals(0.0)
39
40
  end
40
41
 
41
42
  should "return a random date using `date`" do
42
- assert_kind_of Date, subject.date
43
+ assert_that(subject.date).is_kind_of(Date)
43
44
  end
44
45
 
45
46
  should "return a random time object using `time`" do
46
- assert_kind_of Time, subject.time
47
+ assert_that(subject.time).is_kind_of(Time)
47
48
  end
48
49
 
49
50
  should "return a random time object using `datetime`" do
50
- assert_kind_of DateTime, subject.datetime
51
+ assert_that(subject.datetime).is_kind_of(DateTime)
51
52
  end
52
53
 
53
- should "return a random string using `string`" do
54
- assert_kind_of String, subject.string
55
- assert_equal 10, subject.string.length
54
+ should "return a random String using `string`" do
55
+ assert_that(subject.string).is_kind_of(String)
56
+ assert_that(subject.string.length).equals(10)
56
57
  end
57
58
 
58
59
  should "allow passing a maximum length using `string`" do
59
- assert_equal 1, subject.string(1).length
60
+ assert_that(subject.string(1).length).equals(1)
61
+ end
62
+
63
+ should "return a random Symbol using `symbol`" do
64
+ assert_that(subject.symbol).is_kind_of(Symbol)
65
+ assert_that(subject.symbol.length).equals(10)
66
+ end
67
+
68
+ should "allow passing a maximum length using `symbol`" do
69
+ assert_that(subject.symbol(1).length).equals(1)
60
70
  end
61
71
 
62
72
  should "return a random string using `text`" do
63
- assert_kind_of String, subject.text
64
- assert_equal 20, subject.text.length
73
+ assert_that(subject.text).is_kind_of(String)
74
+ assert_that(subject.text.length).equals(20)
65
75
  end
66
76
 
67
77
  should "allow passing a maximum length using `text`" do
68
- assert_equal 1, subject.text(1).length
78
+ assert_that(subject.text(1).length).equals(1)
69
79
  end
70
80
 
71
81
  should "return a random string using `slug`" do
72
- assert_kind_of String, subject.slug
73
- assert_equal 5, subject.slug.length
82
+ assert_that(subject.slug).is_kind_of(String)
83
+ assert_that(subject.slug.length).equals(5)
74
84
  end
75
85
 
76
86
  should "allow passing a maximum length using `slug`" do
77
- assert_equal 1, subject.slug(1).length
87
+ assert_that(subject.slug(1).length).equals(1)
78
88
  end
79
89
 
80
90
  should "return a random hex string using `hex`" do
81
- assert_kind_of String, subject.hex
82
- assert_match /\A[0-9a-f]{10}\Z/, subject.hex
91
+ assert_that(subject.hex).is_kind_of(String)
92
+ assert_that(subject.hex).matches(/\A[0-9a-f]{10}\Z/)
83
93
  end
84
94
 
85
95
  should "allow passing a maximum length using `hex`" do
86
- assert_equal 1, subject.hex(1).length
96
+ assert_that(subject.hex(1).length).equals(1)
87
97
  end
88
98
 
89
99
  should "return a random file name string using `file_name`" do
90
- assert_kind_of String, subject.file_name
91
- assert_match /\A[a-z]{6}\.[a-z]{3}\Z/, subject.file_name
100
+ assert_that(subject.file_name).is_kind_of(String)
101
+ assert_that(subject.file_name).matches(/\A[a-z]{6}\.[a-z]{3}\Z/)
92
102
  end
93
103
 
94
104
  should "allow passing a name length using `file_name`" do
95
- assert_match /\A[a-z]{1}.[a-z]{3}\Z/, subject.file_name(1)
105
+ assert_that(subject.file_name(1)).matches(/\A[a-z]{1}.[a-z]{3}\Z/)
96
106
  end
97
107
 
98
108
  should "return a random folder path string using `dir_path`" do
99
- assert_kind_of String, subject.dir_path
100
- path_segments = subject.dir_path.split('/')
101
- assert_equal 3, path_segments.size
102
- path_segments.each{ |s| assert_match /\A[a-z]{4}\Z/, s }
109
+ assert_that(subject.dir_path).is_kind_of(String)
110
+ path_segments = subject.dir_path.split("/")
111
+ assert_that(path_segments.size).equals(3)
112
+ path_segments.each{ |s| assert_that(s).matches(/\A[a-z]{4}\Z/) }
103
113
  end
104
114
 
105
115
  should "allow passing a maximum length using `dir_path`" do
106
- assert_equal 1, subject.dir_path(1).length
116
+ assert_that(subject.dir_path(1).length).equals(1)
107
117
  end
108
118
 
109
119
  should "return a random folder path and file name using `file_path`" do
110
- assert_kind_of String, subject.file_path
111
- segments = subject.file_path.split('/')
112
- assert_equal 4, segments.size
113
- segments[0..-2].each{ |s| assert_match /\A[a-z]{4}\Z/, s }
114
- assert_match /\A[a-z]{6}\.[a-z]{3}\Z/, segments.last
120
+ assert_that(subject.file_path).is_kind_of(String)
121
+ segments = subject.file_path.split("/")
122
+ assert_that(segments.size).equals(4)
123
+ segments[0..-2].each{ |s| assert_that(s).matches(/\A[a-z]{4}\Z/) }
124
+ assert_that(segments.last).matches(/\A[a-z]{6}\.[a-z]{3}\Z/)
115
125
  end
116
126
 
117
127
  should "return a random url string using `url`" do
118
128
  u = subject.url
119
- segments = u.split('/')
129
+ segments = u.split("/")
120
130
 
121
- assert_kind_of String, u
122
- assert_match /\A\//, u
123
- assert_equal 4, segments.size
124
- segments[1..-1].each{ |s| assert_match /\A[a-z]{4}\Z/, s }
131
+ assert_that(u).is_kind_of(String)
132
+ assert_that(u).matches(/\A\//)
133
+ assert_that(segments.size).equals(4)
134
+ segments[1..-1].each{ |s| assert_that(s).matches(/\A[a-z]{4}\Z/) }
125
135
  end
126
136
 
127
137
  should "allow passing a host string using `url`" do
128
138
  host = "example.com"
129
- assert_match /\A#{host}\//, subject.url(host)
139
+ assert_that(subject.url(host)).matches(/\A#{host}\//)
130
140
  end
131
141
 
132
142
  should "allow passing a maximum length using `url`" do
133
- assert_equal 2, subject.url('', 1).length # plus leading '/'
143
+ # plus 1 for the leading "/"
144
+ assert_that(subject.url("", 1).length).equals(2)
134
145
  end
135
146
 
136
147
  should "return a random email string using `email`" do
137
148
  e = subject.email
138
- assert_kind_of String, e
139
- assert_match /\A\w+@\w+\.com\Z/, e
149
+ assert_that(e).is_kind_of(String)
150
+ assert_that(e).matches(/\A\w+@\w+\.com\Z/)
140
151
  end
141
152
 
142
153
  should "allow passing a custom domain to `email`" do
143
- e = subject.email('example.org')
144
- assert_match /@example\.org\Z/, e
154
+ e = subject.email("example.org")
155
+ assert_that(e).matches(/@example\.org\Z/)
145
156
  end
146
157
 
147
158
  should "allow passing a mailbox length using `email`" do
148
- assert_equal 2, subject.email(nil, 2).split('@').first.size
159
+ assert_that(subject.email(nil, 2).split("@").first.size).equals(2)
149
160
  end
150
161
 
151
162
  should "return a random binary string using `binary`" do
152
- assert_kind_of String, subject.binary
163
+ assert_that(subject.binary).is_kind_of(String)
153
164
  end
154
165
 
155
166
  should "return a random boolean using `boolean`" do
156
- assert_includes subject.boolean.class, [ TrueClass, FalseClass ]
167
+ assert_that([TrueClass, FalseClass]).includes(subject.boolean.class)
157
168
  end
158
169
 
159
170
  should "type cast values to a specified type using `type_cast`" do
160
- expected = Date.parse('2013-01-01')
161
- assert_equal expected, subject.type_cast('2013-01-01', :date)
171
+ expected = Date.parse("2013-01-01")
172
+ assert_that(subject.type_cast("2013-01-01", :date)).equals(expected)
162
173
  end
163
174
 
164
175
  should "use `TypedConverter` for the default type converter" do
165
- assert_equal TypeConverter, subject.type_converter
176
+ assert_that(subject.type_converter).equals(TypeConverter)
166
177
  end
167
-
168
178
  end
169
-
170
179
  end
metadata CHANGED
@@ -1,77 +1,76 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: much-factory
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Kelly Redding
8
8
  - Collin Redding
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2018-06-06 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2021-01-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: assert
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- requirements:
20
- - - ~>
21
- - !ruby/object:Gem::Version
22
- version: 2.16.4
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 2.19.0
23
21
  type: :development
24
- version_requirements: *id001
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.19.0
25
28
  description: An API for generating randomized data.
26
- email:
29
+ email:
27
30
  - kelly@kellyredding.com
28
31
  - collin.redding@me.com
29
32
  executables: []
30
-
31
33
  extensions: []
32
-
33
34
  extra_rdoc_files: []
34
-
35
- files:
36
- - .gitignore
35
+ files:
36
+ - ".gitignore"
37
37
  - Gemfile
38
38
  - LICENSE
39
39
  - README.md
40
40
  - lib/much-factory.rb
41
41
  - lib/much-factory/version.rb
42
- - log/.gitkeep
42
+ - log/.keep
43
43
  - much-factory.gemspec
44
44
  - test/helper.rb
45
45
  - test/support/factory.rb
46
+ - test/system/.keep
46
47
  - test/unit/much-factory_tests.rb
47
48
  - tmp/.gitkeep
48
49
  homepage: https://github.com/redding/much-factory
49
- licenses:
50
+ licenses:
50
51
  - MIT
51
52
  metadata: {}
52
-
53
53
  post_install_message:
54
54
  rdoc_options: []
55
-
56
- require_paths:
55
+ require_paths:
57
56
  - lib
58
- required_ruby_version: !ruby/object:Gem::Requirement
59
- requirements:
60
- - &id002
61
- - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- required_rubygems_version: !ruby/object:Gem::Requirement
65
- requirements:
66
- - *id002
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
67
  requirements: []
68
-
69
- rubyforge_project:
70
- rubygems_version: 2.6.6
68
+ rubygems_version: 3.1.2
71
69
  signing_key:
72
70
  specification_version: 4
73
71
  summary: An API for generating randomized data.
74
- test_files:
72
+ test_files:
75
73
  - test/helper.rb
76
74
  - test/support/factory.rb
75
+ - test/system/.keep
77
76
  - test/unit/much-factory_tests.rb