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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b1773a868a5012f81f6205f90c4710164de75f5
4
- data.tar.gz: f5d1ffede2ace6132875c88d2991dca1310d911d
3
+ metadata.gz: a7233939662eca4e9857932d846ee0c55acf9cea
4
+ data.tar.gz: cbd2d00472d24f7d2ef5265f49cf351ca0c70d02
5
5
  SHA512:
6
- metadata.gz: 2a2864707f51f0dfe4ed2aa9b0d5569a3f405c76262675de60e0d88c851c577322b5c3f589a4f60e46afc6ae87a7641a43d197f92692995be299358b2e462a37
7
- data.tar.gz: d08cf85e7aac6db36f24caf079981ed914d21ff8f713a63ad42c2ac81697e8e337809eb8c97fcff6808d0682f14268211dcbe851b5b1253b0eb17925877a743e
6
+ metadata.gz: 9ddd7d54f911eb39e01c2519c05e16751dd07931e6a2fdc40fe8816fad20694416d7c563045c27442ac2c99c2731e7e3ccc19107bdd7a126eeb8c9c6bdbce43f
7
+ data.tar.gz: 6b5d64ba38270f6934d8d7b3ab9bc00a832ee139c1710a8861e12dce0b088c4c18850a680c75db1ce3ac7d552a7996c2849b41ef7377648b32b1dbbe4f9003cc
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ test_file
@@ -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
- if word_length < 1
7
+
8
+ if @word_length < 1
8
9
  fail ArgumentError, 'word_length need to be positibe'
9
10
  end
10
11
  end
@@ -1,3 +1,3 @@
1
1
  module WordGen
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,4 @@
1
+ require 'pry'
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -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.1
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