kitchen 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/kitchen.rb +79 -0
  2. metadata +38 -0
@@ -0,0 +1,79 @@
1
+ #
2
+ # Used to create one of "everything", where everything includes objects that can be instantiated
3
+ # with no arguments
4
+ #
5
+ module KitchenSink
6
+ Version = '0.0.3'
7
+
8
+ class KitchenSinkError < StandardError #:nodoc
9
+ end
10
+
11
+ # Returns one of each object instantiated with it's default value
12
+ def everything
13
+ objects = []
14
+ ObjectSpace.each_object(Class) do |c|
15
+ if c.methods.include?('new')
16
+ begin
17
+ m = c.method(:new)
18
+ o = m.call if m.arity == -1
19
+ objects.push(o)
20
+ rescue ArgumentError, ThreadError, TypeError
21
+ end
22
+ end
23
+ end
24
+ objects
25
+ end
26
+
27
+ # Returns one of everything except the type specified (as a class)
28
+ # +klass+
29
+ def everything_but(klass)
30
+ begin
31
+ unless klass.is_a?(Class)
32
+ raise KitchenSinkError , "#{klass} isn't a Class"
33
+ end
34
+ rescue NoMethodError
35
+ raise KitchenSinkError, "#{klass} isn't a Class"
36
+ end
37
+ objects = everything
38
+ objects.delete_if do |o|
39
+ o.kind_of?(klass)
40
+ end
41
+ end
42
+
43
+ # Returns one of everything that cannot respond to the method
44
+ # +method+
45
+ def everything_that_cannot(method)
46
+ objects = everything
47
+ objects.delete_if do |o|
48
+ o.respond_to?(method)
49
+ end
50
+ end
51
+
52
+ # Returns one of everything that cannot be coereced into a specified class
53
+ # +klass+
54
+ def everything_that_cannot_be_coerced_into(klass)
55
+ objects = everything
56
+ objects.delete_if do |o|
57
+ begin
58
+ klass.new(o)
59
+ rescue
60
+ end
61
+ end
62
+ end
63
+ alias everything_that_aint everything_that_cannot_be_coerced_into
64
+
65
+ # Returns an array of common edge cases for a specified class
66
+ # +klass+
67
+ def edge_cases_for(klass)
68
+ objects = []
69
+ case
70
+ when klass == String
71
+ objects = %w[ "", " ", "\", "'", "`"]
72
+ when klass == Array
73
+ objects = [[], [1], [""], [0], [10000000000], [Class]]
74
+ when klass == Hash
75
+ objects = [{1 => nil}, {2=>[]}, {3 => "a"}, {4 => 0}, {}]
76
+ end
77
+ return objects
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,38 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.10
3
+ specification_version: 1
4
+ name: kitchen
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.3
7
+ date: 2005-11-18
8
+ summary: kitchen provides an easy way to destructively test your code.
9
+ require_paths:
10
+ - lib
11
+ email: foamdino@gmail.com
12
+ homepage: http://rubyforge.org/projects/kitchen/
13
+ rubyforge_project:
14
+ description: "kitchen gives you access to a whole array of objects to really test that your
15
+ code doesn't do something strange when given an odd value."
16
+ autorequire: kitchen
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: false
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ -
23
+ - ">"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.0.0
26
+ version:
27
+ platform: ruby
28
+ authors:
29
+ - Kev Jackson
30
+ files:
31
+ - lib/kitchen.rb
32
+ test_files: []
33
+ rdoc_options: []
34
+ extra_rdoc_files: []
35
+ executables: []
36
+ extensions: []
37
+ requirements: []
38
+ dependencies: []