junklet 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/junklet/version.rb +1 -1
- data/lib/junklet.rb +17 -9
- data/spec/lib/junklet_spec.rb +13 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDBjY2JlZjYxYjAyMjI4NTc0NTBlZDkwZTRjNzdmMjMyZmQwNGMyMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmRjOTE4OGRiYTA4ODkyYzE3ZTAzNTQ3Y2VjOGYzZDkwZjc0NTY4MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGY2OTMwZGM3NDc5MWI5MzFjYmY2ZTFiZTdjM2VjOTFiMjJiYWVjMjk3N2Fk
|
10
|
+
OWE1MDU2YTc5OWI1M2ZmMjM2YThiMzNiZGMyYTg1MGJkNzNlOTU1NDVjMWEw
|
11
|
+
N2NjMjNjYzE5ZTQyYWNkMGZiNmFkODFhZjkxYzAyNzk4YTNjZmE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjRkMGJhNjdhNzBmMzI4N2U3ZjgwZTVhNjdmODdjNmQxYzg0ZWM1NzBkMzYz
|
14
|
+
NTljODE1NjM4Y2I2YTc0NjEzMjc3MmM3Zjg3M2I1N2NiZDZjODcyZDBjMWM5
|
15
|
+
ODI3MGI1NjQ5ZmQ5MDYyNTM0ODFmY2M4ODdkMWI2MWM0Y2QwZTE=
|
data/lib/junklet/version.rb
CHANGED
data/lib/junklet.rb
CHANGED
@@ -8,24 +8,32 @@ module RSpec
|
|
8
8
|
opts = args.size > 1 && !args.last.is_a?(Symbol) && args.pop || {}
|
9
9
|
|
10
10
|
names = args.map(&:to_s)
|
11
|
-
|
11
|
+
|
12
12
|
if opts.key?(:separator)
|
13
13
|
names = names.map {|name| name.gsub(/_/, opts[:separator]) }
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
args.zip(names).each do |arg, name|
|
17
17
|
let(arg) { "#{name}-#{junk}" }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def junk(size=32)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
def junk(size=32, options={})
|
23
|
+
if :integer == options[:type]
|
24
|
+
# TODO: We can actual know how many hex digits we need in
|
25
|
+
# advance because of te ratio of the logs. We should totally
|
26
|
+
# work that out sometime. The ratio is like 1.2 something. For
|
27
|
+
# now, blah, just make it work.
|
28
|
+
SecureRandom.hex.to_i(16).to_s[0..size]
|
29
|
+
else
|
30
|
+
# hex returns size*2 digits, because it returns a 0..255 byte
|
31
|
+
# as a hex pair. But when we want junt, we want *bytes* of
|
32
|
+
# junk. Get (size+1)/2 chars, which will be correct for even
|
33
|
+
# sizes and 1 char too many for odds, so trim off with
|
34
|
+
# [0...size] (note three .'s to trim off final char)
|
35
|
+
SecureRandom.hex((size+1)/2)[0...size]
|
36
|
+
end
|
29
37
|
end
|
30
38
|
end
|
31
39
|
end
|
data/spec/lib/junklet_spec.rb
CHANGED
@@ -8,11 +8,11 @@ describe Junklet do
|
|
8
8
|
describe '.junklet' do
|
9
9
|
context "with a single arg" do
|
10
10
|
junklet :trash
|
11
|
-
|
11
|
+
|
12
12
|
specify { expect(trash).to be }
|
13
13
|
specify { expect(trash).to match /^trash-/ }
|
14
14
|
specify { expect(trash).to match hex_regex }
|
15
|
-
|
15
|
+
|
16
16
|
describe "memoization" do
|
17
17
|
specify { expect(trash).to eq(trash) }
|
18
18
|
end
|
@@ -44,10 +44,10 @@ describe Junklet do
|
|
44
44
|
|
45
45
|
describe '.junk' do
|
46
46
|
let(:trash) { junk }
|
47
|
-
|
47
|
+
|
48
48
|
specify { expect(trash).to match hex_regex }
|
49
49
|
specify { expect(trash.size).to eq(32) }
|
50
|
-
|
50
|
+
|
51
51
|
it "is not cached" do
|
52
52
|
expect(junk).to_not eq(junk)
|
53
53
|
end
|
@@ -59,7 +59,7 @@ describe Junklet do
|
|
59
59
|
context "with argument" do
|
60
60
|
let(:little_trash) { junk 5 }
|
61
61
|
let(:big_trash) { junk 100 }
|
62
|
-
|
62
|
+
|
63
63
|
it "returns junk of that length" do
|
64
64
|
expect(little_trash.size).to eq(5)
|
65
65
|
expect(big_trash.size).to eq(100)
|
@@ -70,5 +70,13 @@ describe Junklet do
|
|
70
70
|
expect(big_trash).to match /^[\da-f]{100}$/
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
context "with type: :decimal" do
|
75
|
+
let(:junk_integer) { junk 15, type: :integer }
|
76
|
+
it "returns the request number of decimal digits" do
|
77
|
+
expect { (widget_id).to be_a Integer }
|
78
|
+
expect { (widget_id.to_s.size).to eq(15) }
|
79
|
+
end
|
80
|
+
end
|
73
81
|
end
|
74
82
|
end
|