stubble 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/lib/stubble.rb +6 -4
  3. data/test/stubble_test.rb +18 -0
  4. metadata +3 -3
data/Rakefile CHANGED
@@ -34,7 +34,7 @@ spec = Gem::Specification.new do |s|
34
34
 
35
35
  # Change these as appropriate
36
36
  s.name = "stubble"
37
- s.version = "0.1.1"
37
+ s.version = "0.1.2"
38
38
  s.summary = "(experimental) simple stubbing"
39
39
  s.author = "Matthew Rudy Jacobs"
40
40
  s.email = "MatthewRudyJacobs@gmail.com"
data/lib/stubble.rb CHANGED
@@ -87,16 +87,18 @@ module Stubble
87
87
 
88
88
  def track!(method_name)
89
89
  self._stubble.track!(method_name)
90
- unless methods.include?("#{method_name}_with_stubble")
90
+
91
+ unstubbled_method_name = "__unstubbled__#{method_name}"
92
+ unless methods.include?(unstubbled_method_name)
91
93
  class_eval <<-RUBY
92
- def #{method_name}_with_stubble(*args, &block)
94
+ alias #{unstubbled_method_name} #{method_name}
95
+ def #{method_name}(*args, &block)
93
96
  if stubbed_return = self._stubble.called!(#{method_name.inspect}, args, block)
94
97
  stubbed_return.perform
95
98
  else
96
- #{method_name}_without_stubble(*args, &block)
99
+ #{unstubbled_method_name}(*args, &block)
97
100
  end
98
101
  end
99
- alias_method_chain #{method_name.inspect}, :stubble
100
102
  RUBY
101
103
  end
102
104
  end
data/test/stubble_test.rb CHANGED
@@ -16,6 +16,10 @@ class StubbleTest < Test::Unit::TestCase
16
16
  @hits +=1
17
17
  end
18
18
 
19
+ def with_punctuation!
20
+ "punctuated"
21
+ end
22
+
19
23
  def some_method_with_arguments(times, shout="boom")
20
24
  shout * times
21
25
  end
@@ -108,6 +112,20 @@ class StubbleTest < Test::Unit::TestCase
108
112
  assert_equal 1, this._stubble[:some_method].length # no new
109
113
  end
110
114
 
115
+ test "we can stub! punctuated methods" do
116
+ this = StubThis.new
117
+ assert_equal "punctuated", this.with_punctuation!
118
+
119
+ Stubble.add_stubble!(this)
120
+ this.stub!(:with_punctuation!, [:a, :b, :c])
121
+
122
+ assert_equal :a, this.with_punctuation!
123
+ assert_equal :b, this.with_punctuation!
124
+ assert_equal :c, this.with_punctuation!
125
+
126
+ assert_equal "punctuated", this.with_punctuation!
127
+ end
128
+
111
129
  test "stub! - defines the next values to be returned" do
112
130
  this = StubThis.new
113
131
  assert_equal 1, this.some_method
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stubble
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew Rudy Jacobs