rand-rspec 0.0.3 → 0.0.4

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
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8b84f9a7bd4ee81ab40804709403c10ea68757c
4
- data.tar.gz: b377860fce0d1ae7f1130fbe161a4705796bb005
3
+ metadata.gz: aee728c8432b16c2c12d719dab61b7114e0a22bc
4
+ data.tar.gz: eea5fc928ebc40faedf70b000fa29666b35ada4e
5
5
  SHA512:
6
- metadata.gz: 8870a35e78ebb92147b2ff2cace6a4200b40d9cfb00af1b8ee7aecea8524627b616d198c65ffa05605892b5108d2cf7e93c0704496ac755b4d0f59e7d11dbc5b
7
- data.tar.gz: ed01dc055849d586433bac35b1c08398b29854549e17abbc228e358df87db7d23aa85f594846e05b74b92c1de5c7c4397d8fc7b035d2ad1be1875c43dcd10699
6
+ metadata.gz: bba1ffdf3461a3235e70b22b769e23e93867a8abd4e8239e38c7dd872bab04ade6cb3bc2db44a2148d244eedb5b519136184e21db104dd9d9331bafe91df94f7
7
+ data.tar.gz: af283dbcf03a3bae34dacf8fc05fecf6ad6b622b1b3fa65927c3159511578df3d0d32436317dfa53044f9fe20b1e0d0b9b99379a03b35d844ae31d0e447ec221
@@ -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 = random_number_between(min, max)
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
- acc << CHARS[rand(CHARS.size)].chr
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
- code_point = random_number_between(BLOCK_STARTS[block], BLOCK_ENDS[block])
64
- acc << code_point.chr(Encoding::UTF_8)
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
@@ -1,3 +1,3 @@
1
1
  module Randtest
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -2,28 +2,58 @@ require 'spec_helper'
2
2
 
3
3
  describe 'RandTest::Strings' do
4
4
 
5
- context "when requesting an ascii string" do
5
+ let(:min) { 10 }
6
+ let(:max) { 100 }
6
7
 
7
- let(:min) { 10 }
8
- let(:max) { 100 }
8
+ describe "using no modification options" do
9
9
 
10
- subject(:ascii_string) { random_ascii_of_length_between(min,max) }
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
- it "generates an string of length between min and max" do
13
- expect(ascii_string.length).to satisfy { |length| ((min <= length) && ( length <= max )) }
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
- context "when requesting an unicode string" do
30
+ describe "requesting an string with spaces" do
31
+
32
+ let(:options) { {:spaces => true} }
18
33
 
19
- let(:min) { 0 }
20
- let(:max) { 100 }
34
+ shared_examples "string generation with spaces" do
21
35
 
22
- subject(:unicode_string) { random_unicode_of_length(min, max) }
36
+ let(:num_spaces) { string.chars.inject(0) { |a,v| if (v!=" ") then a+=1 else a end } }
23
37
 
24
- it "generates an string of a given length" do
25
- expect(unicode_string.length).to satisfy { |length| ((min <= length) && ( length <= max )) }
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.3
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-16 00:00:00.000000000 Z
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler