random-word 1.3.0 → 2.0.0
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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -16
- data/LICENSE.txt +1 -1
- data/README.markdown +28 -21
- data/Rakefile +3 -39
- data/lib/random-word.rb +0 -1
- data/lib/random_word.rb +35 -5
- data/lib/random_word/version.rb +3 -0
- data/random-word.gemspec +38 -0
- metadata +59 -86
- data/.rspec +0 -0
- data/VERSION +0 -1
- data/lib/random_word/machinist.rb +0 -27
- data/spec/random-word_spec.rb +0 -7
- data/spec/random_word/machinist_spec.rb +0 -38
- data/spec/random_word_spec.rb +0 -92
- data/spec/spec_helper.rb +0 -12
- data/spec/support/matchers.rb +0 -6
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5dfad3232b235871bbe1e413c1a4009d65417324
|
4
|
+
data.tar.gz: f72d97cf5b9cf3b4225715de1239be97c39a5006
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f4c7ac7f3150ccd28caa11341ceaa952cebbbd9725c6d2a568aedea14ddac466ea4fe91bb17efa2d963a63270ea80c58d88d48837cb8b389bd8f5973d898a7c6
|
7
|
+
data.tar.gz: da1e4846c7675849cbb19ccdafda6b07ecc7cfbc8a8a14051c17f184fa83daa0d174e7d0c1c7edba511a2df96c6ecf6c5ac7af1dd92c6644c9b69a8324a5f1ca
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,17 +1,4 @@
|
|
1
|
-
source
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
1
|
+
source 'https://rubygems.org'
|
5
2
|
|
6
|
-
#
|
7
|
-
|
8
|
-
group :development do
|
9
|
-
gem "rspec", "~> 2.3.0"
|
10
|
-
gem "yard", "~> 0.6.0"
|
11
|
-
gem "bundler", "~> 1.0.0"
|
12
|
-
gem "jeweler", "~> 1.6.2"
|
13
|
-
gem "rcov", ">= 0"
|
14
|
-
gem "machinist", ">=2.0.0.beta2"
|
15
|
-
gem "activesupport"
|
16
|
-
gem "i18n"
|
17
|
-
end
|
3
|
+
# Specify your gem's dependencies in random-word.gemspec
|
4
|
+
gemspec
|
data/LICENSE.txt
CHANGED
data/README.markdown
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
random-word
|
2
2
|
====
|
3
|
+
[](https://travis-ci.org/openlogic/random-word)
|
4
|
+
[](https://coveralls.io/github/openlogic/random-word?branch=master)
|
3
5
|
|
4
6
|
A random word generator intended for use in test data factories. This
|
5
7
|
library uses a large list (the wordnet corpus) of english words and
|
@@ -12,31 +14,24 @@ Usage
|
|
12
14
|
You can get a random word any where you need one. Just request the
|
13
15
|
next of which ever word flavor you prefer.
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
```ruby
|
18
|
+
RandomWord.adjs.next #=> "pugnacious"
|
19
|
+
RandomWord.nouns.next #=> "audience"
|
20
|
+
```
|
17
21
|
|
18
22
|
### Factory Girl
|
19
23
|
|
20
24
|
This library was first developed to use in factories. It can be used
|
21
25
|
with Factory Girl like this.
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
```ruby
|
28
|
+
Factory.define(:user) do |u|
|
29
|
+
u.name { "#{RandomWord.adjs.next} User" }
|
30
|
+
u.email { "#{name.gsub(/ +/, '.')}@example.com" }
|
31
|
+
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
### Machinist
|
31
|
-
|
32
|
-
|
33
|
-
For Machinist a `#sw` (short for serial word) method is provided. It works exactly like `#sn`
|
34
|
-
but it returns a string instead of a number.
|
35
|
-
|
36
|
-
User.blueprint do
|
37
|
-
name { "#{sw.capitalize} User" }
|
38
|
-
email { "#{sw}.user@example.com" }
|
39
|
-
end
|
33
|
+
Factory(:user) #=> ...
|
34
|
+
```
|
40
35
|
|
41
36
|
Exclusion
|
42
37
|
----
|
@@ -44,12 +39,24 @@ Exclusion
|
|
44
39
|
Words may be excluded by pattern, or exact match. To do this just add
|
45
40
|
an object that responds to `#===` to the exclude list.
|
46
41
|
|
47
|
-
|
48
|
-
|
42
|
+
```ruby
|
43
|
+
RandomWord.exclude_list << /fo+/
|
44
|
+
RandomWord.exclude_list << 'bar'
|
45
|
+
```
|
49
46
|
|
50
47
|
This will prevent the return of the exact string `"bar"` and any word
|
51
48
|
which matches the regex `/fo+/`.
|
52
49
|
|
50
|
+
Constraining word length
|
51
|
+
----
|
52
|
+
|
53
|
+
You can constrain the length of words provided by the `nouns` and `adjs` iterators like so:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
RandomWord.nouns(not_longer_than: 56).next
|
57
|
+
RandomWord.adjs(not_shorter_than: 3).next
|
58
|
+
RandomWord.adjs(not_shorter_than: 16, not_longer_than: 672).next
|
59
|
+
```
|
53
60
|
|
54
61
|
Contributing to random-word
|
55
62
|
----
|
@@ -70,6 +77,6 @@ Contributing to random-word
|
|
70
77
|
Copyright
|
71
78
|
----
|
72
79
|
|
73
|
-
Copyright (c) 2011 OpenLogic,
|
80
|
+
Copyright (c) 2011 OpenLogic, Inc. See LICENSE.txt for
|
74
81
|
further details.
|
75
82
|
|
data/Rakefile
CHANGED
@@ -1,42 +1,6 @@
|
|
1
|
-
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
2
3
|
|
3
|
-
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "random-word"
|
18
|
-
gem.homepage = "http://github.com/pezra/random-word"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{Pick random words for factory data}
|
21
|
-
gem.description = %Q{A random word generator intended for use in test data factories. This library uses a large list (the wordnet corpus) of english words and provides an enumerator interface to that corpus that will return the words in a random order without repeats.}
|
22
|
-
gem.email = "pezra@barelyenough.org"
|
23
|
-
gem.authors = ["Peter Williams"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
27
|
-
|
28
|
-
require 'rspec/core'
|
29
|
-
require 'rspec/core/rake_task'
|
30
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
-
end
|
33
|
-
|
34
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
-
spec.rcov = true
|
37
|
-
end
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
38
5
|
|
39
6
|
task :default => :spec
|
40
|
-
|
41
|
-
require 'yard'
|
42
|
-
YARD::Rake::YardocTask.new
|
data/lib/random-word.rb
CHANGED
data/lib/random_word.rb
CHANGED
@@ -9,23 +9,40 @@ require 'pathname'
|
|
9
9
|
module RandomWord
|
10
10
|
module EachRandomly
|
11
11
|
attr_accessor :random_word_exclude_list
|
12
|
+
attr_accessor :min_length
|
13
|
+
attr_accessor :max_length
|
12
14
|
|
13
15
|
def each_randomly(&blk)
|
14
16
|
used = Set.new
|
15
|
-
|
16
|
-
|
17
|
+
skipped = Set.new
|
18
|
+
loop do
|
17
19
|
idx = next_unused_idx(used)
|
18
20
|
used << idx
|
19
21
|
word = at(idx)
|
20
|
-
|
22
|
+
if excluded?(word)
|
23
|
+
skipped << idx
|
24
|
+
next
|
25
|
+
end
|
21
26
|
yield word
|
27
|
+
used.subtract(skipped)
|
28
|
+
skipped.clear
|
22
29
|
end
|
23
30
|
|
24
31
|
rescue OutOfWords
|
25
32
|
# we are done.
|
26
33
|
end
|
27
34
|
|
35
|
+
def set_constraints(opts = {})
|
36
|
+
@min_length = opts[:not_shorter_than] || 1
|
37
|
+
@max_length = opts[:not_longer_than] || Float::INFINITY
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.extended(mod)
|
41
|
+
mod.set_constraints
|
42
|
+
end
|
43
|
+
|
28
44
|
private
|
45
|
+
|
29
46
|
def next_unused_idx(used)
|
30
47
|
idx = rand(length)
|
31
48
|
try = 1
|
@@ -37,22 +54,34 @@ module RandomWord
|
|
37
54
|
|
38
55
|
idx
|
39
56
|
end
|
57
|
+
|
58
|
+
def excluded?(word)
|
59
|
+
exclude_list = Array(@random_word_exclude_list)
|
60
|
+
exclude_list.any? {|r| r === word} || word.length < min_length || (!(max_length.nil?) && word.length > max_length)
|
61
|
+
end
|
62
|
+
|
40
63
|
class OutOfWords < Exception; end
|
41
64
|
end
|
42
65
|
|
43
66
|
class << self
|
67
|
+
attr_accessor :word_list
|
68
|
+
|
44
69
|
def exclude_list
|
45
70
|
@exclude_list ||= []
|
46
71
|
end
|
47
72
|
|
48
73
|
# @return [Enumerator] Random noun enumerator
|
49
|
-
def nouns
|
74
|
+
def nouns(opts = {})
|
50
75
|
@nouns ||= enumerator(load_word_list("nouns.dat"), exclude_list)
|
76
|
+
word_list.set_constraints(opts)
|
77
|
+
@nouns
|
51
78
|
end
|
52
79
|
|
53
80
|
# @return [Enumerator] Random adjective enumerator
|
54
|
-
def adjs
|
81
|
+
def adjs(opts = {})
|
55
82
|
@adjs ||= enumerator(load_word_list("adjs.dat"), exclude_list)
|
83
|
+
word_list.set_constraints(opts)
|
84
|
+
@adjs
|
56
85
|
end
|
57
86
|
|
58
87
|
# @return [Enumerator] Random phrase enumerator
|
@@ -69,6 +98,7 @@ module RandomWord
|
|
69
98
|
# Create a random, non-repeating enumerator for a list of words
|
70
99
|
# (or anything really).
|
71
100
|
def enumerator(word_list, list_of_regexs_or_strings_to_exclude = [])
|
101
|
+
@word_list = word_list
|
72
102
|
word_list.extend EachRandomly
|
73
103
|
word_list.random_word_exclude_list = list_of_regexs_or_strings_to_exclude
|
74
104
|
word_list.enum_for(:each_randomly)
|
data/random-word.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'random_word/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'random-word'
|
8
|
+
spec.version = RandomWord::VERSION
|
9
|
+
spec.authors = ['Peter Williams', 'Todd Thomas']
|
10
|
+
spec.email = ['pezra@barelyenough.org', 'todd.thomas@openlogic.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Pick random words for factory data}
|
13
|
+
spec.description = %q{A random word generator intended for use in test data factories. This library uses a large list (the wordnet corpus) of english words and provides an enumerator interface to that corpus that will return the words in a random order without repeats.}
|
14
|
+
spec.homepage = 'https://github.com/openlogic/random-word'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
34
|
+
spec.add_development_dependency 'coveralls'
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_development_dependency 'machinist', '~>2.0'
|
38
|
+
end
|
metadata
CHANGED
@@ -1,161 +1,134 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: random-word
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Peter Williams
|
8
|
+
- Todd Thomas
|
9
9
|
autorequire:
|
10
|
-
bindir:
|
10
|
+
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
12
|
+
date: 2017-04-21 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
requirement:
|
18
|
-
none: false
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
19
17
|
requirements:
|
20
|
-
- - ~>
|
18
|
+
- - "~>"
|
21
19
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
20
|
+
version: '1.14'
|
23
21
|
type: :development
|
24
22
|
prerelease: false
|
25
|
-
version_requirements:
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: yard
|
28
|
-
requirement: &2155117900 !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
24
|
requirements:
|
31
|
-
- - ~>
|
25
|
+
- - "~>"
|
32
26
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: *2155117900
|
27
|
+
version: '1.14'
|
37
28
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
39
|
-
requirement:
|
40
|
-
none: false
|
29
|
+
name: coveralls
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
41
31
|
requirements:
|
42
|
-
- -
|
32
|
+
- - ">="
|
43
33
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
34
|
+
version: '0'
|
45
35
|
type: :development
|
46
36
|
prerelease: false
|
47
|
-
version_requirements:
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: jeweler
|
50
|
-
requirement: &2155116940 !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
38
|
requirements:
|
53
|
-
- -
|
39
|
+
- - ">="
|
54
40
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
56
|
-
type: :development
|
57
|
-
prerelease: false
|
58
|
-
version_requirements: *2155116940
|
41
|
+
version: '0'
|
59
42
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
61
|
-
requirement:
|
62
|
-
none: false
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
63
45
|
requirements:
|
64
|
-
- -
|
46
|
+
- - "~>"
|
65
47
|
- !ruby/object:Gem::Version
|
66
|
-
version: '0'
|
48
|
+
version: '10.0'
|
67
49
|
type: :development
|
68
50
|
prerelease: false
|
69
|
-
version_requirements:
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: machinist
|
72
|
-
requirement: &2155115980 !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
52
|
requirements:
|
75
|
-
- -
|
53
|
+
- - "~>"
|
76
54
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
78
|
-
type: :development
|
79
|
-
prerelease: false
|
80
|
-
version_requirements: *2155115980
|
55
|
+
version: '10.0'
|
81
56
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
83
|
-
requirement:
|
84
|
-
none: false
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
85
59
|
requirements:
|
86
|
-
- -
|
60
|
+
- - "~>"
|
87
61
|
- !ruby/object:Gem::Version
|
88
|
-
version: '0'
|
62
|
+
version: '3.0'
|
89
63
|
type: :development
|
90
64
|
prerelease: false
|
91
|
-
version_requirements:
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.0'
|
92
70
|
- !ruby/object:Gem::Dependency
|
93
|
-
name:
|
94
|
-
requirement:
|
95
|
-
none: false
|
71
|
+
name: machinist
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
96
73
|
requirements:
|
97
|
-
- -
|
74
|
+
- - "~>"
|
98
75
|
- !ruby/object:Gem::Version
|
99
|
-
version: '0'
|
76
|
+
version: '2.0'
|
100
77
|
type: :development
|
101
78
|
prerelease: false
|
102
|
-
version_requirements:
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '2.0'
|
103
84
|
description: A random word generator intended for use in test data factories. This
|
104
85
|
library uses a large list (the wordnet corpus) of english words and provides an
|
105
86
|
enumerator interface to that corpus that will return the words in a random order
|
106
87
|
without repeats.
|
107
|
-
email:
|
88
|
+
email:
|
89
|
+
- pezra@barelyenough.org
|
90
|
+
- todd.thomas@openlogic.com
|
108
91
|
executables: []
|
109
92
|
extensions: []
|
110
|
-
extra_rdoc_files:
|
111
|
-
- LICENSE.txt
|
112
|
-
- README.markdown
|
93
|
+
extra_rdoc_files: []
|
113
94
|
files:
|
114
|
-
- .document
|
115
|
-
- .
|
95
|
+
- ".document"
|
96
|
+
- ".gitignore"
|
97
|
+
- ".travis.yml"
|
116
98
|
- Gemfile
|
117
99
|
- HISTORY.markdown
|
118
100
|
- LICENSE.txt
|
119
101
|
- README.markdown
|
120
102
|
- Rakefile
|
121
|
-
- VERSION
|
122
103
|
- data/adjs.dat
|
123
104
|
- data/nouns.dat
|
124
105
|
- lib/random-word.rb
|
125
106
|
- lib/random_word.rb
|
126
|
-
- lib/random_word/
|
127
|
-
-
|
128
|
-
|
129
|
-
- spec/random_word_spec.rb
|
130
|
-
- spec/spec_helper.rb
|
131
|
-
- spec/support/matchers.rb
|
132
|
-
has_rdoc: true
|
133
|
-
homepage: http://github.com/pezra/random-word
|
107
|
+
- lib/random_word/version.rb
|
108
|
+
- random-word.gemspec
|
109
|
+
homepage: https://github.com/openlogic/random-word
|
134
110
|
licenses:
|
135
111
|
- MIT
|
112
|
+
metadata:
|
113
|
+
allowed_push_host: https://rubygems.org
|
136
114
|
post_install_message:
|
137
115
|
rdoc_options: []
|
138
116
|
require_paths:
|
139
117
|
- lib
|
140
118
|
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
-
none: false
|
142
119
|
requirements:
|
143
|
-
- -
|
120
|
+
- - ">="
|
144
121
|
- !ruby/object:Gem::Version
|
145
122
|
version: '0'
|
146
|
-
segments:
|
147
|
-
- 0
|
148
|
-
hash: 2056485225028355172
|
149
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
-
none: false
|
151
124
|
requirements:
|
152
|
-
- -
|
125
|
+
- - ">="
|
153
126
|
- !ruby/object:Gem::Version
|
154
127
|
version: '0'
|
155
128
|
requirements: []
|
156
129
|
rubyforge_project:
|
157
|
-
rubygems_version:
|
130
|
+
rubygems_version: 2.6.11
|
158
131
|
signing_key:
|
159
|
-
specification_version:
|
132
|
+
specification_version: 4
|
160
133
|
summary: Pick random words for factory data
|
161
134
|
test_files: []
|
data/.rspec
DELETED
File without changes
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.3.0
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module RandomWord
|
2
|
-
module Machinist
|
3
|
-
# The serial word for the object being manufactured.
|
4
|
-
def serial_word
|
5
|
-
@serial_word ||= RandomWord.adjs.next
|
6
|
-
end
|
7
|
-
alias_method :sw, :serial_word
|
8
|
-
|
9
|
-
# The serial adjective for the object being manufactured.
|
10
|
-
def serial_adj
|
11
|
-
serial_word
|
12
|
-
end
|
13
|
-
|
14
|
-
# The serial noun for the object being manufactured.
|
15
|
-
def serial_noun
|
16
|
-
@serial_noun ||= RandomWord.nouns.next
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
begin
|
23
|
-
require 'machinist/lathe'
|
24
|
-
Machinist::Lathe.send(:include, RandomWord::Machinist)
|
25
|
-
rescue LoadError, NameError
|
26
|
-
# Machinist is not available
|
27
|
-
end
|
data/spec/random-word_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require File.expand_path("../spec_helper", File.dirname(__FILE__))
|
2
|
-
require 'machinist/machinable'
|
3
|
-
require 'machinist/blueprint'
|
4
|
-
require 'machinist/lathe'
|
5
|
-
require 'random_word/machinist'
|
6
|
-
|
7
|
-
describe RandomWord::Machinist do
|
8
|
-
let(:klass){ Class.new(Struct.new(:name,:role)) do
|
9
|
-
extend Machinist::Machinable
|
10
|
-
end
|
11
|
-
}
|
12
|
-
|
13
|
-
it "allows the use of #sw in blue prints" do
|
14
|
-
klass.blueprint do
|
15
|
-
name {sw}
|
16
|
-
end
|
17
|
-
klass.make.name.should_not be_nil
|
18
|
-
end
|
19
|
-
|
20
|
-
it "allows the use of #serial_word in blue prints" do
|
21
|
-
klass.blueprint do
|
22
|
-
name {serial_word}
|
23
|
-
end
|
24
|
-
klass.make.name.should_not be_nil
|
25
|
-
end
|
26
|
-
|
27
|
-
it "return same word for each call to serial_word" do
|
28
|
-
klass.blueprint do
|
29
|
-
name {serial_word}
|
30
|
-
role {serial_word}
|
31
|
-
end
|
32
|
-
|
33
|
-
klass.make.tap do |obj|
|
34
|
-
obj.name.should == obj.role
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
data/spec/random_word_spec.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require File.expand_path("spec_helper", File.dirname(__FILE__))
|
2
|
-
|
3
|
-
describe RandomWord, "enumerator" do
|
4
|
-
subject {RandomWord.enumerator(["aaa", "bbb", "ccc"])}
|
5
|
-
|
6
|
-
it "can get you the next word in its list" do
|
7
|
-
subject.next.should be_one_of(["aaa", "bbb", "ccc"])
|
8
|
-
end
|
9
|
-
|
10
|
-
it "raises error when it runs out of words" do
|
11
|
-
3.times{subject.next}
|
12
|
-
|
13
|
-
lambda{subject.next}.should raise_error(StopIteration)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "make sure each word is only returned once" do
|
17
|
-
already_received = []
|
18
|
-
3.times do
|
19
|
-
(new_word = subject.next).should_not be_one_of(already_received)
|
20
|
-
already_received << new_word
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe RandomWord do
|
26
|
-
after(:all) do
|
27
|
-
RandomWord.instance_eval{ @nouns, @adjs = nil, nil } # reset rspec effects
|
28
|
-
end
|
29
|
-
|
30
|
-
it "can return a random noun enumerator" do
|
31
|
-
RandomWord.nouns.should respond_to(:next)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "can return a random adj enumerator" do
|
35
|
-
RandomWord.adjs.should respond_to(:next)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "can return a random phrase enumerator" do
|
39
|
-
RandomWord.phrases.next.should be_a(String)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe RandomWord, "#exclude" do
|
44
|
-
let(:word_list) { ["aaa","ccc","c", "cab", "abc", "ace", "dad"] }
|
45
|
-
|
46
|
-
[
|
47
|
-
{:name => "normal words", :exclude => "ccc", :expected => Set.new(["aaa","c", "cab", "abc", "ace", "dad"])},
|
48
|
-
{:name => "regex", :exclude => /c/, :expected => Set.new(["aaa", "dad"])},
|
49
|
-
{:name => "list", :exclude => [/c/,/d/], :expected => Set.new(["aaa"])},
|
50
|
-
].each do |rec|
|
51
|
-
it "will not return an excluded #{rec[:name]}" do
|
52
|
-
subject = RandomWord.enumerator(word_list, rec[:exclude])
|
53
|
-
|
54
|
-
received_words = []
|
55
|
-
loop do
|
56
|
-
received_words << subject.next
|
57
|
-
end rescue StopIteration
|
58
|
-
|
59
|
-
Set.new(received_words).should == rec[:expected]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "RandomWord#nouns", "with exclusions" do
|
66
|
-
|
67
|
-
subject{ RandomWord.nouns }
|
68
|
-
|
69
|
-
before(:each) do
|
70
|
-
RandomWord.should_receive(:load_word_list).and_return(["aaa","bbb", "ccc"])
|
71
|
-
end
|
72
|
-
|
73
|
-
after(:each) do
|
74
|
-
RandomWord.exclude_list.clear
|
75
|
-
RandomWord.instance_eval{ @nouns, @adjs = nil, nil } # reset rspec effects
|
76
|
-
end
|
77
|
-
|
78
|
-
it "will not return an excluded word" do
|
79
|
-
RandomWord.exclude_list << "ccc"
|
80
|
-
|
81
|
-
received_words = []
|
82
|
-
loop do
|
83
|
-
received_words << subject.next
|
84
|
-
end
|
85
|
-
|
86
|
-
received_words.should_not include "ccc"
|
87
|
-
received_words.should include "aaa"
|
88
|
-
received_words.should include "bbb"
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
data/spec/spec_helper.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
require 'rspec'
|
4
|
-
require 'random-word'
|
5
|
-
|
6
|
-
# Requires supporting files with custom matchers and macros, etc,
|
7
|
-
# in ./support/ and its subdirectories.
|
8
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
-
|
10
|
-
RSpec.configure do |config|
|
11
|
-
|
12
|
-
end
|