close_enough 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/close_enough.rb CHANGED
@@ -1,18 +1,10 @@
1
1
  require 'damerau-levenshtein'
2
+ require 'close_enough/extensions'
2
3
 
3
- class Object
4
- private
5
-
6
- def method_missing(name, *args)
7
- dl = DamerauLevenshtein
8
- ms = methods.map(&:to_s).freeze
4
+ module CloseEnough
9
5
 
10
- meth = ms.inject([]) do |matches, a|
11
- distance = dl.distance(name.to_s, a)
12
- matches << [distance, a] if distance < 3
13
- matches
14
- end.sort_by(&:first).first
6
+ end
15
7
 
16
- meth ? send(meth[1], *args) : super
17
- end
8
+ class Object
9
+ include CloseEnough::Extensions
18
10
  end
@@ -2,7 +2,17 @@ require "spec_helper.rb"
2
2
 
3
3
  module CloseEnoughSpec
4
4
 
5
- describe "it should call the closest method on Object" do
5
+ describe "nearest_method should find the nearest method to the typo" do
6
+ before(:each) do
7
+ @obj = Object.new
8
+ end
9
+
10
+ it "should return 'freeze' for 'frese'" do
11
+ @obj.send(:nearest_method, 'frese').should == "freeze"
12
+ end
13
+ end
14
+
15
+ describe "method_missing should call the closest method on Object" do
6
16
  before(:each) do
7
17
  @obj = Object.new
8
18
  end
@@ -40,4 +50,20 @@ module CloseEnoughSpec
40
50
  end
41
51
  end
42
52
 
53
+ describe "the called method should be able to take a block" do
54
+ it "should yield the results of applying the block" do
55
+ [1,2,3,4].correct do |a|
56
+ a += 1
57
+ end.should == [2,3,4,5]
58
+ end
59
+ end
60
+
61
+ describe "warnings should be issued when the correct method is guessed" do
62
+ it "should warn when guessing 'reverse' for 'reserve'" do
63
+ str = "avocado"
64
+ str.should_receive(:warn).with("[CloseEnough] reserve not found, using reverse instead")
65
+ str.reserve
66
+ end
67
+ end
68
+
43
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: close_enough
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -73,7 +73,7 @@ files:
73
73
  - lib/close_enough.rb
74
74
  - spec/close_enough_spec.rb
75
75
  - spec/spec_helper.rb
76
- homepage: https://github.com/ruby-jokes/close_enough
76
+ homepage: https://ruby-jokes.github.com/close_enough
77
77
  licenses:
78
78
  - GPLv3
79
79
  post_install_message: