rand-rspec 0.0.3 → 0.0.4
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aee728c8432b16c2c12d719dab61b7114e0a22bc
|
4
|
+
data.tar.gz: eea5fc928ebc40faedf70b000fa29666b35ada4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bba1ffdf3461a3235e70b22b769e23e93867a8abd4e8239e38c7dd872bab04ade6cb3bc2db44a2148d244eedb5b519136184e21db104dd9d9331bafe91df94f7
|
7
|
+
data.tar.gz: af283dbcf03a3bae34dacf8fc05fecf6ad6b622b1b3fa65927c3159511578df3d0d32436317dfa53044f9fe20b1e0d0b9b99379a03b35d844ae31d0e447ec221
|
data/lib/rand-rspec/strings.rb
CHANGED
@@ -5,16 +5,16 @@ module RandTest
|
|
5
5
|
|
6
6
|
module Strings
|
7
7
|
|
8
|
-
def random_ascii_of_length_between(min, max)
|
9
|
-
RandTest::AsciiGenerator.random_ascii_between(min, max)
|
8
|
+
def random_ascii_of_length_between(min, max, options={})
|
9
|
+
RandTest::AsciiGenerator.random_ascii_between(min, max, options)
|
10
10
|
end
|
11
11
|
|
12
|
-
def random_ascii_of_length(length)
|
13
|
-
random_ascii_of_length_between(0, length-1)
|
12
|
+
def random_ascii_of_length(length, options={})
|
13
|
+
random_ascii_of_length_between(0, length-1, options)
|
14
14
|
end
|
15
15
|
|
16
|
-
def random_unicode_of_length(min, max)
|
17
|
-
RandTest::UnicodeGenerator.random_unicode_of_length(min, max)
|
16
|
+
def random_unicode_of_length(min, max, options={})
|
17
|
+
RandTest::UnicodeGenerator.random_unicode_of_length(min, max, options)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -10,10 +10,15 @@ module RandTest
|
|
10
10
|
|
11
11
|
class << self
|
12
12
|
|
13
|
-
def random_ascii_between(min, max)
|
14
|
-
size
|
13
|
+
def random_ascii_between(min, max, options={})
|
14
|
+
size = random_number_between(min, max)
|
15
|
+
spaces = options[:spaces] || false
|
15
16
|
(min...(min+size)).inject("") do |acc, obj|
|
16
|
-
|
17
|
+
if (spaces && (rand(2) > 0))
|
18
|
+
acc << " "
|
19
|
+
else
|
20
|
+
acc << CHARS[rand(CHARS.size)].chr
|
21
|
+
end
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
@@ -56,12 +56,17 @@ module RandTest
|
|
56
56
|
|
57
57
|
class << self
|
58
58
|
|
59
|
-
def random_unicode_of_length(min, max)
|
59
|
+
def random_unicode_of_length(min, max, options={})
|
60
60
|
length = random_number_between(min, max)
|
61
|
+
spaces = options[:spaces] || false
|
61
62
|
block = rand(BLOCK_STARTS.count)
|
62
63
|
(0...length).inject("") do |acc, obj|
|
63
|
-
|
64
|
-
|
64
|
+
if (spaces && rand(2) > 0)
|
65
|
+
acc << " "
|
66
|
+
else
|
67
|
+
code_point = random_number_between(BLOCK_STARTS[block], BLOCK_ENDS[block])
|
68
|
+
acc << code_point.chr(Encoding::UTF_8)
|
69
|
+
end
|
65
70
|
end
|
66
71
|
end
|
67
72
|
end
|
data/lib/rand-rspec/version.rb
CHANGED
@@ -2,28 +2,58 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'RandTest::Strings' do
|
4
4
|
|
5
|
-
|
5
|
+
let(:min) { 10 }
|
6
|
+
let(:max) { 100 }
|
6
7
|
|
7
|
-
|
8
|
-
let(:max) { 100 }
|
8
|
+
describe "using no modification options" do
|
9
9
|
|
10
|
-
|
10
|
+
shared_examples "string generation with no options" do
|
11
|
+
it "generates an string of length between min and max" do
|
12
|
+
expect(string.length).to satisfy { |length| ((min <= length) && ( length <= max )) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "#ascii_string" do
|
17
|
+
it_behaves_like "string generation with no options" do
|
18
|
+
subject(:string) { random_ascii_of_length_between(min,max) }
|
19
|
+
end
|
20
|
+
end
|
11
21
|
|
12
|
-
|
13
|
-
|
22
|
+
context "#unicode_string" do
|
23
|
+
it_behaves_like "string generation with no options" do
|
24
|
+
subject(:string) { random_unicode_of_length(min,max) }
|
25
|
+
end
|
14
26
|
end
|
27
|
+
|
15
28
|
end
|
16
29
|
|
17
|
-
|
30
|
+
describe "requesting an string with spaces" do
|
31
|
+
|
32
|
+
let(:options) { {:spaces => true} }
|
18
33
|
|
19
|
-
|
20
|
-
let(:max) { 100 }
|
34
|
+
shared_examples "string generation with spaces" do
|
21
35
|
|
22
|
-
|
36
|
+
let(:num_spaces) { string.chars.inject(0) { |a,v| if (v!=" ") then a+=1 else a end } }
|
23
37
|
|
24
|
-
|
25
|
-
|
38
|
+
it "generates an string of length between min and max" do
|
39
|
+
expect(string.length).to satisfy { |length| ((min <= length) && ( length <= (max+num_spaces) )) }
|
40
|
+
end
|
41
|
+
|
42
|
+
it "generate a sentence with spaces" do
|
43
|
+
expect(num_spaces).to be > 0
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "#ascii_string" do
|
48
|
+
it_behaves_like "string generation with spaces" do
|
49
|
+
subject(:string) { random_ascii_of_length_between(min, max, options) }
|
50
|
+
end
|
26
51
|
end
|
27
52
|
|
53
|
+
context "#unicode_string" do
|
54
|
+
it_behaves_like "string generation with spaces" do
|
55
|
+
subject(:string) { random_unicode_of_length(min, max, options) }
|
56
|
+
end
|
57
|
+
end
|
28
58
|
end
|
29
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rand-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pere Urbon-Bayes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|