flexmock 0.4.3 → 0.4.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README +1 -1
- data/Rakefile +1 -1
- data/lib/flexmock.rb +20 -11
- data/test/test_stubbing.rb +8 -0
- metadata +3 -3
data/CHANGELOG
CHANGED
data/README
CHANGED
data/Rakefile
CHANGED
data/lib/flexmock.rb
CHANGED
@@ -780,7 +780,7 @@ class FlexMock
|
|
780
780
|
# (assuming the the flexmock teardown isn't overridden).
|
781
781
|
#
|
782
782
|
# If a block is given, then the mock object is passed to the block and
|
783
|
-
# may be configured
|
783
|
+
# may be configured within the block.
|
784
784
|
def flexmock(name="unknown")
|
785
785
|
mock = FlexMock.new(name)
|
786
786
|
yield(mock) if block_given?
|
@@ -788,25 +788,31 @@ class FlexMock
|
|
788
788
|
mock
|
789
789
|
end
|
790
790
|
|
791
|
-
# Stub the given object by overriding the behavior of individual
|
792
|
-
# The stub object returned will respond to the
|
793
|
-
# method, just like normal stubs.
|
794
|
-
#
|
791
|
+
# Stub the given object by overriding the behavior of individual
|
792
|
+
# methods. The stub object returned will respond to the
|
793
|
+
# +should_receive+ method, just like normal stubs.
|
794
|
+
#
|
795
|
+
# If a block is given, then the stub object is passed to the block
|
796
|
+
# and may be configured within the block.
|
795
797
|
#
|
796
798
|
# Example: Stub out DBI to return a fake db connection.
|
797
799
|
#
|
798
|
-
# flexstub(DBI)
|
799
|
-
#
|
800
|
-
#
|
801
|
-
#
|
802
|
-
#
|
800
|
+
# flexstub(DBI) do |s|
|
801
|
+
# s.should_receive(:connect).and_return {
|
802
|
+
# flexmock("db connection") do |m|
|
803
|
+
# m.should_receive(:select_all).and_return(...)
|
804
|
+
# end
|
805
|
+
# }
|
806
|
+
# end
|
803
807
|
#
|
804
808
|
def flexstub(obj, name=nil)
|
805
809
|
name ||= "flexstub(#{obj.class.to_s})"
|
806
810
|
obj.instance_eval {
|
807
811
|
@flexmock_proxy ||= StubProxy.new(obj, FlexMock.new(name))
|
808
812
|
}
|
809
|
-
|
813
|
+
proxy = obj.instance_variable_get("@flexmock_proxy")
|
814
|
+
yield(proxy) if block_given?
|
815
|
+
flexmock_remember(proxy)
|
810
816
|
end
|
811
817
|
|
812
818
|
# Intercept the named class in the target class for the duration
|
@@ -818,6 +824,9 @@ class FlexMock
|
|
818
824
|
# will be left behind that will forward all calls to the original
|
819
825
|
# class.
|
820
826
|
#
|
827
|
+
# <b>Warning:</b> <em>Class Interception is deprecated. Use
|
828
|
+
# flexstub instead.</em>
|
829
|
+
#
|
821
830
|
# Usage:
|
822
831
|
# intercept(SomeClass).in(ClassBeingTested).with(MockClass)
|
823
832
|
# intercept(SomeClass).with(MockClass).in(ClassBeingTested)
|
data/test/test_stubbing.rb
CHANGED
@@ -30,6 +30,14 @@ class TestStubbing < Test::Unit::TestCase
|
|
30
30
|
assert_equal :stub_hi, obj.hi
|
31
31
|
end
|
32
32
|
|
33
|
+
def test_stub_command_can_configure_via_block
|
34
|
+
obj = Object.new
|
35
|
+
flexstub(obj) do |m|
|
36
|
+
m.should_receive(:hi).once.and_return(:stub_hi)
|
37
|
+
end
|
38
|
+
assert_equal :stub_hi, obj.hi
|
39
|
+
end
|
40
|
+
|
33
41
|
def test_stubbed_methods_can_take_blocks
|
34
42
|
obj = Object.new
|
35
43
|
flexstub(obj).should_receive(:with_block).once.with(Proc).
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0.
|
2
|
+
rubygems_version: 0.9.0.10
|
3
3
|
specification_version: 1
|
4
4
|
name: flexmock
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.3
|
7
|
-
date:
|
6
|
+
version: 0.4.3.1
|
7
|
+
date: 2007-01-26 00:00:00 -05:00
|
8
8
|
summary: Simple and Flexible Mock Objects for Testing
|
9
9
|
require_paths:
|
10
10
|
- lib
|