can_has_fixtures 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -3,10 +3,10 @@
3
3
  Easily create fixtures.
4
4
 
5
5
  Author:: Ben Burkert (mailto:ben@benburkert.com)
6
- Version:: 0.1.0
6
+ Version:: 0.1.1
7
7
  Copyright:: Copyright (c) 2008 Ben Burkert. All rights reserved.
8
8
  License:: New BSD License (http://opensource.org/licenses/bsd-license.php)
9
- Website:: http://canhasgems.rubyforge.org/can_has_fixtures/
9
+ Website:: http://canhasgems.rubyforge.org/can_has_fixtures
10
10
  Repository:: git://github.com/benburkert/can_has_fixtures.git
11
11
 
12
12
  == Dependencies
@@ -74,5 +74,4 @@ simply call +fixture+ within the body of the spec:
74
74
 
75
75
  @post.should_not be_valid
76
76
  end
77
- end
78
-
77
+ end
@@ -1,5 +1,6 @@
1
1
  class Random
2
2
 
3
+ @@used ||= []
3
4
  WORDS_PER_SENTENCE = 3..20
4
5
  SENTENCES_PER_PARAGRAPH = 3..8
5
6
  TLDS = %w[com net org biz info gov]
@@ -46,20 +47,60 @@ class Random
46
47
  [true, false].random
47
48
  end
48
49
 
49
- def word
50
- dictionary.random
50
+ def satisfies?(value, options)
51
+ return false if @@used.include?(value) if options[:unique]
52
+ return false if value.size > options[:max] if options[:max]
53
+ return false if value.size < options[:min] if options[:min]
54
+ true
51
55
  end
52
56
 
53
- def sentence(punctuate = true)
54
- WORDS_PER_SENTENCE.random.random.words.join(' ') << (punctuate && '.')
57
+ def default_word_options
58
+ {:used => true}
55
59
  end
56
60
 
57
- def paragraph(end_with_newline = true)
58
- SENTENCES_PER_PARAGRAPH.random.random.sentences.join(' ') << (end_with_newline && '\n')
61
+ def word(options = default_word_options)
62
+ word = dictionary.random
63
+ word = dictionary.random until satisfies?(word, options)
64
+
65
+ @@used << word if options[:used]
66
+
67
+ word
59
68
  end
60
69
 
61
- def email
62
- "#{word}@#{word}.#{TLDS.random}"
70
+ def default_sentence_options
71
+ default_word_options.merge(:punctuate => true)
72
+ end
73
+
74
+ def sentence(options = default_sentence_options)
75
+ sentence = WORDS_PER_SENTENCE.random.random.words(options.merge(:used => false)).join(' ')
76
+ until satisfies?(sentence, options)
77
+ sentence = WORDS_PER_SENTENCE.random.random.words(options.merge(:used => false)).join(' ')
78
+ end
79
+
80
+ sentence << '.' if options[:punctuate]
81
+ @@used << sentence if options[:used]
82
+
83
+ sentence
84
+ end
85
+
86
+ def default_paragraph_options
87
+ default_sentence_options.merge(:end_with_line => true)
88
+ end
89
+
90
+ def paragraph(options = default_paragraph_options)
91
+ paragraph = SENTENCES_PER_PARAGRAPH.random.random.sentences(options).join(' ')
92
+ until satisfies?(paragraph, options)
93
+ paragraph = SENTENCES_PER_PARAGRAPH.random.random.sentences(options).join(' ')
94
+ end
95
+
96
+ paragraph << '\n' if options[:end_with_line]
97
+ @@used << paragraph if options[:end_with_line]
98
+
99
+ paragraph
100
+ end
101
+
102
+ def email(options = {})
103
+ "#{word(options)}@#{word(options)}.#{TLDS.random}"
63
104
  end
64
105
 
65
106
  def url
@@ -1,3 +1,3 @@
1
1
  module CanHasFixtures
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: can_has_fixtures
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-18 00:00:00 -05:00
12
+ date: 2008-03-25 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15