mocha 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/RELEASE +8 -0
- data/Rakefile +1 -1
- data/lib/mocha/mock.rb +0 -2
- data/lib/mocha/parameter_matchers/instance_of.rb +39 -0
- data/lib/mocha/parameter_matchers/kind_of.rb +39 -0
- data/test/unit/parameter_matchers/instance_of_test.rb +25 -0
- data/test/unit/parameter_matchers/kind_of_test.rb +25 -0
- metadata +6 -2
data/RELEASE
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
= 0.5.3 (r165)
|
2
|
+
|
3
|
+
- Attempt to fix packaging problems by switching to newer version (1.15.1) of gnutar and setting COPY_EXTENDED_ATTRIBUTES_DISABLE environment variable.
|
4
|
+
- Removed unused ExpectationSequenceError exception.
|
5
|
+
- Added instance_of and kind_of parameter matchers.
|
6
|
+
- Added Google Webmaster meta tag to rdoc template header.
|
7
|
+
- Put Google Webmaster meta tag in the right header i.e. the one for the index page.
|
8
|
+
|
1
9
|
= 0.5.2 (r159)
|
2
10
|
|
3
11
|
- Fix bug 11885 - "never doesn't work with stub_everything" submitted by Alexander Lang. In fixing this bug, also fixed undiscoverd bug where expected & actual invocation counts were being incorrectly reported which seems to have been introduced when fixes were added for invocation dispatch (see MockedMethodDispatchAcceptanceTest).
|
data/Rakefile
CHANGED
data/lib/mocha/mock.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Mocha
|
2
|
+
|
3
|
+
module ParameterMatchers
|
4
|
+
|
5
|
+
# :call-seq: instance_of(klass) -> parameter_matcher
|
6
|
+
#
|
7
|
+
# Matches any object that is an instance of +klass+
|
8
|
+
# object = mock()
|
9
|
+
# object.expects(:method_1).with(instance_of(String))
|
10
|
+
# object.method_1('string')
|
11
|
+
# # no error raised
|
12
|
+
#
|
13
|
+
# object = mock()
|
14
|
+
# object.expects(:method_1).with(instance_of(String))
|
15
|
+
# object.method_1(99)
|
16
|
+
# # error raised, because method_1 was not called with an instance of String
|
17
|
+
def instance_of(klass)
|
18
|
+
InstanceOf.new(klass)
|
19
|
+
end
|
20
|
+
|
21
|
+
class InstanceOf # :nodoc:
|
22
|
+
|
23
|
+
def initialize(klass)
|
24
|
+
@klass = klass
|
25
|
+
end
|
26
|
+
|
27
|
+
def ==(parameter)
|
28
|
+
parameter.instance_of?(@klass)
|
29
|
+
end
|
30
|
+
|
31
|
+
def mocha_inspect
|
32
|
+
"instance_of(#{@klass.mocha_inspect})"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Mocha
|
2
|
+
|
3
|
+
module ParameterMatchers
|
4
|
+
|
5
|
+
# :call-seq: kind_of(klass) -> parameter_matcher
|
6
|
+
#
|
7
|
+
# Matches any object that is a kind of +klass+
|
8
|
+
# object = mock()
|
9
|
+
# object.expects(:method_1).with(kind_of(Integer))
|
10
|
+
# object.method_1(99)
|
11
|
+
# # no error raised
|
12
|
+
#
|
13
|
+
# object = mock()
|
14
|
+
# object.expects(:method_1).with(kind_of(Integer))
|
15
|
+
# object.method_1('string')
|
16
|
+
# # error raised, because method_1 was not called with a kind of Integer
|
17
|
+
def kind_of(klass)
|
18
|
+
KindOf.new(klass)
|
19
|
+
end
|
20
|
+
|
21
|
+
class KindOf # :nodoc:
|
22
|
+
|
23
|
+
def initialize(klass)
|
24
|
+
@klass = klass
|
25
|
+
end
|
26
|
+
|
27
|
+
def ==(parameter)
|
28
|
+
parameter.kind_of?(@klass)
|
29
|
+
end
|
30
|
+
|
31
|
+
def mocha_inspect
|
32
|
+
"kind_of(#{@klass.mocha_inspect})"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
|
+
|
3
|
+
require 'mocha/parameter_matchers/instance_of'
|
4
|
+
require 'mocha/inspect'
|
5
|
+
|
6
|
+
class InstanceOfTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include Mocha::ParameterMatchers
|
9
|
+
|
10
|
+
def test_should_match_object_that_is_an_instance_of_specified_class
|
11
|
+
matcher = instance_of(String)
|
12
|
+
assert matcher == 'string'
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_not_match_object_that_is_not_an_instance_of_specified_class
|
16
|
+
matcher = instance_of(String)
|
17
|
+
assert matcher != 99
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_describe_matcher
|
21
|
+
matcher = instance_of(String)
|
22
|
+
assert_equal "instance_of(String)", matcher.mocha_inspect
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
|
+
|
3
|
+
require 'mocha/parameter_matchers/kind_of'
|
4
|
+
require 'mocha/inspect'
|
5
|
+
|
6
|
+
class InstanceOfTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include Mocha::ParameterMatchers
|
9
|
+
|
10
|
+
def test_should_match_object_that_is_a_kind_of_specified_class
|
11
|
+
matcher = kind_of(Integer)
|
12
|
+
assert matcher == 99
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_not_match_object_that_is_not_a_kind_of_specified_class
|
16
|
+
matcher = kind_of(Integer)
|
17
|
+
assert matcher != 'string'
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_describe_matcher
|
21
|
+
matcher = kind_of(Integer)
|
22
|
+
assert_equal "kind_of(Integer)", matcher.mocha_inspect
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: mocha
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date: 2007-07-
|
6
|
+
version: 0.5.3
|
7
|
+
date: 2007-07-28 00:00:00 +01:00
|
8
8
|
summary: Mocking and stubbing library
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -55,6 +55,8 @@ files:
|
|
55
55
|
- lib/mocha/parameter_matchers/has_key.rb
|
56
56
|
- lib/mocha/parameter_matchers/has_value.rb
|
57
57
|
- lib/mocha/parameter_matchers/includes.rb
|
58
|
+
- lib/mocha/parameter_matchers/instance_of.rb
|
59
|
+
- lib/mocha/parameter_matchers/kind_of.rb
|
58
60
|
- lib/mocha/parameter_matchers.rb
|
59
61
|
- lib/mocha/pretty_parameters.rb
|
60
62
|
- lib/mocha/return_values.rb
|
@@ -108,6 +110,8 @@ files:
|
|
108
110
|
- test/unit/parameter_matchers/has_key_test.rb
|
109
111
|
- test/unit/parameter_matchers/has_value_test.rb
|
110
112
|
- test/unit/parameter_matchers/includes_test.rb
|
113
|
+
- test/unit/parameter_matchers/instance_of_test.rb
|
114
|
+
- test/unit/parameter_matchers/kind_of_test.rb
|
111
115
|
- test/unit/parameter_matchers/stub_matcher.rb
|
112
116
|
- test/unit/pretty_parameters_test.rb
|
113
117
|
- test/unit/return_values_test.rb
|