junklet 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDQyODhhM2I3NTQyNzM3MzY1ZGM2NDk4YjZhN2VkMzVjMWZiZDdiYQ==
4
+ MDdlODdiZDE4MzI3Njk2YjBiZmQ0NTQ1ZDEwMzc3NmY0YTdkNGE3Mw==
5
5
  data.tar.gz: !binary |-
6
- ZjUxZWYzYjI3NDJjZDQwZjE4YzlhN2U2ZTI5OWE1NzRlNzhkMjljOA==
6
+ OWRhN2UxYTQxNzk0MGI1NGNiYjRlZGQ0YTVlMzE2ODAzZGYzZjhjNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmJjYTk5ZmY1ZWEzOGIxMjY0YzU0NzZiODJmODlkMzNhNGJjNTQ2NTFiOTU2
10
- MmYxMDc0YTdlOTI5M2UwNjRjMWRjYzVhYjNhYzU3ZDdlNjk4YWQ0YjA5Zjlk
11
- MDBiZWM5NDIxMzJjZWFlYTM2Yzg5OTVjOTI2NTMwNTIwYzQ5NjY=
9
+ MTJjYzEzNDIxNmQwMzkwNzg0N2U4MTQyMTUxMTgzYjNiNjFhYzJlNmIyMTg3
10
+ ZmZjOTQxOTIzOTFlZjFhZDcwMDViYTM5NDU0YmUyODA5YjUwOTljYTQ3MWRl
11
+ M2I4ODk5YWRmMjk4NTRlMTNjYjQxZGUyZWQyZDBlODYwZTYzZTM=
12
12
  data.tar.gz: !binary |-
13
- NjZjMDc0ZjNkYjU1YWI1NzA0OWM4MzgxZjA0ZGIwNDc1MjhhNDYwZGU5OTUw
14
- NzUyYzQxOGI5ZDNkZDJkNTA5ZDA0MzlhYjI3MTUxMjhiZmI3Mzc5NGI0NzRl
15
- YmY5NmUyM2EyOTg2Yzk0YmRhMzYyZmUyYmE1OWUzZjQ2NTY3ZDI=
13
+ ZWJmMWNlNGQ4MGU1YzY3ZTIwZGE1M2YxY2YzODgyZTgwZjU0YjdkY2EzNGNm
14
+ MGUwODZhYWNjMDNiMjRmMzM1NDI4MDk5MjQ3NDFiYjlkYzhjNWNlZWUzNjUw
15
+ NDQyZjEwYzU1N2I1ZmQxMTY2ZTY2N2QxZWIxMTllMmM2MjczYTg=
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Junklet
2
2
 
3
- Create tiny chunks of unique junk data in RSpec with `junklet :name`.
3
+ Cache tiny chunks of unique junk data in RSpec with `junklet :name`;
4
+ get handy clumps of junk data at any time with `junk`. Size your junk
5
+ with e.g. `junk 100` or `junk 4`.
4
6
 
5
7
  Junklet data is fixture data that:
6
8
 
@@ -16,6 +18,21 @@ So,
16
18
  * If equality fails we want to be led to the offending field by the
17
19
  error message and not just the line number in the stack trace.
18
20
 
21
+ # If You Work At CMM
22
+
23
+ 1. junklet means never having to type SecureRandom again.
24
+ 1. junklet prepends the field name to make errors easier to read.
25
+ 1. junk() returns a 32-byte random hex number, junk(n) returns the
26
+ same thing, only n bytes long (can be longer than 32)
27
+
28
+ Instead of writing this -> write this:
29
+
30
+ * `let(:pants) { SecureRandom.uuid }` -> `junklet :pants`
31
+ * `let(:host_name) { "host-name-#{SecureRandom.uuid}" }` -> `junklet :host_name, separator: '-'` (Remember that underscores aren't legal in host names)
32
+ * `let(:bad_number) { SecureRandom.hex[0..7] }` -> `let(:bad_number) { junk 8 }`
33
+ * `let(:website) { "www.#{SecureRandom.hex}.com" }` -> `let(:website) { "www.#{junk}.com }`
34
+
35
+
19
36
  # Usage
20
37
 
21
38
  junklet :var [, :var_2 [...]] [, options_hash]
@@ -23,14 +40,15 @@ So,
23
40
  junklet :first_name
24
41
 
25
42
  Creates a `let :first_name` with the value of
26
- `first_name-774030d0-f58d-4f58-8c5e-dddbdc7f9580` (the uuid will
27
- change with each test case)
43
+ `first_name-774030d0f58d4f588c5edddbdc7f9580` (the hex number is a
44
+ uuid without hyphens and will change with each test case, not just
45
+ each test run)
28
46
 
29
47
  junklet :host_name, separator: '-'
30
48
 
31
49
  Creates a `let :host_name`, but changes underscores to hyphens in the
32
50
  string value,
33
- e.g. `host-name-774030d0-f58d-4f58-8c5e-dddbdc7f9580`. Useful
51
+ e.g. `host-name-774030d0f58d4f588c5edddbdc7f9580`. Useful
34
52
  specifically for host names, which cannot have underscores in them.
35
53
 
36
54
  junklet :a_a, :b_b, :c_c, separator: '.'
@@ -38,6 +56,12 @@ specifically for host names, which cannot have underscores in them.
38
56
  Does what it says on the tin: creates 3 items with string values of
39
57
  `a.a`, `b.b`, and `c.c` respectively.
40
58
 
59
+
60
+ junk [length=32]
61
+
62
+ Can be called from inside a spec or let block, and returns a random
63
+ hex string 32 bytes long (or whatever length you specify)
64
+
41
65
  # Background
42
66
 
43
67
  At CoverMyMeds we have a legacy impingement that prevents us sometimes
@@ -92,10 +116,8 @@ junklet :first_name, :last_name, :address, :city, :state, :phone
92
116
  ```
93
117
 
94
118
  This will have the same effect as calling `let` on the named fields
95
- and setting the fieldname and a UUID to be the memoized value.
96
-
97
- No, `junklet!` is NOT also included here because it doesn't really
98
- make sense until and unless we write custom generators.
119
+ and setting the fieldname and a 32-byte hex string (a uuid with
120
+ hyphens removed) to be the memoized value.
99
121
 
100
122
  # TODO
101
123
 
@@ -147,14 +169,11 @@ Or install it yourself as:
147
169
 
148
170
  $ gem install junklet
149
171
 
150
- ## Usage
151
-
152
- TODO: Write usage instructions here
153
-
154
172
  ## Contributing
155
173
 
156
174
  1. Fork it ( https://github.com/[my-github-username]/junklet/fork )
157
175
  2. Create your feature branch (`git checkout -b my-new-feature`)
158
176
  3. Commit your changes (`git commit -am 'Add some feature'`)
159
- 4. Push to the branch (`git push origin my-new-feature`)
160
- 5. Create a new Pull Request
177
+ 4. Write specs to document how your change is to be used
178
+ 5. Push to the branch (`git push origin my-new-feature`)
179
+ 6. Create a new Pull Request
@@ -1,3 +1,3 @@
1
1
  module Junklet
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
data/lib/junklet.rb CHANGED
@@ -14,10 +14,22 @@ module RSpec
14
14
  end
15
15
 
16
16
  args.zip(names).each do |arg, name|
17
- let(arg) { "#{name}-#{SecureRandom.uuid}" }
17
+ let(arg) { "#{name}-#{junk}" }
18
18
  end
19
19
  end
20
20
  end
21
+
22
+ def junk(size=32)
23
+ trash = ""
24
+ trash += SecureRandom.hex while trash.size < size
25
+ trash = trash[0...size]
26
+ end
21
27
  end
28
+
29
+ # class ExampleGroup
30
+ # def self.junk
31
+ # SecureRandom.hex
32
+ # end
33
+ # end
22
34
  end
23
35
  end
@@ -3,42 +3,71 @@ require 'spec_helper'
3
3
  describe Junklet do
4
4
  specify { expect(Junklet).to be }
5
5
 
6
- let(:uuid_regex) { /-[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/ }
6
+ let(:hex_regex) { /[\da-f]{32}/ }
7
7
 
8
8
  describe '.junklet' do
9
9
  context "with a single arg" do
10
- junklet :junk
10
+ junklet :trash
11
11
 
12
- specify { expect(junk).to be }
13
- specify { expect(junk).to match /^junk-/ }
14
- specify { expect(junk).to match uuid_regex }
12
+ specify { expect(trash).to be }
13
+ specify { expect(trash).to match /^trash-/ }
14
+ specify { expect(trash).to match hex_regex }
15
15
 
16
16
  describe "memoization" do
17
- specify { expect(junk).to eq(junk) }
17
+ specify { expect(trash).to eq(trash) }
18
18
  end
19
19
  end
20
20
 
21
21
  context "with multiple args" do
22
- junklet :junk, :toss, :crud, :crap
22
+ junklet :trash, :toss, :crud, :crap
23
23
 
24
- specify { expect(junk).to match /^junk-/ }
25
- specify { expect(junk).to match uuid_regex }
24
+ specify { expect(trash).to match /^trash-/ }
25
+ specify { expect(trash).to match hex_regex }
26
26
  specify { expect(toss).to match /^toss-/ }
27
- specify { expect(toss).to match uuid_regex }
27
+ specify { expect(toss).to match hex_regex }
28
28
  specify { expect(crud).to match /^crud-/ }
29
- specify { expect(crud).to match uuid_regex }
29
+ specify { expect(crud).to match hex_regex }
30
30
  specify { expect(crap).to match /^crap-/ }
31
- specify { expect(crap).to match uuid_regex }
31
+ specify { expect(crap).to match hex_regex }
32
32
  end
33
33
 
34
34
  context 'with separator option' do
35
35
  junklet :host_name, :last_name, :first_name, separator: '-'
36
36
  specify { expect(host_name).to match /^host-name-/ }
37
- specify { expect(host_name).to match uuid_regex }
37
+ specify { expect(host_name).to match hex_regex }
38
38
  specify { expect(last_name).to match /^last-name-/ }
39
- specify { expect(last_name).to match uuid_regex }
39
+ specify { expect(last_name).to match hex_regex }
40
40
  specify { expect(first_name).to match /^first-name-/ }
41
- specify { expect(first_name).to match uuid_regex }
41
+ specify { expect(first_name).to match hex_regex }
42
+ end
43
+ end
44
+
45
+ describe '.junk' do
46
+ let(:trash) { junk }
47
+
48
+ specify { expect(trash).to match hex_regex }
49
+
50
+ it "is not cached" do
51
+ expect(junk).to_not eq(junk)
52
+ end
53
+
54
+ it "but lets on junk ARE cached" do
55
+ expect(trash).to eq(trash)
56
+ end
57
+
58
+ context "with argument" do
59
+ let(:little_trash) { junk 5 }
60
+ let(:big_trash) { junk 100 }
61
+
62
+ it "returns junk of that length" do
63
+ expect(little_trash.size).to eq(5)
64
+ expect(big_trash.size).to eq(100)
65
+ end
66
+
67
+ it "returns hex chars of that length" do
68
+ expect(little_trash).to match /^[\da-f]{5}$/
69
+ expect(big_trash).to match /^[\da-f]{100}$/
70
+ end
42
71
  end
43
72
  end
44
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junklet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Brady
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - .gitignore
77
+ - .rspec
77
78
  - Gemfile
78
79
  - Gemfile.lock
79
80
  - LICENSE