Module: Test::Unit::Given::Any
- Included in:
- TestCase
- Defined in:
- lib/test/unit/given/any.rb
Overview
Public: Provides the ability to vend arbitrary values without using literals, or long calls to Faker. This has two levels of utility:
helper methods - #any_number, #any_int, #any_string provide arbitrary primitives
to make it clear what numbers, ints, and strings in your tests are
relevant. Arbitrary values should use one of these any_ helpers.
any sort of any - you can define your own “any” values by using #new_any, which allows you to
extend things if you like. Of course, you could just make your own any_method as well.
Constant Summary collapse
- MAX_RAND =
50000
Instance Method Summary collapse
-
#any(sym, options = {}) ⇒ Object
Public: Get a predefined, arbitrary any.
-
#any_int(*options) ⇒ Object
Public: Returns an integer.
-
#any_number(*options) ⇒ Object
Public: Get any number; one that doesn’t matter.
-
#any_string(options = {}) ⇒ Object
Public: Get an arbitrary string of any potential length (the real max is 2048 characters if you don’t override it).
-
#new_any(any, &block) ⇒ Object
Public: Create a new any that can be retrieved via #any.
Instance Method Details
#any(sym, options = {}) ⇒ Object
Public: Get a predefined, arbitrary any.
sym - the any that has been defined already. By default, the following are defined:
:string - does any_string
String - does any_string
:number - does any_number
Numeric - does any_number
Float - does any_number
:int - does any_int
Fixnum - does any_int
Integer - does any_int
options - whatever options are relevant to the user-defined any
Example
new_any(:foo) do ||
if [:bar]
'bar'
else
'quux'
end
end
some_foo = any :foo
some_other_foo = any :foo, :bar => true
72 73 74 |
# File 'lib/test/unit/given/any.rb', line 72 def any(sym, = {}) anies[sym].call() end |
#any_int(*options) ⇒ Object
Public: Returns an integer. options is the same as for #any_number
28 29 30 |
# File 'lib/test/unit/given/any.rb', line 28 def any_int(*) any :int, end |
#any_number(*options) ⇒ Object
Public: Get any number; one that doesn’t matter
options - options to control what sort of number comes back:
:positive - make sure that the number is greater than zero
:negative - make sure that the number is less than zero
23 24 25 |
# File 'lib/test/unit/given/any.rb', line 23 def any_number(*) any :number, end |
#any_string(options = {}) ⇒ Object
Public: Get an arbitrary string of any potential length (the real max is 2048 characters if you don’t override it)
options - options to control the returned string
:max the max size of the string you want
:min the minimum size we want to come back
Example
any_string :max => 255 # => ensure it'll fit into a varchar(255)
any_string :min => 1024 # at least 1024 characters
43 44 45 |
# File 'lib/test/unit/given/any.rb', line 43 def any_string( = {}) any :string, end |
#new_any(any, &block) ⇒ Object
Public: Create a new any that can be retrieved via #any
any - the identifer of your new any. Can be anything though a Symbol or classname would be appropriate block - the block that will be called whenever you #any your any.
80 81 82 |
# File 'lib/test/unit/given/any.rb', line 80 def new_any(any,&block) anies[any] = block end |