Every repository with this icon (
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
Manifest | ||
| |
README.markdown | ||
| |
lib/ | ||
| |
test/ |
Sequency
- A sequence generator for Ruby *
Sequency helps out with generating sequences for test factories. It could also be useful for other situations, but in the few minutes that I've been sitting here I haven't thought of any such cases. Maybe I should say that it's mainly for test factories, and if you come up with any other good uses for it you should email me so that I'll know about them too.
Practical Example
Let's say you have a Cat class. That class has attributes like color, age, and name. When you're testing the Cat class you don't want to have to come up with all sorts of names yourself, and you also don't want to name every cat the same thing because then it would become very likely that when a test passed it was actually because a different cat stayed around too long. Enter Sequency. You could write a script like the following to generate new cats at random:
require 'sequency'
Sequence.define(:cat_name) do |i|
"Mr. Meowsworth ##{i}"
end
Sequence.define(:cat_age) do |i|
i
end
def build_cat
cat = Cat.new
cat.name = Sequence.next(:cat_name)
cat.color = "gray"
cat.age = Sequence.next(:cat_age)
cat
end
Sequency will make it so that every time you call build_cat a new cat will be created with a name in the sequence "Mr. Meowsworth #n." Also, the cat generated will be one year older each time a cat is built.
Questions/Comments
If you have any questions about Sequency contact me at alan@hellotheory.com or send me a message on GitHub.
License
Copyright (c) 2008 Alan Johnson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.








