rd_stump 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +23 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +118 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/lib/stump.rb +11 -0
- data/lib/stump/core_ext/test_case.rb +21 -0
- data/lib/stump/metaid.rb +17 -0
- data/lib/stump/mock.rb +51 -0
- data/lib/stump/mocks.rb +23 -0
- data/lib/stump/proxy.rb +115 -0
- data/lib/stump/stub.rb +34 -0
- data/lib/stump/version.rb +9 -0
- data/setup.rb +1585 -0
- data/stump.gemspec +44 -0
- data/test/test_helper.rb +16 -0
- data/test/test_mock.rb +111 -0
- data/test/test_proxy.rb +123 -0
- data/test/test_stub.rb +85 -0
- metadata +85 -0
data/stump.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "rd_stump"
|
3
|
+
s.version = "0.0.2"
|
4
|
+
s.date = "2008-10-30"
|
5
|
+
s.summary = "Stubbing and mocking that isn't painful."
|
6
|
+
s.email = "jeremy@entp.com"
|
7
|
+
s.homepage = "http://github.com/jm/stump"
|
8
|
+
s.description = "Stubbing and mocking that isn't painful, fanciful, and doesn't inspire any sort of contempt or bitterness."
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.authors = ["Jeremy McAnally"]
|
11
|
+
s.files = [
|
12
|
+
"History.txt",
|
13
|
+
"Manifest.txt",
|
14
|
+
"README.rdoc",
|
15
|
+
"Rakefile",
|
16
|
+
"stump.gemspec",
|
17
|
+
"History.txt",
|
18
|
+
"License.txt",
|
19
|
+
"Manifest.txt",
|
20
|
+
"PostInstall.txt",
|
21
|
+
"Rakefile",
|
22
|
+
"config/hoe.rb",
|
23
|
+
"config/requirements.rb",
|
24
|
+
"lib/stump.rb",
|
25
|
+
"lib/stump/metaid.rb",
|
26
|
+
"lib/stump/mock.rb",
|
27
|
+
"lib/stump/mocks.rb",
|
28
|
+
"lib/stump/stub.rb",
|
29
|
+
"lib/stump/proxy.rb",
|
30
|
+
"lib/stump/version.rb",
|
31
|
+
"lib/stump/core_ext/test_case.rb",
|
32
|
+
"setup.rb"
|
33
|
+
]
|
34
|
+
|
35
|
+
s.test_files = [
|
36
|
+
"test/test_stub.rb",
|
37
|
+
"test/test_mock.rb",
|
38
|
+
"test/test_proxy.rb",
|
39
|
+
"test/test_helper.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
43
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
44
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/test_mock.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestMock < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_mock_is_set
|
8
|
+
mock_me = MyStump.new
|
9
|
+
|
10
|
+
assert_nothing_raised do
|
11
|
+
mock_me.mock!(:pants)
|
12
|
+
mock_me.pants
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_mock_value_is_returned
|
17
|
+
mock_me = MyStump.new
|
18
|
+
|
19
|
+
assert_nothing_raised do
|
20
|
+
mock_me.mock!(:pants, :return => "slacks")
|
21
|
+
assert_equal "slacks", mock_me.pants
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_mock_is_added_to_tracker
|
26
|
+
mock_me = MyStump.new
|
27
|
+
mock_me.mock!(:biscuits, "tea")
|
28
|
+
|
29
|
+
assert_equal [[mock_me, :biscuits]], Stump::Mocks.failures
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_mock_object_is_created
|
33
|
+
assert_nothing_raised do
|
34
|
+
mocked = mock(:hello)
|
35
|
+
mocked.hello
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_mock_object_can_add_mock_methods
|
40
|
+
assert_nothing_raised do
|
41
|
+
mocked = mock(:hello)
|
42
|
+
|
43
|
+
mocked.mock!(:more, :return => "meep")
|
44
|
+
assert_equal "meep", mocked.more
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_mock_is_created_with_block
|
49
|
+
assert_nothing_raised do
|
50
|
+
my_mock = MyStump.new
|
51
|
+
my_mock.mock!(:lose) do
|
52
|
+
"FAIL"
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_equal "FAIL", my_mock.lose
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_mock_is_created_without_argument
|
60
|
+
assert_nothing_raised do
|
61
|
+
mockery = MyStump.new
|
62
|
+
mockery.mock!(:blank)
|
63
|
+
mockery.blank
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_mock_with_block_takes_args
|
68
|
+
assert_nothing_raised do
|
69
|
+
mockery = MyStump.new
|
70
|
+
mockery.mock!(:spaz) do |arg1, arg2|
|
71
|
+
arg1 + arg2
|
72
|
+
end
|
73
|
+
|
74
|
+
assert_equal 3, mockery.spaz(1,2)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_mock_with_block_requires_args
|
79
|
+
assert_raise ArgumentError do
|
80
|
+
mockery = MyStump.new
|
81
|
+
mockery.mock!(:spaz) do |arg1, arg2|
|
82
|
+
arg1 + arg2
|
83
|
+
end
|
84
|
+
|
85
|
+
assert_equal 3, mockery.spaz
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_mock_fail
|
90
|
+
stumply = MyStump.new
|
91
|
+
stumply.mock!(:hello, "hi")
|
92
|
+
|
93
|
+
assert_raise Test::Unit::AssertionFailedError do
|
94
|
+
stumpdown!
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_mock_pass
|
99
|
+
stumply = MyStump.new
|
100
|
+
stumply.mock!(:hello, "hi")
|
101
|
+
stumply.hello
|
102
|
+
|
103
|
+
assert_nothing_raised do
|
104
|
+
stumpdown!
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def teardown
|
109
|
+
Stump::Mocks.clear!
|
110
|
+
end
|
111
|
+
end
|
data/test/test_proxy.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class ProxyPants
|
4
|
+
def method_missing(method_name, arguments)
|
5
|
+
if method_name.to_s =~ /fun_/
|
6
|
+
return "whoo #{method_name} party!!"
|
7
|
+
else
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class TestProxy < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_proxy_is_set
|
18
|
+
proxy_me = MyStump.new
|
19
|
+
|
20
|
+
assert_nothing_raised do
|
21
|
+
proxy_me.proxy!(:tree)
|
22
|
+
proxy_me.tree
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_proxy_value_is_returned
|
27
|
+
proxy_me = MyStump.new
|
28
|
+
|
29
|
+
assert_nothing_raised do
|
30
|
+
proxy_me.proxy!(:tree, :return => "slacks")
|
31
|
+
assert_equal "slacks", proxy_me.tree
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_proxy_is_added_to_tracker
|
36
|
+
proxy_me = MyStump.new
|
37
|
+
proxy_me.proxy!(:tree, :return => "tea")
|
38
|
+
|
39
|
+
assert_equal [[proxy_me, :tree]], Stump::Mocks.failures
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_proxy_args_are_required
|
43
|
+
proxied = MyStump.new
|
44
|
+
proxied.proxy!(:trunk)
|
45
|
+
|
46
|
+
assert_raise ArgumentError do
|
47
|
+
proxied.trunk
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_nothing_raised do
|
51
|
+
assert_equal "HELLO", proxied.trunk("hello")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_proxy_optional_args_are_not_required
|
56
|
+
proxied = MyStump.new
|
57
|
+
proxied.proxy!(:branch)
|
58
|
+
|
59
|
+
assert_raise ArgumentError do
|
60
|
+
proxied.branch
|
61
|
+
end
|
62
|
+
|
63
|
+
assert_nothing_raised do
|
64
|
+
assert_equal 3, proxied.branch(3)
|
65
|
+
assert_equal 6, proxied.branch(3, 2)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_proxy_fail
|
70
|
+
stumply = MyStump.new
|
71
|
+
stumply.proxy!(:tree, :return => "hi")
|
72
|
+
|
73
|
+
assert_raise Test::Unit::AssertionFailedError do
|
74
|
+
stumpdown!
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_proxy_pass
|
79
|
+
stumply = MyStump.new
|
80
|
+
stumply.proxy!(:tree, :return => "hi")
|
81
|
+
stumply.tree
|
82
|
+
|
83
|
+
assert_nothing_raised do
|
84
|
+
stumpdown!
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_proxy_method_missing
|
89
|
+
obj = ProxyPants.new
|
90
|
+
|
91
|
+
obj.proxy!(:fun_pants)
|
92
|
+
assert_equal "whoo fun_pants party!!", obj.fun_pants
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_proxy_method_missing_with_return
|
96
|
+
obj = ProxyPants.new
|
97
|
+
|
98
|
+
obj.proxy!(:fun_party, :return => "party time in the city!!")
|
99
|
+
assert_equal "party time in the city!!", obj.fun_party
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_proxy_method_missing_fails_with_no_method_match
|
103
|
+
obj = ProxyPants.new
|
104
|
+
|
105
|
+
assert_raises NoMethodError do
|
106
|
+
obj.proxy!(:fail_pants)
|
107
|
+
obj.fail_pants
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_proxy_method_missing_fail
|
112
|
+
stumply = ProxyPants.new
|
113
|
+
stumply.proxy!(:fun_tree, :return => "hello")
|
114
|
+
|
115
|
+
assert_raise Test::Unit::AssertionFailedError do
|
116
|
+
stumpdown!
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def teardown
|
121
|
+
Stump::Mocks.clear!
|
122
|
+
end
|
123
|
+
end
|
data/test/test_stub.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestStub < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_stub_is_set
|
8
|
+
stub_me = MyStump.new
|
9
|
+
|
10
|
+
assert_nothing_raised do
|
11
|
+
stub_me.stub!(:pants)
|
12
|
+
stub_me.pants
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_stub_value_is_returned
|
17
|
+
stub_me = MyStump.new
|
18
|
+
|
19
|
+
assert_nothing_raised do
|
20
|
+
stub_me.stub!(:pants, :return => "slacks")
|
21
|
+
assert_equal "slacks", stub_me.pants
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_stub_object_is_created
|
26
|
+
assert_nothing_raised do
|
27
|
+
stubbed = stub(:hello)
|
28
|
+
stubbed.hello
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_stub_object_can_add_stub_methods
|
33
|
+
assert_nothing_raised do
|
34
|
+
stubbed = stub(:hello)
|
35
|
+
|
36
|
+
stubbed.stub!(:more, :return => "meep")
|
37
|
+
assert_equal "meep", stubbed.more
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_stub_is_created_with_block
|
42
|
+
assert_nothing_raised do
|
43
|
+
my_stub = MyStump.new
|
44
|
+
my_stub.stub!(:lose) do
|
45
|
+
"FAIL"
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_equal "FAIL", my_stub.lose
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_stub_is_created_without_argument
|
53
|
+
assert_nothing_raised do
|
54
|
+
stubble = MyStump.new
|
55
|
+
stubble.stub!(:blank)
|
56
|
+
stubble.blank
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_stub_with_block_takes_args
|
61
|
+
assert_nothing_raised do
|
62
|
+
stubble = MyStump.new
|
63
|
+
stubble.stub!(:spaz) do |arg1, arg2|
|
64
|
+
arg1 + arg2
|
65
|
+
end
|
66
|
+
|
67
|
+
assert_equal 3, stubble.spaz(1,2)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_stub_with_block_requires_args
|
72
|
+
assert_raise ArgumentError do
|
73
|
+
stubble = MyStump.new
|
74
|
+
stubble.stub!(:spaz) do |arg1, arg2|
|
75
|
+
arg1 + arg2
|
76
|
+
end
|
77
|
+
|
78
|
+
assert_equal 3, stubble.spaz
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def teardown
|
83
|
+
Stump::Mocks.clear!
|
84
|
+
end
|
85
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rd_stump
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jeremy McAnally
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2008-10-30 00:00:00 +03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Stubbing and mocking that isn't painful, fanciful, and doesn't inspire any sort of contempt or bitterness.
|
22
|
+
email: jeremy@entp.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- History.txt
|
29
|
+
- Manifest.txt
|
30
|
+
- README.rdoc
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.rdoc
|
35
|
+
- Rakefile
|
36
|
+
- stump.gemspec
|
37
|
+
- License.txt
|
38
|
+
- PostInstall.txt
|
39
|
+
- config/hoe.rb
|
40
|
+
- config/requirements.rb
|
41
|
+
- lib/stump.rb
|
42
|
+
- lib/stump/metaid.rb
|
43
|
+
- lib/stump/mock.rb
|
44
|
+
- lib/stump/mocks.rb
|
45
|
+
- lib/stump/stub.rb
|
46
|
+
- lib/stump/proxy.rb
|
47
|
+
- lib/stump/version.rb
|
48
|
+
- lib/stump/core_ext/test_case.rb
|
49
|
+
- setup.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/jm/stump
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --main
|
57
|
+
- README.rdoc
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.6
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Stubbing and mocking that isn't painful.
|
81
|
+
test_files:
|
82
|
+
- test/test_stub.rb
|
83
|
+
- test/test_mock.rb
|
84
|
+
- test/test_proxy.rb
|
85
|
+
- test/test_helper.rb
|