pass_nils_to 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ 8/15/08 - Initial import [Matthew Bass]
@@ -0,0 +1,16 @@
1
+ Copyright (c) 2007-2008 Matthew Bass (http://matthewbass.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4
+ and associated documentation files (the "Software"), to deal in the Software without
5
+ restriction, including without limitation the rights to use, copy, modify, merge, publish,
6
+ distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7
+ Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or
10
+ substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13
+ BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,54 @@
1
+ = pass_nils_to
2
+
3
+ Pass nils to your methods and see if they explode.
4
+
5
+ == Installation
6
+
7
+ Install the gem directly:
8
+
9
+ gem sources -a http://gems.github.com (you only have to do this once)
10
+ sudo gem install pelargir-pass_nils_to
11
+
12
+ Or install the gem in your Rails project:
13
+
14
+ gem sources -a http://gems.github.com
15
+ script/plugin install pelargir-pass_nils_to
16
+
17
+ Or clone the project:
18
+
19
+ git clone git://github.com/pelargir/pass_nils_to.git
20
+
21
+ == Usage
22
+
23
+ Pass nils to your methods thusly:
24
+
25
+ class Parser
26
+ def parse(arg1, arg2)
27
+ ...
28
+ end
29
+ end
30
+
31
+ parser = Parser.new
32
+ pass_nils_to(:parse, parser)
33
+
34
+ This would pass nils to the #parse method in these combinations:
35
+
36
+ parse(nil, "foo")
37
+ parse("foo", nil)
38
+ parse(nil, nil)
39
+
40
+ An arbitrary number of arguments are supported, so you can try passing
41
+ nils to methods with three arguments, four, five, etc.
42
+
43
+ == Running Unit Tests
44
+
45
+ Use the rake command to run the unit tests for the plugin. The tests require
46
+ that the Mocha gem be installed locally:
47
+
48
+ sudo gem install mocha
49
+
50
+ == Resources
51
+
52
+ Repository: http://github.com/pelargir/pass_nils_to/
53
+ Blog: http://matthewbass.com
54
+ Author: Matthew Bass
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the pass_nils_to plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the pass_nils_to plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'pass_nils_to'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'pass_nils_to'
@@ -0,0 +1,22 @@
1
+ module PassNils
2
+ def pass_nils_to(method_sym, object = self)
3
+ method = object.method(method_sym.to_s)
4
+
5
+ method.arity.times do |i|
6
+ nils = Array.new(method.arity) { nil }
7
+ nils[i] = "foo"
8
+ method.call(*nils)
9
+ end
10
+
11
+ if method.arity > 2
12
+ method.arity.times do |i|
13
+ nils = Array.new(method.arity) { nil }
14
+ (method.arity - 1).times { |j| nils[i-j] = "foo" }
15
+ method.call(*nils)
16
+ end
17
+ end
18
+
19
+ nils = Array.new(method.arity) { nil }
20
+ method.call(*nils) # Call with all nils
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "pass_nils_to"
3
+ s.version = "0.5"
4
+ s.date = "2008-08-15"
5
+ s.summary = "Pass nils to your methods and see if they explode."
6
+ s.email = "pelargir@gmail.com"
7
+ s.homepage = "http://github.com/pelargir/pass_nils_to"
8
+ s.description = "Pass nils to your methods and see if they explode."
9
+ s.has_rdoc = true
10
+ s.authors = ["Matthew Bass"]
11
+ s.files = [
12
+ "CHANGELOG",
13
+ "init.rb",
14
+ "lib/pass_nils_to.rb",
15
+ "MIT-LICENSE",
16
+ "pass_nils_to.gemspec",
17
+ "Rakefile",
18
+ "README",
19
+ "test/pass_nils_to_test.rb",
20
+ "test/test_helper.rb"
21
+ ]
22
+ s.rdoc_options = ["--main", "README"]
23
+ s.extra_rdoc_files = ["README"]
24
+ end
@@ -0,0 +1,83 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class MockObject
4
+ attr_accessor :spooge_args
5
+
6
+ def initialize
7
+ @spooge_args = []
8
+ end
9
+
10
+ def spooge
11
+ @spooge_args << true
12
+ end
13
+
14
+ def spooge_with_one_arg(arg)
15
+ @spooge_args << [arg]
16
+ end
17
+
18
+ def spooge_with_two_args(arg1, arg2)
19
+ @spooge_args << [arg1, arg2]
20
+ end
21
+
22
+ def spooge_with_three_args(arg1, arg2, arg3)
23
+ @spooge_args << [arg1, arg2, arg3]
24
+ end
25
+
26
+ def spooge_with_four_args(arg1, arg2, arg3, arg4)
27
+ @spooge_args << [arg1, arg2, arg3, arg4]
28
+ end
29
+ end
30
+
31
+
32
+ class TestHelperTest < Test::Unit::TestCase
33
+ include PassNils
34
+
35
+ def setup
36
+ @obj = MockObject.new
37
+ end
38
+
39
+ def test_pass_nils_to
40
+ pass_nils_to(:spooge, @obj)
41
+ assert [true], @obj.spooge_args
42
+ end
43
+
44
+ def test_pass_nils_to_with_one_arg
45
+ pass_nils_to(:spooge_with_one_arg, @obj)
46
+ assert_equal [["foo"], [nil]], @obj.spooge_args
47
+ end
48
+
49
+ def test_pass_nils_to_with_two_args
50
+ pass_nils_to(:spooge_with_two_args, @obj)
51
+ assert_equal [["foo", nil], [nil, "foo"], [nil, nil]], @obj.spooge_args
52
+ end
53
+
54
+ def test_pass_nils_to_with_three_args
55
+ pass_nils_to(:spooge_with_three_args, @obj)
56
+ expected = [
57
+ ["foo", nil, nil],
58
+ [nil, "foo", nil],
59
+ [nil, nil, "foo"],
60
+ ["foo", nil, "foo"],
61
+ ["foo", "foo", nil],
62
+ [nil, "foo", "foo"],
63
+ [nil, nil, nil]
64
+ ]
65
+ assert_equal expected, @obj.spooge_args
66
+ end
67
+
68
+ def test_pass_nils_to_with_four_args
69
+ pass_nils_to(:spooge_with_four_args, @obj)
70
+ expected = [
71
+ ["foo", nil, nil, nil],
72
+ [nil, "foo", nil, nil],
73
+ [nil, nil, "foo", nil],
74
+ [nil, nil, nil, "foo"],
75
+ ["foo", nil, "foo", "foo"],
76
+ ["foo", "foo", nil, "foo"],
77
+ ["foo", "foo", "foo", nil],
78
+ [nil, "foo", "foo", "foo"],
79
+ [nil, nil, nil, nil]
80
+ ]
81
+ assert_equal expected, @obj.spooge_args
82
+ end
83
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/pass_nils_to'
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pass_nils_to
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.5"
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Bass
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-15 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Pass nils to your methods and see if they explode.
17
+ email: pelargir@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - CHANGELOG
26
+ - init.rb
27
+ - lib/pass_nils_to.rb
28
+ - MIT-LICENSE
29
+ - pass_nils_to.gemspec
30
+ - Rakefile
31
+ - README
32
+ - test/pass_nils_to_test.rb
33
+ - test/test_helper.rb
34
+ has_rdoc: true
35
+ homepage: http://github.com/pelargir/pass_nils_to
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --main
41
+ - README
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.4
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Pass nils to your methods and see if they explode.
63
+ test_files: []
64
+