word_gen 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 +4 -4
- data/.gitignore +1 -0
- data/lib/word_gen/generator.rb +2 -1
- data/lib/word_gen/version.rb +1 -1
- data/spec/spec_helper.rb +4 -0
- data/spec/word_gen/generator_spec.rb +49 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7233939662eca4e9857932d846ee0c55acf9cea
|
4
|
+
data.tar.gz: cbd2d00472d24f7d2ef5265f49cf351ca0c70d02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ddd7d54f911eb39e01c2519c05e16751dd07931e6a2fdc40fe8816fad20694416d7c563045c27442ac2c99c2731e7e3ccc19107bdd7a126eeb8c9c6bdbce43f
|
7
|
+
data.tar.gz: 6b5d64ba38270f6934d8d7b3ab9bc00a832ee139c1710a8861e12dce0b088c4c18850a680c75db1ce3ac7d552a7996c2849b41ef7377648b32b1dbbe4f9003cc
|
data/.gitignore
CHANGED
data/lib/word_gen/generator.rb
CHANGED
@@ -4,7 +4,8 @@ class WordGen::Generator
|
|
4
4
|
|
5
5
|
def initialize word_length, character_set, writer = $stdout
|
6
6
|
@word_length, @character_set, @writer = Integer(word_length), character_set.map(&:to_s), writer
|
7
|
-
|
7
|
+
|
8
|
+
if @word_length < 1
|
8
9
|
fail ArgumentError, 'word_length need to be positibe'
|
9
10
|
end
|
10
11
|
end
|
data/lib/word_gen/version.rb
CHANGED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'word_gen'
|
3
|
+
|
4
|
+
describe WordGen::Generator do
|
5
|
+
let(:generator) { build_generator(1, WordGen::Modes::NUMERIC) }
|
6
|
+
|
7
|
+
it 'writes to stdout by default' do
|
8
|
+
expect($stdout).to receive(:puts).exactly(10).times
|
9
|
+
generator.start
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'can write to a file' do
|
13
|
+
file_name = 'test_file'
|
14
|
+
File.open file_name, 'w+' do |file|
|
15
|
+
build_generator(1, WordGen::Modes::NUMERIC, file).start
|
16
|
+
end
|
17
|
+
expect(`wc -l #{file_name}`).to include('10')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'supports all modes' do
|
21
|
+
WordGen::Modes.constants.each do |m|
|
22
|
+
set = WordGen::Modes.class_eval m.to_s
|
23
|
+
g = build_generator(1, set, FakeWriter.new)
|
24
|
+
expect(g.start).to eq(set.size)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'does not work for a word length of zero' do
|
29
|
+
expect {build_generator(0, WordGen::Modes::NUMERIC)}.to raise_error(ArgumentError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'does not work for a negative word length' do
|
33
|
+
expect {build_generator(-1, WordGen::Modes::NUMERIC)}.to raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_generator(word_length, mode, writer = nil)
|
37
|
+
if writer
|
38
|
+
described_class.new(word_length, mode, writer)
|
39
|
+
else
|
40
|
+
described_class.new(word_length, mode)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class FakeWriter
|
45
|
+
def puts(*)
|
46
|
+
# NoOp
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: word_gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Schmidt
|
@@ -84,6 +84,8 @@ files:
|
|
84
84
|
- lib/word_gen/generator.rb
|
85
85
|
- lib/word_gen/modes.rb
|
86
86
|
- lib/word_gen/version.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
- spec/word_gen/generator_spec.rb
|
87
89
|
- word_gen.gemspec
|
88
90
|
homepage: http://schlubbi.io
|
89
91
|
licenses:
|
@@ -109,4 +111,6 @@ rubygems_version: 2.0.3
|
|
109
111
|
signing_key:
|
110
112
|
specification_version: 4
|
111
113
|
summary: Generate WordLists
|
112
|
-
test_files:
|
114
|
+
test_files:
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
- spec/word_gen/generator_spec.rb
|