Word generator for ruby testing
Does someone know of a good ruby testing library for generating English (or maybe also those Latin "lor开发者_开发知识库em ipsum") words? Another nice thing would be to specify some additional options (e.g. the word length, only use names). Does such a thing exist?
Check out Faker. For example,
ruby-1.8.7-p302 > Faker::Lorem.sentence
=> "Enim molestiae incidunt rem ipsum perferendis beatae excepturi tenetur."
ruby-1.8.7-p302 > Faker::Name.name
=> "Agnes Hand II"
I'm the author of the gem lorem_ipsum_amet
which you'll find here:
- Rubygems: https://rubygems.org/gems/lorem_ipsum_amet
- Homepage: http://yagooar.github.io/lorem_ipsum_amet/
- Source code: https://github.com/yagooar/lorem_ipsum_amet
For now, it only produces Latin text, but you can use various parameters. These are the most common methods:
LoremIpsum.lorem_ipsum # default Lorem Ipsum text
LoremIpsum.text # alias for #lorem_ipsum
LoremIpsum.placeholder_image(400, 300) # placeholder image
LoremIpsum.lorem_ipsum(50) # 50 characters
LoremIpsum.lorem_ipsum(paragraphs: 4) # 4 paragraphs
LoremIpsum.lorem_ipsum(words: 100) # 100 words
LoremIpsum.lorem_ipsum(words: 100, html: true) # 100 words, paragraphs joined by <br />
LoremIpsum.lorem_ipsum(50, join: "\r\n") # join paragraph with a custom string
LoremIpsum.random # one random paragraph starting at a random position
LoremIpsum.random(paragraphs: 4) # 4 random paragraphs
LoremIpsum.short # a short text
LoremIpsum.long # a long text
There is also a Rails integration for rendering blind texts & placeholder images in your views:
ERB:
<%= text_area_tag 'placeholder', lorem_ipsum %>
<%= image_tag placeholder_image(200, 300) %>
HAML:
%p= lorem_ipsum(paragraphs: 5)
= image_tag placeholder_image(250)
Some more features are planned (adding multiple language support). Just check out the repository for more details on the current and future features.
have a look at Randexp http://github.com/mattetti/randexp
It gives you a tight control on what's generated
精彩评论