degenerate 0.0.1 → 0.0.2

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
- SHA1:
3
- metadata.gz: ac65b80667efb1b4e4a370b86545decd3e5d58b7
4
- data.tar.gz: 5ce63cb196ee90a20c6ab33b5fca9364efdd82e4
5
- SHA512:
6
- metadata.gz: be0c4a49c1fe48cf8dd728b10c6088abb52005928f2ab67ca5603727c337b9f9a1c6efc52ced2d73684d51f88b615ada2656732a7c3ef93d82d1ed48b48ac22b
7
- data.tar.gz: 2c392b8c239924c171dd59907104f29b4e1605293bc36dd354e1cb71be76d2496eee49717df0221335979f152dc2afd21fe51df7d6de64f3026ccb6587f74375
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 088ff8eb3cf7313df055e89feba0849f4a068f67
4
+ data.tar.gz: fa3bed4a61194f9a62dec3b1a0d6ba0743b81dda
5
+ SHA512:
6
+ metadata.gz: d927a80d809e03f85b2bb8ecd9e9877e73a449933e9f2646741a8c06af3d05c535919f8b4ecf1cd93a9f4b6913f4f5e92c39d18d823f449a7e9d45d34703013d
7
+ data.tar.gz: 3b24e2ea03f4641bcb1444915e521e4b90e0cdc892f0aa972604b9d94ed89c71fdeabb389f6e5891beabc2ebea4338ac8215010b7b1042f59eaf5dc2b0738949
data/lib/degenerate.rb CHANGED
@@ -6,4 +6,6 @@ module Degenerate
6
6
  Generative.register_generator(:string, Generators.string)
7
7
  Generative.register_generator(:integer, Generators.integer)
8
8
  Generative.register_generator(:array, Generators.array)
9
+ Generative.register_generator(:any, Generators.any)
10
+ Generative.register_generator(:http_status, Generators.http_status)
9
11
  end
@@ -3,26 +3,55 @@ module Degenerate
3
3
  INTEGER_MAX = (2**(0.size * 8 -2) -1) / 2
4
4
  INTEGER_MIN = -(INTEGER_MAX)
5
5
 
6
+ GENERATORS = [:integer, :string, :array]
7
+
8
+ HTTP_STATUSES = [100, 101, 102, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 307, 308, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 422, 423, 424, 426, 428, 429, 431, 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511]
9
+
6
10
  def self.integer
7
11
  ->(opts={}) { rand((opts[:min] || INTEGER_MIN)..(opts[:max] || INTEGER_MAX)) }
8
12
  end
9
13
 
10
14
  def self.string
11
- ->(opts={}) { random_string(opts[:length] || random_int) }
15
+ ->(opts={}) {
16
+ chars = opts[:of] || default_chars
17
+ limit = opts[:limit] || random_int
18
+ random_string_of(chars, limit)
19
+ }
12
20
  end
13
21
 
14
22
  def self.array
15
- ->(opts={}) { [].class.new(opts[:size] || random_int) }
23
+ ->(opts={}) {
24
+ limit = opts[:limit] || random_int
25
+ of = Array(opts [:of] ||
26
+ send([:integer, :string].sample).call(limit: 1000))
27
+ array_of(limit, *of)
28
+ }
29
+ end
30
+
31
+ def self.any
32
+ send(GENERATORS.sample)
33
+ end
34
+
35
+ def self.http_status
36
+ ->() { HTTP_STATUSES.sample }
16
37
  end
17
38
 
18
39
  private
19
40
 
20
- def self.random_string(length)
21
- [].class.new(length) { "" << rand(0..3000) }.join
41
+ def self.default_chars
42
+ ('1'..'z').to_a
43
+ end
44
+
45
+ def self.array_of(limit, *generated)
46
+ [].class.new(random_int(limit)) { generated.sample }
47
+ end
48
+
49
+ def self.random_string_of(chars, limit)
50
+ [].class.new(random_int(limit)) { chars.sample }.join
22
51
  end
23
52
 
24
- def self.random_int
25
- Degenerate::Generators.integer.call(min: 0, max: 9999)
53
+ def self.random_int(limit=9999)
54
+ Degenerate::Generators.integer.call(min: 0, max: limit)
26
55
  end
27
56
  end
28
57
  end
@@ -1,3 +1,3 @@
1
1
  module Degenerate
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -30,4 +30,27 @@ RSpec.describe Degenerate do
30
30
  end
31
31
  end
32
32
  end
33
+
34
+ describe "any generator" do
35
+ generative do
36
+ data(:any) { generate(:array) }
37
+
38
+ it "registers an any generator" do
39
+ class_name = any.class.to_s.downcase.to_sym
40
+ expect(Degenerate::Generators::GENERATORS)
41
+ .to include(class_name)
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "http status generator" do
47
+ generative do
48
+ data(:status) { generate(:http_status) }
49
+
50
+ it "registers an http status generator" do
51
+ expect(Degenerate::Generators::HTTP_STATUSES)
52
+ .to include(status)
53
+ end
54
+ end
55
+ end
33
56
  end
@@ -1,4 +1,4 @@
1
- require_relative '../spec_helper.rb'
1
+ require_relative '../spec_helper'
2
2
 
3
3
  RSpec.describe Degenerate::Generators do
4
4
  describe ".integer" do
@@ -32,6 +32,20 @@ RSpec.describe Degenerate::Generators do
32
32
  it "'s generator returns a string" do
33
33
  expect(Degenerate::Generators.string.call).to be_a(String)
34
34
  end
35
+
36
+ data(:chars) { generate(:string, limit: 10).split('') }
37
+
38
+ it "only uses characters from user input when given a list of characters" do
39
+ string = Degenerate::Generators.string.call(of: chars)
40
+ expect(string.split('').all? { |c| chars.include?(c) }).to be true
41
+ end
42
+
43
+ data(:limit) { generate(:integer, min: 0, max: 100) }
44
+
45
+ it "limits strings to a given size" do
46
+ expect(Degenerate::Generators.string.call(limit: limit).size)
47
+ .to be <= limit
48
+ end
35
49
  end
36
50
  end
37
51
 
@@ -44,6 +58,21 @@ RSpec.describe Degenerate::Generators do
44
58
  it "'s generator returns a array" do
45
59
  expect(Degenerate::Generators.array.call).to be_a(Array)
46
60
  end
61
+
62
+ let(:limit) { generate(:integer, min: 0, max: 100) }
63
+
64
+ it "limits the array to a given size" do
65
+ array = Degenerate::Generators.array.call(limit: limit)
66
+ expect(array.size).to be <= limit
67
+ end
68
+
69
+ let(:generated) { generate([:integer, :string].sample) }
70
+
71
+ it "generate an array from 1 given generator" do
72
+ array = Degenerate::Generators.array.call(limit: limit, of: generated)
73
+ result_classes = array.map(&:class)
74
+ result_classes.all? { |c| expect(c).to eq(generated.class) }
75
+ end
47
76
  end
48
77
  end
49
78
 
@@ -58,4 +87,15 @@ RSpec.describe Degenerate::Generators do
58
87
  end
59
88
  end
60
89
  end
90
+
91
+ describe ".http_status" do
92
+ generative do
93
+ let(:statuses) { Degenerate::Generators::HTTP_STATUSES }
94
+
95
+ it "returns a valid http status" do
96
+ status = Degenerate::Generators.http_status.call
97
+ expect(statuses).to include(status)
98
+ end
99
+ end
100
+ end
61
101
  end
metadata CHANGED
@@ -1,98 +1,81 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: degenerate
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Nate West
8
8
  - Eric West
9
9
  - Jack Newton
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-11-12 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
13
+
14
+ date: 2014-12-01 00:00:00 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ version_requirements: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: "1.6"
16
22
  name: bundler
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - "~>"
20
- - !ruby/object:Gem::Version
21
- version: '1.6'
22
23
  type: :development
24
+ requirement: *id001
23
25
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - "~>"
27
- - !ruby/object:Gem::Version
28
- version: '1.6'
29
- - !ruby/object:Gem::Dependency
26
+ - !ruby/object:Gem::Dependency
27
+ version_requirements: &id002 !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - &id005
30
+ - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: "0"
30
33
  name: rake
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: '0'
36
34
  type: :development
35
+ requirement: *id002
37
36
  prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: '0'
43
- - !ruby/object:Gem::Dependency
44
- name: rspec-core
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
37
+ - !ruby/object:Gem::Dependency
38
+ version_requirements: &id003 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
49
42
  version: 3.1.3
43
+ name: rspec-core
50
44
  type: :development
45
+ requirement: *id003
51
46
  prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: 3.1.3
57
- - !ruby/object:Gem::Dependency
58
- name: rspec
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
47
+ - !ruby/object:Gem::Dependency
48
+ version_requirements: &id004 !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
63
52
  version: 3.1.0
53
+ name: rspec
64
54
  type: :development
55
+ requirement: *id004
65
56
  prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - "~>"
69
- - !ruby/object:Gem::Version
70
- version: 3.1.0
71
- - !ruby/object:Gem::Dependency
57
+ - !ruby/object:Gem::Dependency
58
+ version_requirements: &id006 !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - *id005
72
61
  name: pry
73
- requirement: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
62
  type: :development
63
+ requirement: *id006
79
64
  prerelease: false
80
- version_requirements: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: '0'
85
65
  description: Random data generator for use with Generative.
86
- email:
66
+ email:
87
67
  - natescott.west@gmail.com
88
68
  - esw9999@gmail.com
89
69
  - eternal.turtles@gmail.com
90
70
  executables: []
71
+
91
72
  extensions: []
73
+
92
74
  extra_rdoc_files: []
93
- files:
94
- - ".gitignore"
95
- - ".rspec"
75
+
76
+ files:
77
+ - .gitignore
78
+ - .rspec
96
79
  - Gemfile
97
80
  - LICENSE.txt
98
81
  - README.md
@@ -105,30 +88,29 @@ files:
105
88
  - spec/lib/generators_spec.rb
106
89
  - spec/spec_helper.rb
107
90
  homepage: http://github.com/niftyn8/degenerate
108
- licenses:
91
+ licenses:
109
92
  - MIT
110
93
  metadata: {}
94
+
111
95
  post_install_message:
112
96
  rdoc_options: []
113
- require_paths:
97
+
98
+ require_paths:
114
99
  - lib
115
- required_ruby_version: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: '0'
120
- required_rubygems_version: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - *id005
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - *id005
125
106
  requirements: []
107
+
126
108
  rubyforge_project:
127
109
  rubygems_version: 2.2.2
128
110
  signing_key:
129
111
  specification_version: 4
130
112
  summary: Random data generator for use with Generative.
131
- test_files:
113
+ test_files:
132
114
  - spec/lib/degenerate_spec.rb
133
115
  - spec/lib/generators_spec.rb
134
116
  - spec/spec_helper.rb