flexmock 0.8.7 → 0.8.8
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/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/lib/flexmock/rspec.rb +10 -6
- data/test/test_record_mode.rb +161 -161
- metadata +4 -4
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
data/lib/flexmock/rspec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#---
|
4
|
-
# Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@
|
4
|
+
# Copyright 2003, 2004, 2005, 2006, 2007, 2010 by Jim Weirich (jim.weirich@gmail.com).
|
5
5
|
# All rights reserved.
|
6
6
|
|
7
7
|
# Permission is granted for use, copying, modification, distribution,
|
@@ -12,10 +12,15 @@
|
|
12
12
|
require 'flexmock/base'
|
13
13
|
|
14
14
|
class FlexMock
|
15
|
-
|
15
|
+
if defined?(::RSpec)
|
16
|
+
SpecModule = RSpec
|
17
|
+
else
|
18
|
+
SpecModule = Spec
|
19
|
+
end
|
20
|
+
|
16
21
|
class RSpecFrameworkAdapter
|
17
22
|
def assert_block(msg, &block)
|
18
|
-
|
23
|
+
SpecModule::Expectations.fail_with(msg) unless yield
|
19
24
|
end
|
20
25
|
|
21
26
|
def assert_equal(a, b, msg=nil)
|
@@ -25,10 +30,9 @@ class FlexMock
|
|
25
30
|
|
26
31
|
class AssertionFailedError < StandardError; end
|
27
32
|
def assertion_failed_error
|
28
|
-
|
33
|
+
SpecModule::Expectations::ExpectationNotMetError
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
32
37
|
@framework_adapter = RSpecFrameworkAdapter.new
|
33
|
-
|
34
|
-
end
|
38
|
+
end
|
data/test/test_record_mode.rb
CHANGED
@@ -1,161 +1,161 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
#---
|
4
|
-
# Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org).
|
5
|
-
# All rights reserved.
|
6
|
-
|
7
|
-
# Permission is granted for use, copying, modification, distribution,
|
8
|
-
# and distribution of modified versions of this work as long as the
|
9
|
-
# above copyright notice is included.
|
10
|
-
#+++
|
11
|
-
|
12
|
-
require 'test/unit'
|
13
|
-
require 'flexmock'
|
14
|
-
require 'test/asserts'
|
15
|
-
|
16
|
-
class TestRecordMode < Test::Unit::TestCase
|
17
|
-
include FlexMock::TestCase
|
18
|
-
include FlexMock::FailureAssertion
|
19
|
-
|
20
|
-
def test_recording_mode_works
|
21
|
-
mock = flexmock("mock")
|
22
|
-
mock.should_expect do |recorder|
|
23
|
-
recorder.f { :answer }
|
24
|
-
end
|
25
|
-
assert_equal :answer, mock.f
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_arguments_are_passed_to_recording_mode_block
|
29
|
-
mock = flexmock("mock")
|
30
|
-
mock.should_expect do |recorder|
|
31
|
-
recorder.f(:arg) do |arg|
|
32
|
-
assert_equal :arg, arg
|
33
|
-
:answer
|
34
|
-
end
|
35
|
-
end
|
36
|
-
assert_equal :answer, mock.f(:arg)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_recording_mode_handles_multiple_returns
|
40
|
-
FlexMock.use("mock") do |mock|
|
41
|
-
mock.should_expect do |r|
|
42
|
-
answers = [1, 2]
|
43
|
-
# HACK: The following lambda is needed in Ruby 1.9 to cause
|
44
|
-
# the answers to be properly bound in the following block.
|
45
|
-
lambda { }
|
46
|
-
r.f { answers.shift }
|
47
|
-
end
|
48
|
-
assert_equal 1, mock.f
|
49
|
-
assert_equal 2, mock.f
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_recording_mode_does_not_specify_order
|
54
|
-
FlexMock.use("mock") do |mock|
|
55
|
-
mock.should_expect do |r|
|
56
|
-
r.f { 1 }
|
57
|
-
r.g { 2 }
|
58
|
-
end
|
59
|
-
assert_equal 2, mock.g
|
60
|
-
assert_equal 1, mock.f
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_recording_mode_gets_block_args_too
|
65
|
-
mock = flexmock("mock")
|
66
|
-
mock.should_expect do |r|
|
67
|
-
r.f(1, Proc) { |arg, block|
|
68
|
-
assert_not_nil block
|
69
|
-
block.call
|
70
|
-
}
|
71
|
-
end
|
72
|
-
|
73
|
-
assert_equal :block_result, mock.f(1) { :block_result }
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_recording_mode_should_validate_args_with_equals
|
77
|
-
assert_failure do
|
78
|
-
FlexMock.use("mock") do |mock|
|
79
|
-
mock.should_expect do |r|
|
80
|
-
r.f(1)
|
81
|
-
end
|
82
|
-
mock.f(2)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_recording_mode_should_allow_arg_contraint_validation
|
88
|
-
assert_failure do
|
89
|
-
FlexMock.use("mock") do |mock|
|
90
|
-
mock.should_expect do |r|
|
91
|
-
r.f(1)
|
92
|
-
end
|
93
|
-
mock.f(2)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_recording_mode_should_handle_multiplicity_contraints
|
99
|
-
assert_failure do
|
100
|
-
FlexMock.use("mock") do |mock|
|
101
|
-
mock.should_expect do |r|
|
102
|
-
r.f { :result }.once
|
103
|
-
end
|
104
|
-
mock.f
|
105
|
-
mock.f
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_strict_record_mode_requires_exact_argument_matches
|
111
|
-
assert_failure do
|
112
|
-
FlexMock.use("mock") do |mock|
|
113
|
-
mock.should_expect do |rec|
|
114
|
-
rec.should_be_strict
|
115
|
-
rec.f(Integer)
|
116
|
-
end
|
117
|
-
mock.f(3)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_strict_record_mode_requires_exact_ordering
|
123
|
-
assert_failure do
|
124
|
-
FlexMock.use("mock") do |mock|
|
125
|
-
mock.should_expect do |rec|
|
126
|
-
rec.should_be_strict
|
127
|
-
rec.f(1)
|
128
|
-
rec.f(2)
|
129
|
-
end
|
130
|
-
mock.f(2)
|
131
|
-
mock.f(1)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_strict_record_mode_requires_once
|
137
|
-
assert_failure do
|
138
|
-
FlexMock.use("mock") do |mock|
|
139
|
-
mock.should_expect do |rec|
|
140
|
-
rec.should_be_strict
|
141
|
-
rec.f(1)
|
142
|
-
end
|
143
|
-
mock.f(1)
|
144
|
-
mock.f(1)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_strict_record_mode_can_not_fail
|
150
|
-
FlexMock.use("mock") do |mock|
|
151
|
-
mock.should_expect do |rec|
|
152
|
-
rec.should_be_strict
|
153
|
-
rec.f(Integer)
|
154
|
-
rec.f(2)
|
155
|
-
end
|
156
|
-
mock.f(Integer)
|
157
|
-
mock.f(2)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#---
|
4
|
+
# Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org).
|
5
|
+
# All rights reserved.
|
6
|
+
|
7
|
+
# Permission is granted for use, copying, modification, distribution,
|
8
|
+
# and distribution of modified versions of this work as long as the
|
9
|
+
# above copyright notice is included.
|
10
|
+
#+++
|
11
|
+
|
12
|
+
require 'test/unit'
|
13
|
+
require 'flexmock'
|
14
|
+
require 'test/asserts'
|
15
|
+
|
16
|
+
class TestRecordMode < Test::Unit::TestCase
|
17
|
+
include FlexMock::TestCase
|
18
|
+
include FlexMock::FailureAssertion
|
19
|
+
|
20
|
+
def test_recording_mode_works
|
21
|
+
mock = flexmock("mock")
|
22
|
+
mock.should_expect do |recorder|
|
23
|
+
recorder.f { :answer }
|
24
|
+
end
|
25
|
+
assert_equal :answer, mock.f
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_arguments_are_passed_to_recording_mode_block
|
29
|
+
mock = flexmock("mock")
|
30
|
+
mock.should_expect do |recorder|
|
31
|
+
recorder.f(:arg) do |arg|
|
32
|
+
assert_equal :arg, arg
|
33
|
+
:answer
|
34
|
+
end
|
35
|
+
end
|
36
|
+
assert_equal :answer, mock.f(:arg)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_recording_mode_handles_multiple_returns
|
40
|
+
FlexMock.use("mock") do |mock|
|
41
|
+
mock.should_expect do |r|
|
42
|
+
answers = [1, 2]
|
43
|
+
# HACK: The following lambda is needed in Ruby 1.9 to cause
|
44
|
+
# the answers to be properly bound in the following block.
|
45
|
+
lambda { }
|
46
|
+
r.f { answers.shift }
|
47
|
+
end
|
48
|
+
assert_equal 1, mock.f
|
49
|
+
assert_equal 2, mock.f
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_recording_mode_does_not_specify_order
|
54
|
+
FlexMock.use("mock") do |mock|
|
55
|
+
mock.should_expect do |r|
|
56
|
+
r.f { 1 }
|
57
|
+
r.g { 2 }
|
58
|
+
end
|
59
|
+
assert_equal 2, mock.g
|
60
|
+
assert_equal 1, mock.f
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_recording_mode_gets_block_args_too
|
65
|
+
mock = flexmock("mock")
|
66
|
+
mock.should_expect do |r|
|
67
|
+
r.f(1, Proc) { |arg, block|
|
68
|
+
assert_not_nil block
|
69
|
+
block.call
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
assert_equal :block_result, mock.f(1) { :block_result }
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_recording_mode_should_validate_args_with_equals
|
77
|
+
assert_failure do
|
78
|
+
FlexMock.use("mock") do |mock|
|
79
|
+
mock.should_expect do |r|
|
80
|
+
r.f(1)
|
81
|
+
end
|
82
|
+
mock.f(2)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_recording_mode_should_allow_arg_contraint_validation
|
88
|
+
assert_failure do
|
89
|
+
FlexMock.use("mock") do |mock|
|
90
|
+
mock.should_expect do |r|
|
91
|
+
r.f(1)
|
92
|
+
end
|
93
|
+
mock.f(2)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_recording_mode_should_handle_multiplicity_contraints
|
99
|
+
assert_failure do
|
100
|
+
FlexMock.use("mock") do |mock|
|
101
|
+
mock.should_expect do |r|
|
102
|
+
r.f { :result }.once
|
103
|
+
end
|
104
|
+
mock.f
|
105
|
+
mock.f
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_strict_record_mode_requires_exact_argument_matches
|
111
|
+
assert_failure do
|
112
|
+
FlexMock.use("mock") do |mock|
|
113
|
+
mock.should_expect do |rec|
|
114
|
+
rec.should_be_strict
|
115
|
+
rec.f(Integer)
|
116
|
+
end
|
117
|
+
mock.f(3)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_strict_record_mode_requires_exact_ordering
|
123
|
+
assert_failure do
|
124
|
+
FlexMock.use("mock") do |mock|
|
125
|
+
mock.should_expect do |rec|
|
126
|
+
rec.should_be_strict
|
127
|
+
rec.f(1)
|
128
|
+
rec.f(2)
|
129
|
+
end
|
130
|
+
mock.f(2)
|
131
|
+
mock.f(1)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_strict_record_mode_requires_once
|
137
|
+
assert_failure do
|
138
|
+
FlexMock.use("mock") do |mock|
|
139
|
+
mock.should_expect do |rec|
|
140
|
+
rec.should_be_strict
|
141
|
+
rec.f(1)
|
142
|
+
end
|
143
|
+
mock.f(1)
|
144
|
+
mock.f(1)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_strict_record_mode_can_not_fail
|
150
|
+
FlexMock.use("mock") do |mock|
|
151
|
+
mock.should_expect do |rec|
|
152
|
+
rec.should_be_strict
|
153
|
+
rec.f(Integer)
|
154
|
+
rec.f(2)
|
155
|
+
end
|
156
|
+
mock.f(Integer)
|
157
|
+
mock.f(2)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 47
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 8
|
10
|
+
version: 0.8.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jim Weirich
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-13 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|