rrr 0.1.2 → 0.1.3

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/Rakefile CHANGED
@@ -6,7 +6,7 @@ AUTHOR = "maiha"
6
6
  EMAIL = "maiha@wota.jp"
7
7
  HOMEPAGE = "http://github.com/maiha/rrr"
8
8
  SUMMARY = "A ruby library for Ruby programming with RR that allows method overload"
9
- GEM_VERSION = "0.1.2"
9
+ GEM_VERSION = "0.1.3"
10
10
 
11
11
  spec = Gem::Specification.new do |s|
12
12
  s.rubyforge_project = 'asakusa'
data/lib/rrr.rb CHANGED
@@ -5,46 +5,14 @@ require 'blankslate'
5
5
 
6
6
  module RRR
7
7
  extend RR::Adapters::RRMethods
8
+ end
8
9
 
9
- class Proxy < BlankSlate
10
- def initialize(klass)
11
- @klass = klass
12
- end
13
- end
14
-
15
- class ClassProxy < Proxy
16
- private
17
- def method_missing(*args, &block)
18
- RRR.stub(@klass).__send__(*args, &block)
19
- end
20
- end
21
-
22
- class InstanceProxy < Proxy
23
- private
24
- def method_missing(*args, &block)
25
- RRR.mock.instance_of(@klass).__send__(*args, &block)
26
- end
27
- end
28
-
29
- def self.included(klass)
30
- klass.class_eval do
31
- include RR::Adapters::RRMethods
32
- klass.extend ClassMethods
33
- end
10
+ class << Object
11
+ def cm(&block)
12
+ RRR.stub(self).__send__(:instance_eval, &block)
34
13
  end
35
14
 
36
- module ClassMethods
37
- def cm(&block)
38
- ClassProxy.new(self).__send__(:instance_eval, &block)
39
- end
40
-
41
- def im(&block)
42
- InstanceProxy.new(self).__send__(:instance_eval, &block)
43
- end
15
+ def im(&block)
16
+ RRR.stub.instance_of(self).__send__(:instance_eval, &block)
44
17
  end
45
18
  end
46
-
47
- class Object
48
- include RRR
49
- end
50
-
@@ -2,8 +2,56 @@ require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "RRR" do
4
4
  describe "im" do
5
- it "TODO" do
6
- pending "This file should be filled with cm_spec"
5
+ before do
6
+ Object.send(:remove_const, 'Foo') rescue nil
7
+ class Foo
8
+ im {
9
+ bar {'bar'}
10
+
11
+ foo(1) {'foo1'}
12
+ foo('x') {'foox'}
13
+ }
14
+ end
15
+ end
16
+
17
+ context "when no arged method is defined" do
18
+ it "adds class methods" do
19
+ Foo.new.should respond_to(:bar)
20
+ end
21
+
22
+ it "allows empty args" do
23
+ Foo.new.bar.should == 'bar'
24
+ end
25
+
26
+ it "ignores args" do
27
+ Foo.new.bar(1).should == 'bar'
28
+ end
29
+ end
30
+
31
+ context "when only immediate integer or string is defined" do
32
+ it "adds class methods" do
33
+ Foo.new.should respond_to(:foo)
34
+ end
35
+
36
+ it "should raise an error against empty args" do
37
+ lambda {
38
+ Foo.new.foo
39
+ }.should raise_error(RR::Errors::DoubleNotFoundError)
40
+ end
41
+
42
+ it "allows method overload for immediate integer" do
43
+ Foo.new.foo(1).should == 'foo1'
44
+ end
45
+
46
+ it "allows method overload for immediate string" do
47
+ Foo.new.foo('x').should == 'foox'
48
+ end
49
+
50
+ it "raise an error against symbol" do
51
+ lambda {
52
+ Foo.new.foo(:x)
53
+ }.should raise_error(RR::Errors::DoubleNotFoundError)
54
+ end
7
55
  end
8
56
  end
9
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rrr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - maiha
@@ -46,7 +46,6 @@ files:
46
46
  - README
47
47
  - Rakefile
48
48
  - lib/rrr.rb
49
- - spec/call_method_spec.rb
50
49
  - spec/im_spec.rb
51
50
  - spec/cm_spec.rb
52
51
  - spec/spec_helper.rb
@@ -1,22 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "RRR" do
4
- before do
5
- Object.send(:remove_const, 'Foo') rescue nil
6
-
7
- class Foo
8
- cm {
9
- foo {'foo'}
10
-
11
- upcase {ancestors}
12
- downcase {foo}
13
- }
14
- end
15
- end
16
-
17
- describe "cm" do
18
- it "can call defined methods" do
19
- Foo.upcase.should == 'Foo'
20
- end
21
- end
22
- end