nkpart-accidentally 0.0.1
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.
- data/History.txt +6 -0
- data/Manifest.txt +27 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +65 -0
- data/Rakefile +28 -0
- data/TODO +12 -0
- data/accidentally.gemspec +41 -0
- data/etc/examples.rb +21 -0
- data/etc/textmate_command.rb +16 -0
- data/lib/accidentally/mad_hax.rb +24 -0
- data/lib/accidentally/method_invoker.rb +54 -0
- data/lib/accidentally/patches/kernel.rb +12 -0
- data/lib/accidentally/patches/thread.rb +11 -0
- data/lib/accidentally.rb +34 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/accidentally_spec.rb +85 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +16 -0
- data/tasks/rspec.rake +29 -0
- metadata +110 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
TODO
|
7
|
+
accidentally.gemspec
|
8
|
+
coverage/index.html
|
9
|
+
coverage/lib-accidentally-mad_hax_rb.html
|
10
|
+
coverage/lib-accidentally-method_invoker_rb.html
|
11
|
+
coverage/lib-accidentally-patches-kernel_rb.html
|
12
|
+
coverage/lib-accidentally-patches-thread_rb.html
|
13
|
+
coverage/lib-accidentally_rb.html
|
14
|
+
etc/examples.rb
|
15
|
+
etc/textmate_command.rb
|
16
|
+
lib/accidentally.rb
|
17
|
+
lib/accidentally/mad_hax.rb
|
18
|
+
lib/accidentally/method_invoker.rb
|
19
|
+
lib/accidentally/patches/kernel.rb
|
20
|
+
lib/accidentally/patches/thread.rb
|
21
|
+
script/console
|
22
|
+
script/destroy
|
23
|
+
script/generate
|
24
|
+
spec/accidentally_spec.rb
|
25
|
+
spec/spec.opts
|
26
|
+
spec/spec_helper.rb
|
27
|
+
tasks/rspec.rake
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
= Accidentally!
|
2
|
+
|
3
|
+
* http://github.com/nkpart/accidentally
|
4
|
+
|
5
|
+
== What
|
6
|
+
|
7
|
+
Accidentally helps you out when you know what, but you don't know how.
|
8
|
+
|
9
|
+
== How
|
10
|
+
|
11
|
+
$ sudo gem install nkpart-accidentally
|
12
|
+
$ irb
|
13
|
+
|
14
|
+
>> require 'accidentally'
|
15
|
+
>> 1.accidentally == '1'
|
16
|
+
=> ["to_s", "inspect"]
|
17
|
+
|
18
|
+
== Examples:
|
19
|
+
|
20
|
+
> [1,2,3].accidentally == 3
|
21
|
+
=> ["last", "pop", "length", "size", "nitems", "max"]
|
22
|
+
|
23
|
+
>> [1,nil,3,5].accidentally == [1,3,5]
|
24
|
+
=> ["select", "compact", "compact!", "find_all"]
|
25
|
+
|
26
|
+
>> [:a, :b, :c].accidentally(:b) == 1
|
27
|
+
=> ["index", "rindex"]
|
28
|
+
|
29
|
+
>> [:a, :b, :c, :d].accidentally(2,3) == [:c, :d]
|
30
|
+
=> ["slice", "indexes", "values_at", "indices", "slice!", "[]"]
|
31
|
+
|
32
|
+
>> "abc".accidentally(/\w/) == ["a","b","c"]
|
33
|
+
=> ["scan"]
|
34
|
+
|
35
|
+
>> [1,2,3,4,5].accidentally{|a,b| a + b} == 15
|
36
|
+
=> ["inject"]
|
37
|
+
|
38
|
+
== Requirements
|
39
|
+
|
40
|
+
*prohax - http://github.com/nkpart/prohax
|
41
|
+
|
42
|
+
== License
|
43
|
+
|
44
|
+
(The MIT License)
|
45
|
+
|
46
|
+
Copyright (c) 2008 nkpart
|
47
|
+
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
49
|
+
a copy of this software and associated documentation files (the
|
50
|
+
'Software'), to deal in the Software without restriction, including
|
51
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
52
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
53
|
+
permit persons to whom the Software is furnished to do so, subject to
|
54
|
+
the following conditions:
|
55
|
+
|
56
|
+
The above copyright notice and this permission notice shall be
|
57
|
+
included in all copies or substantial portions of the Software.
|
58
|
+
|
59
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
60
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
61
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
62
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
63
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
64
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
65
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/accidentally'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('accidentally', Accidentally::VERSION) do |p|
|
7
|
+
p.developer('nkpart', 'nkpart@gmail.com')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
|
+
p.rubyforge_name = p.name # TODO this is default value
|
11
|
+
p.extra_deps = [
|
12
|
+
['nkpart-prohax','>= 1.0.1']
|
13
|
+
]
|
14
|
+
p.extra_dev_deps = [
|
15
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
16
|
+
]
|
17
|
+
|
18
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
19
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
20
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
21
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'newgem/tasks'
|
25
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
26
|
+
|
27
|
+
task "build" => ["spec", "verify_rcov"]
|
28
|
+
task :default => [:build]
|
data/TODO
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
* Make it work with UtilityBelt - this will require knowing which methods are patched in. At the moment, it will run all sorts of nasty 'equipped' methods (pastie, vi, emacs, mate).
|
2
|
+
|
3
|
+
* Make it return the block used if a block is inferred. There's a failing spec in there for this.
|
4
|
+
|
5
|
+
* Find a method which expects parameters even when we haven't supplied the arguments.
|
6
|
+
* Would need to knock up our own arguments in the MethodInvoker...
|
7
|
+
|
8
|
+
* Expand the list of canned blocks from 1 to many
|
9
|
+
** always true, always false, alternating, etc.
|
10
|
+
|
11
|
+
* Allow the user to specify a proc as a target, this will be used in the equality check:
|
12
|
+
> [1].accidently == proc { |x| x =~ /"1"/ }
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{accidentally}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["nkpart"]
|
9
|
+
s.date = %q{2008-11-19}
|
10
|
+
s.description = %q{}
|
11
|
+
s.email = ["nkpart@gmail.com"]
|
12
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
|
13
|
+
s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "TODO", "accidentally.gemspec", "coverage/index.html", "coverage/lib-accidentally-mad_hax_rb.html", "coverage/lib-accidentally-method_invoker_rb.html", "coverage/lib-accidentally-patches-kernel_rb.html", "coverage/lib-accidentally-patches-thread_rb.html", "coverage/lib-accidentally_rb.html", "etc/examples.rb", "etc/textmate_command.rb", "lib/accidentally.rb", "lib/accidentally/mad_hax.rb", "lib/accidentally/method_invoker.rb", "lib/accidentally/patches/kernel.rb", "lib/accidentally/patches/thread.rb", "script/console", "script/destroy", "script/generate", "spec/accidentally_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/nkpart/accidentally}
|
16
|
+
s.post_install_message = %q{PostInstall.txt}
|
17
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubyforge_project = %q{accidentally}
|
20
|
+
s.rubygems_version = %q{1.3.1}
|
21
|
+
s.summary = %q{}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 2
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_runtime_dependency(%q<nkpart-prohax>, [">= 1.0.1"])
|
29
|
+
s.add_development_dependency(%q<newgem>, [">= 1.1.0"])
|
30
|
+
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<nkpart-prohax>, [">= 1.0.1"])
|
33
|
+
s.add_dependency(%q<newgem>, [">= 1.1.0"])
|
34
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
35
|
+
end
|
36
|
+
else
|
37
|
+
s.add_dependency(%q<nkpart-prohax>, [">= 1.0.1"])
|
38
|
+
s.add_dependency(%q<newgem>, [">= 1.1.0"])
|
39
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
40
|
+
end
|
41
|
+
end
|
data/etc/examples.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require '../lib/accidentally'
|
2
|
+
|
3
|
+
examples = <<EXAMPLES
|
4
|
+
[1,2,3].accidentally == 3
|
5
|
+
[1,nil,3,5].accidentally == [1,3,5]
|
6
|
+
[:a, :b, :c].accidentally(:b) == 1
|
7
|
+
[:a, :b, :c, :d].accidentally(2,3) == [:c, :d]
|
8
|
+
"abc".accidentally(/\\w/) == ["a","b","c"]
|
9
|
+
[1,2,3,4,5].accidentally{|a,b| a + b} == 15
|
10
|
+
EXAMPLES
|
11
|
+
|
12
|
+
examples.split("\n").each do |example|
|
13
|
+
next if example.empty?
|
14
|
+
puts "> #{example}\n => #{eval(example).inspect}"
|
15
|
+
puts ""
|
16
|
+
end
|
17
|
+
|
18
|
+
1.accidentally == '1'
|
19
|
+
|
20
|
+
[1,2,3].accidentally(2) == [1,2]
|
21
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
gem 'nkpart-accidentally'
|
5
|
+
require 'accidentally'
|
6
|
+
|
7
|
+
selection = ENV['TM_SELECTED_TEXT']
|
8
|
+
answers = eval(selection)
|
9
|
+
if !answers.empty?
|
10
|
+
puts "# #{selection}"
|
11
|
+
puts answers.map { |a|
|
12
|
+
selection.gsub(/accidentally/, a)
|
13
|
+
}.join("\n")
|
14
|
+
else
|
15
|
+
puts ENV['TM_SELECTED_TEXT'] + " # No match"
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'accidentally/method_invoker'
|
2
|
+
|
3
|
+
module Accidentally
|
4
|
+
module MadHax
|
5
|
+
|
6
|
+
@@blacklist = %w(daemonize display exec exit! fork sleep system syscall what? what ri accidentally accidently)
|
7
|
+
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def select_candidates methods
|
11
|
+
methods.select { |m| m !~ /(should)|(assert)|(methods)/ && !@@blacklist.include?(m)}
|
12
|
+
end
|
13
|
+
|
14
|
+
def find_how original, target, args = [], &blk
|
15
|
+
let(
|
16
|
+
:f => proc { |m| MethodInvoker.invoke(original, m, args, &blk) },
|
17
|
+
:candidates => proc { select_candidates(original.methods) }
|
18
|
+
).in {
|
19
|
+
candidates.select { |m| f(m) == target }
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'accidentally/patches/kernel'
|
2
|
+
require 'accidentally/patches/thread'
|
3
|
+
|
4
|
+
class InvocationResult < Strucked.build(:result, :block_used); end
|
5
|
+
|
6
|
+
module Accidentally
|
7
|
+
class MethodInvoker
|
8
|
+
def self.invoke v, meth, args, &blk
|
9
|
+
self.new(v).invoke(meth, args, &blk)
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize v
|
13
|
+
@v = v
|
14
|
+
end
|
15
|
+
|
16
|
+
def invoke meth, args, &blk
|
17
|
+
v, warns = yield_and_collect_stderr {
|
18
|
+
invocation_result, fail = either { do_send(meth, args, &blk) }
|
19
|
+
if should_do_block_execute(invocation_result, fail) then
|
20
|
+
either { invoke_and_infer_block(meth, args) }.compact.first
|
21
|
+
else
|
22
|
+
invocation_result
|
23
|
+
end
|
24
|
+
}
|
25
|
+
# TODO handle the warns
|
26
|
+
v
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def should_do_block_execute(invocation_result, fail)
|
32
|
+
let(
|
33
|
+
:is_a_187_block_result => proc { |x| defined?(Enumerable::Enumerator) && x.is_a?(Enumerable::Enumerator) },
|
34
|
+
:failed_because_no_block => proc { |fail| (fail && fail.is_a?(LocalJumpError)) }
|
35
|
+
).in {
|
36
|
+
failed_because_no_block(fail) || is_a_187_block_result(invocation_result)
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def do_send meth, args, &blk
|
41
|
+
# Executing with timeout in case of endless methods, like Array#cycle in 1.8.7
|
42
|
+
Thread.execute_with_timeout { dup(@v).send(meth, *args, &blk) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def dup value
|
46
|
+
(value.is_a? Fixnum) ? value : value.dup
|
47
|
+
end
|
48
|
+
|
49
|
+
def invoke_and_infer_block m, args
|
50
|
+
blk = proc { |x| x }
|
51
|
+
do_send(m, args, &blk)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/accidentally.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
gem 'nkpart-prohax'
|
5
|
+
require 'prohax'
|
6
|
+
require 'accidentally/mad_hax'
|
7
|
+
|
8
|
+
class Object
|
9
|
+
def accidentally *args, &block
|
10
|
+
Accidentally::Proxy.new(self).with(*args, &block)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Accidentally
|
15
|
+
VERSION = '0.0.1'
|
16
|
+
|
17
|
+
class Proxy
|
18
|
+
def initialize object
|
19
|
+
@object = object
|
20
|
+
@args = []
|
21
|
+
@block = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def == result
|
25
|
+
MadHax.find_how @object, result, @args, &@block
|
26
|
+
end
|
27
|
+
|
28
|
+
def with *args, &block
|
29
|
+
@args.concat args
|
30
|
+
@block = block
|
31
|
+
self
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/how_does.rb'}"
|
9
|
+
puts "Loading how_does gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
include Accidentally
|
4
|
+
|
5
|
+
describe Accidentally do
|
6
|
+
it "should figure out length of an array" do
|
7
|
+
methods = "dog".accidentally == 3
|
8
|
+
assert methods.include?("length")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should figure out array reversal" do
|
12
|
+
methods = [1, 2].accidentally == [2, 1]
|
13
|
+
assert methods.include?("reverse")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should figure out select" do
|
17
|
+
methods = [1, false, 2].accidentally == [1, 2]
|
18
|
+
assert methods.include?("select { |x| x }")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should figure out index" do
|
22
|
+
methods = [:a, :b, :c].accidentally == :a
|
23
|
+
assert methods.include?("first")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be able to be guided by a parameter" do
|
27
|
+
methods = [:a, :b, :c].accidentally(:b) == 1
|
28
|
+
assert methods.include?("index")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be able to be guided by more than one parameter" do
|
32
|
+
methods = [:a, :b, :c, :d, :e].accidentally(1, 2) == [:b, :c]
|
33
|
+
assert methods.include?("slice")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be able to take a block suggestion" do
|
37
|
+
m = [1, 2, 3].accidentally{ |a, b| a + b } == 6
|
38
|
+
assert m.include?("inject")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not fail for fixnums" do
|
42
|
+
m = 1.accidentally == "1"
|
43
|
+
assert m.include?("to_s")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe Accidentally::MethodInvoker do
|
48
|
+
it "should invoke a simple no args method" do
|
49
|
+
r = MethodInvoker.invoke [], :size, []
|
50
|
+
assert_equal 0, r
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should invoke a no args method that takes a block" do
|
54
|
+
r = MethodInvoker.invoke [1], :select, []
|
55
|
+
assert_equal [1], r
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "Kernel patches" do
|
60
|
+
it "should collect warns" do
|
61
|
+
a, warns = yield_and_collect_stderr {
|
62
|
+
warn "fail"
|
63
|
+
warn "2"
|
64
|
+
5
|
65
|
+
}
|
66
|
+
|
67
|
+
a.should == 5
|
68
|
+
warns.should == "fail\n2\n"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "Thread patches" do
|
73
|
+
it "should execute with a timeout" do
|
74
|
+
Thread.execute_with_timeout(0.1) do
|
75
|
+
5
|
76
|
+
end.should == 5
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should terminate early if longer than timeout" do
|
80
|
+
Thread.execute_with_timeout(0.1) do sleep(0.2); 1 end.should == nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
gem 'rspec'
|
6
|
+
require 'spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'test/unit/assertions'
|
10
|
+
|
11
|
+
include Test::Unit::Assertions
|
12
|
+
|
13
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
14
|
+
require 'accidentally'
|
15
|
+
require 'accidentally/method_invoker'
|
16
|
+
require 'accidentally/patches/kernel'
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
require 'spec/rake/verify_rcov'
|
10
|
+
rescue LoadError
|
11
|
+
puts <<-EOS
|
12
|
+
To use rspec for testing you must install rspec gem:
|
13
|
+
gem install rspec
|
14
|
+
EOS
|
15
|
+
exit(0)
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "coverage"
|
19
|
+
RCov::VerifyTask.new do |t|
|
20
|
+
t.threshold = 100
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Run the specs under spec/models"
|
24
|
+
Spec::Rake::SpecTask.new do |t|
|
25
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
26
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
t.rcov_opts = ['--exclude', 'spec,rcov.rb']
|
28
|
+
t.rcov = true
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nkpart-accidentally
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nkpart
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-19 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nkpart-prohax
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.1
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: newgem
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 1.1.0
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: hoe
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.0
|
41
|
+
version:
|
42
|
+
description: ""
|
43
|
+
email:
|
44
|
+
- nkpart@gmail.com
|
45
|
+
executables: []
|
46
|
+
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
extra_rdoc_files:
|
50
|
+
- History.txt
|
51
|
+
- Manifest.txt
|
52
|
+
- PostInstall.txt
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- History.txt
|
56
|
+
- Manifest.txt
|
57
|
+
- PostInstall.txt
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- TODO
|
61
|
+
- accidentally.gemspec
|
62
|
+
- coverage/index.html
|
63
|
+
- coverage/lib-accidentally-mad_hax_rb.html
|
64
|
+
- coverage/lib-accidentally-method_invoker_rb.html
|
65
|
+
- coverage/lib-accidentally-patches-kernel_rb.html
|
66
|
+
- coverage/lib-accidentally-patches-thread_rb.html
|
67
|
+
- coverage/lib-accidentally_rb.html
|
68
|
+
- etc/examples.rb
|
69
|
+
- etc/textmate_command.rb
|
70
|
+
- lib/accidentally.rb
|
71
|
+
- lib/accidentally/mad_hax.rb
|
72
|
+
- lib/accidentally/method_invoker.rb
|
73
|
+
- lib/accidentally/patches/kernel.rb
|
74
|
+
- lib/accidentally/patches/thread.rb
|
75
|
+
- script/console
|
76
|
+
- script/destroy
|
77
|
+
- script/generate
|
78
|
+
- spec/accidentally_spec.rb
|
79
|
+
- spec/spec.opts
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- tasks/rspec.rake
|
82
|
+
has_rdoc: true
|
83
|
+
homepage: http://github.com/nkpart/accidentally
|
84
|
+
post_install_message: PostInstall.txt
|
85
|
+
rdoc_options:
|
86
|
+
- --main
|
87
|
+
- README.rdoc
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: "0"
|
95
|
+
version:
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
version:
|
102
|
+
requirements: []
|
103
|
+
|
104
|
+
rubyforge_project: accidentally
|
105
|
+
rubygems_version: 1.2.0
|
106
|
+
signing_key:
|
107
|
+
specification_version: 2
|
108
|
+
summary: ""
|
109
|
+
test_files: []
|
110
|
+
|