flexmock 0.8.11 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/Rakefile +23 -65
- data/TAGS +689 -691
- data/doc/releases/flexmock-0.9.0.rdoc +89 -0
- data/lib/flexmock.rb +1 -1
- data/lib/flexmock/argument_matchers.rb +5 -5
- data/lib/flexmock/argument_types.rb +1 -1
- data/lib/flexmock/base.rb +1 -1
- data/lib/flexmock/core.rb +5 -5
- data/lib/flexmock/core_class_methods.rb +6 -6
- data/lib/flexmock/default_framework_adapter.rb +2 -2
- data/lib/flexmock/deprecated_methods.rb +1 -1
- data/lib/flexmock/errors.rb +1 -1
- data/lib/flexmock/expectation.rb +12 -12
- data/lib/flexmock/expectation_director.rb +1 -1
- data/lib/flexmock/mock_container.rb +12 -2
- data/lib/flexmock/noop.rb +2 -2
- data/lib/flexmock/ordering.rb +1 -1
- data/lib/flexmock/partial_mock.rb +10 -3
- data/lib/flexmock/rails.rb +1 -1
- data/lib/flexmock/recorder.rb +1 -1
- data/lib/flexmock/rspec.rb +1 -1
- data/lib/flexmock/test_unit.rb +2 -2
- data/lib/flexmock/test_unit_integration.rb +5 -5
- data/lib/flexmock/undefined.rb +8 -4
- data/lib/flexmock/validators.rb +2 -2
- data/lib/flexmock/version.rb +11 -0
- data/test/{test_aliasing.rb → aliasing_test.rb} +7 -8
- data/test/{test_container_methods.rb → container_methods_test.rb} +21 -22
- data/test/{test_default_framework_adapter.rb → default_framework_adapter_test.rb} +8 -9
- data/test/{test_demeter_mocking.rb → demeter_mocking_test.rb} +1 -4
- data/test/{test_deprecated_methods.rb → deprecated_methods_test.rb} +11 -13
- data/test/{test_examples_from_readme.rb → examples_from_readme_test.rb} +5 -6
- data/test/{test_extended_should_receive.rb → extended_should_receive_test.rb} +11 -12
- data/test/{test_flexmodel.rb → flexmodel_test.rb} +1 -2
- data/test/{test_naming.rb → naming_test.rb} +5 -6
- data/test/{test_new_instances.rb → new_instances_test.rb} +36 -28
- data/test/{test_partial_mock.rb → partial_mock_test.rb} +20 -18
- data/test/{test_rails_view_stub.rb → rails_view_stub_test.rb} +3 -3
- data/test/{test_record_mode.rb → record_mode_test.rb} +2 -5
- data/test/rspec_integration/integration_spec.rb +14 -8
- data/test/{test_samples.rb → samples_test.rb} +13 -14
- data/test/{test_should_ignore_missing.rb → should_ignore_missing_test.rb} +4 -6
- data/test/{test_should_receive.rb → should_receive_test.rb} +39 -42
- data/test/test_setup.rb +30 -0
- data/test/test_unit_integration/{test_auto_test_unit.rb → auto_test_unit_test.rb} +4 -4
- data/test/tu_integration_test.rb +99 -0
- data/test/{test_undefined.rb → undefined_test.rb} +2 -3
- metadata +31 -39
- data/test/asserts.rb +0 -34
- data/test/test_tu_integration.rb +0 -94
data/lib/flexmock/rails.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#---
|
4
|
-
# Copyright 2003
|
4
|
+
# Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
|
5
5
|
# All rights reserved.
|
6
6
|
#
|
7
7
|
# Permission is granted for use, copying, modification, distribution,
|
data/lib/flexmock/recorder.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#---
|
4
|
-
# Copyright 2003
|
4
|
+
# Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
|
5
5
|
# All rights reserved.
|
6
6
|
|
7
7
|
# Permission is granted for use, copying, modification, distribution,
|
data/lib/flexmock/rspec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#---
|
4
|
-
# Copyright 2003
|
4
|
+
# Copyright 2003-2011 by Jim Weirich (jim.weirich@gmail.com).
|
5
5
|
# All rights reserved.
|
6
6
|
|
7
7
|
# Permission is granted for use, copying, modification, distribution,
|
data/lib/flexmock/test_unit.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#---
|
4
|
-
# Copyright 2003
|
4
|
+
# Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
|
5
5
|
# All rights reserved.
|
6
6
|
|
7
7
|
# Permission is granted for use, copying, modification, distribution,
|
@@ -29,4 +29,4 @@ module Test
|
|
29
29
|
|
30
30
|
end
|
31
31
|
end
|
32
|
-
end
|
32
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#---
|
4
|
-
# Copyright 2003
|
4
|
+
# Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
|
5
5
|
# All rights reserved.
|
6
6
|
|
7
7
|
# Permission is granted for use, copying, modification, distribution,
|
@@ -13,13 +13,13 @@ require 'test/unit'
|
|
13
13
|
require 'flexmock/base'
|
14
14
|
|
15
15
|
class FlexMock
|
16
|
-
|
16
|
+
|
17
17
|
####################################################################
|
18
18
|
# Test::Unit::TestCase Integration.
|
19
19
|
#
|
20
20
|
# Include this module in any TestCase class in a Test::Unit test
|
21
21
|
# suite to get integration with FlexMock. When this module is
|
22
|
-
# included, the mock container methods (e.g. flexmock(), flexstub())
|
22
|
+
# included, the mock container methods (e.g. flexmock(), flexstub())
|
23
23
|
# will be available.
|
24
24
|
#
|
25
25
|
# <b>Note:</b> If you define a +teardown+ method in the test case,
|
@@ -38,14 +38,14 @@ class FlexMock
|
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
####################################################################
|
43
43
|
# Adapter for adapting FlexMock to the Test::Unit framework.
|
44
44
|
#
|
45
45
|
class TestUnitFrameworkAdapter
|
46
46
|
include Test::Unit::Assertions
|
47
47
|
def assertion_failed_error
|
48
|
-
Test::Unit::AssertionFailedError
|
48
|
+
defined?(Test::Unit::AssertionFailedError) ? Test::Unit::AssertionFailedError : MiniTest::Assertion
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
data/lib/flexmock/undefined.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#---
|
4
|
-
# Copyright 2003
|
4
|
+
# Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
|
5
5
|
# All rights reserved.
|
6
6
|
|
7
7
|
# Permission is granted for use, copying, modification, distribution,
|
@@ -30,7 +30,11 @@ class FlexMock
|
|
30
30
|
def clone
|
31
31
|
self
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
|
+
def <=>(other)
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
34
38
|
def coerce(other)
|
35
39
|
[FlexMock.undefined, FlexMock.undefined]
|
36
40
|
end
|
@@ -43,8 +47,8 @@ class FlexMock
|
|
43
47
|
def self.undefined
|
44
48
|
@undefined
|
45
49
|
end
|
46
|
-
|
50
|
+
|
47
51
|
class << Undefined
|
48
52
|
private :new
|
49
53
|
end
|
50
|
-
end
|
54
|
+
end
|
data/lib/flexmock/validators.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#---
|
4
|
-
# Copyright 2003
|
4
|
+
# Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
|
5
5
|
# All rights reserved.
|
6
6
|
|
7
7
|
# Permission is granted for use, copying, modification, distribution,
|
@@ -73,5 +73,5 @@ class FlexMock
|
|
73
73
|
"Method '#{@exp}' should be called at most #{@limit} times,\n" +
|
74
74
|
"only called #{n} times") { n <= @limit }
|
75
75
|
end
|
76
|
-
end
|
76
|
+
end
|
77
77
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'test/
|
4
|
-
require 'flexmock'
|
3
|
+
require 'test/test_setup'
|
5
4
|
|
6
5
|
class FlexMock
|
7
6
|
module StubsAndExpects
|
@@ -36,21 +35,21 @@ class AliasingTest < Test::Unit::TestCase
|
|
36
35
|
assert_equal :woof!, m.pat
|
37
36
|
assert_equal :woof!, m.pat
|
38
37
|
end
|
39
|
-
|
38
|
+
|
40
39
|
def test_once_mocking
|
41
|
-
|
40
|
+
mock("a cute dog").expects(:pat).and_return(:woof!).mock
|
42
41
|
end
|
43
|
-
|
42
|
+
|
44
43
|
def test_twice_mocking
|
45
44
|
m = mock("a cute dog").expects(:pat).and_return(:woof!).twice.mock
|
46
|
-
assert_raises(
|
45
|
+
assert_raises(assertion_failed_error) { m.flexmock_verify }
|
47
46
|
end
|
48
|
-
|
47
|
+
|
49
48
|
def test_stubbing
|
50
49
|
m = stub("a cute dog").expects(:pat).and_return(:woof!).mock
|
51
50
|
assert_equal :woof!, m.pat
|
52
51
|
end
|
53
|
-
|
52
|
+
|
54
53
|
def test_partial
|
55
54
|
obj = Object.new
|
56
55
|
stub(obj).stubs(:wag).and_return(:tail)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#---
|
4
|
-
# Copyright 2003
|
4
|
+
# Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
|
5
5
|
# All rights reserved.
|
6
6
|
|
7
7
|
# Permission is granted for use, copying, modification, distribution,
|
@@ -9,8 +9,7 @@
|
|
9
9
|
# above copyright notice is included.
|
10
10
|
#+++
|
11
11
|
|
12
|
-
require "test/
|
13
|
-
require "flexmock"
|
12
|
+
require "test/test_setup"
|
14
13
|
|
15
14
|
# These tests exercise the interface used to define mocks
|
16
15
|
class TestFlexmockContainerMethods < Test::Unit::TestCase
|
@@ -21,36 +20,36 @@ class TestFlexmockContainerMethods < Test::Unit::TestCase
|
|
21
20
|
mock.should_receive(:hi).once.and_return(:lo)
|
22
21
|
assert_equal :lo, mock.hi
|
23
22
|
end
|
24
|
-
|
23
|
+
|
25
24
|
def test_mock_with_name
|
26
25
|
mock = flexmock("Danny")
|
27
26
|
mock.should_receive(:xxx).with(1)
|
28
|
-
ex = assert_raise(
|
27
|
+
ex = assert_raise(assertion_failed_error) { mock.xxx }
|
29
28
|
assert_match(/Danny/, ex.message)
|
30
29
|
end
|
31
|
-
|
30
|
+
|
32
31
|
def test_mock_with_symbol_name
|
33
32
|
mock = flexmock(:Danny)
|
34
33
|
mock.should_receive(:xxx).with(1)
|
35
|
-
ex = assert_raise(
|
34
|
+
ex = assert_raise(assertion_failed_error) { mock.xxx }
|
36
35
|
assert_match(/Danny/, ex.message)
|
37
36
|
end
|
38
|
-
|
37
|
+
|
39
38
|
def test_mock_with_hash
|
40
39
|
mock = flexmock(:hi => :lo, :good => :bye)
|
41
40
|
assert_equal :lo, mock.hi
|
42
41
|
assert_equal :bye, mock.good
|
43
42
|
end
|
44
|
-
|
43
|
+
|
45
44
|
def test_mock_with_name_and_hash
|
46
45
|
mock = flexmock("Danny", :hi => :lo, :good => :bye)
|
47
46
|
mock.should_receive(:xxx).with(1)
|
48
47
|
assert_equal :lo, mock.hi
|
49
48
|
assert_equal :bye, mock.good
|
50
|
-
ex = assert_raise(
|
49
|
+
ex = assert_raise(assertion_failed_error) { mock.xxx }
|
51
50
|
assert_match(/Danny/, ex.message)
|
52
51
|
end
|
53
|
-
|
52
|
+
|
54
53
|
def test_mock_with_name_hash_and_block
|
55
54
|
mock = flexmock("Danny", :hi => :lo, :good => :bye) do |m|
|
56
55
|
m.should_receive(:one).and_return(1)
|
@@ -58,25 +57,25 @@ class TestFlexmockContainerMethods < Test::Unit::TestCase
|
|
58
57
|
assert_equal 1, mock.one
|
59
58
|
assert_equal :lo, mock.hi
|
60
59
|
end
|
61
|
-
|
60
|
+
|
62
61
|
def test_basic_stub
|
63
62
|
fido = Object.new
|
64
63
|
mock = flexmock(fido)
|
65
64
|
mock.should_receive(:wag).and_return(:happy)
|
66
65
|
assert_equal :happy, fido.wag
|
67
66
|
end
|
68
|
-
|
67
|
+
|
69
68
|
def test_basic_stub_with_name
|
70
69
|
fido = Object.new
|
71
70
|
mock = flexmock(fido, "Danny")
|
72
71
|
mock.should_receive(:xxx).with(1).and_return(:happy)
|
73
|
-
ex = assert_raise(
|
72
|
+
ex = assert_raise(assertion_failed_error) { fido.xxx }
|
74
73
|
assert_match(/Danny/, ex.message)
|
75
74
|
end
|
76
75
|
|
77
76
|
def test_stub_with_quick_definitions
|
78
77
|
fido = Object.new
|
79
|
-
|
78
|
+
flexmock(fido, :wag => :happy)
|
80
79
|
assert_equal :happy, fido.wag
|
81
80
|
end
|
82
81
|
|
@@ -84,31 +83,31 @@ class TestFlexmockContainerMethods < Test::Unit::TestCase
|
|
84
83
|
fido = Object.new
|
85
84
|
mock = flexmock(fido, "Danny", :wag => :happy)
|
86
85
|
mock.should_receive(:xxx).with(1).and_return(:happy)
|
87
|
-
ex = assert_raise(
|
86
|
+
ex = assert_raise(assertion_failed_error) { fido.xxx }
|
88
87
|
assert_match(/Danny/, ex.message)
|
89
88
|
assert_equal :happy, fido.wag
|
90
89
|
end
|
91
|
-
|
90
|
+
|
92
91
|
def test_stubs_are_auto_verified
|
93
92
|
fido = Object.new
|
94
93
|
mock = flexmock(fido)
|
95
94
|
mock.should_receive(:hi).once
|
96
|
-
|
95
|
+
assert_raise(assertion_failed_error) { flexmock_verify }
|
97
96
|
end
|
98
|
-
|
97
|
+
|
99
98
|
def test_stubbing_a_string
|
100
99
|
s = "hello"
|
101
|
-
|
100
|
+
flexmock(:base, s, :length => 2)
|
102
101
|
assert_equal 2, s.length
|
103
102
|
end
|
104
|
-
|
103
|
+
|
105
104
|
def test_multiple_stubs_work_with_same_partial_mock_proxy
|
106
105
|
obj = Object.new
|
107
106
|
mock1 = flexmock(obj)
|
108
107
|
mock2 = flexmock(obj)
|
109
108
|
assert_equal mock1, mock2
|
110
109
|
end
|
111
|
-
|
110
|
+
|
112
111
|
def test_multiple_stubs_layer_behavior
|
113
112
|
obj = Object.new
|
114
113
|
flexmock(obj, :hi => :lo)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#---
|
4
|
-
# Copyright 2003
|
4
|
+
# Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
|
5
5
|
# All rights reserved.
|
6
6
|
|
7
7
|
# Permission is granted for use, copying, modification, distribution,
|
@@ -9,16 +9,15 @@
|
|
9
9
|
# above copyright notice is included.
|
10
10
|
#+++
|
11
11
|
|
12
|
-
require "test/
|
13
|
-
require "flexmock"
|
12
|
+
require "test/test_setup"
|
14
13
|
|
15
14
|
class TestFlexmockDefaultFrameworkAdapter < Test::Unit::TestCase
|
16
15
|
def setup
|
17
16
|
@adapter = FlexMock::DefaultFrameworkAdapter.new
|
18
17
|
end
|
19
18
|
|
20
|
-
def test_assert_block_raises_exception
|
21
|
-
|
19
|
+
def test_assert_block_raises_exception
|
20
|
+
assert_raise(FlexMock::DefaultFrameworkAdapter::AssertionFailedError) {
|
22
21
|
@adapter.assert_block("failure message") { false }
|
23
22
|
}
|
24
23
|
end
|
@@ -26,14 +25,14 @@ class TestFlexmockDefaultFrameworkAdapter < Test::Unit::TestCase
|
|
26
25
|
def test_assert_block_doesnt_raise_exception
|
27
26
|
@adapter.assert_block("failure message") { true }
|
28
27
|
end
|
29
|
-
|
28
|
+
|
30
29
|
def test_assert_equal_doesnt_raise_exception
|
31
30
|
@adapter.assert_equal("a", "a", "no message")
|
32
31
|
end
|
33
|
-
|
32
|
+
|
34
33
|
def test_assert_equal_can_fail
|
35
|
-
|
34
|
+
assert_raise(FlexMock::DefaultFrameworkAdapter::AssertionFailedError) {
|
36
35
|
@adapter.assert_equal("a", "b", "a should not equal b")
|
37
36
|
}
|
38
37
|
end
|
39
|
-
end
|
38
|
+
end
|
@@ -1,12 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'test/
|
4
|
-
require 'flexmock'
|
5
|
-
require 'test/asserts'
|
3
|
+
require 'test/test_setup'
|
6
4
|
|
7
5
|
class TestDemeterMocking < Test::Unit::TestCase
|
8
6
|
include FlexMock::TestCase
|
9
|
-
include FlexMock::FailureAssertion
|
10
7
|
|
11
8
|
def test_demeter_mocking
|
12
9
|
m = flexmock("A")
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#---
|
4
|
-
# Copyright 2003
|
4
|
+
# Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
|
5
5
|
# All rights reserved.
|
6
6
|
|
7
7
|
# Permission is granted for use, copying, modification, distribution,
|
@@ -9,10 +9,8 @@
|
|
9
9
|
# above copyright notice is included.
|
10
10
|
#+++
|
11
11
|
|
12
|
-
require 'test/
|
13
|
-
require 'flexmock'
|
12
|
+
require 'test/test_setup'
|
14
13
|
require 'flexmock/deprecated_methods'
|
15
|
-
require 'test/redirect_error'
|
16
14
|
|
17
15
|
class TestFlexMock < Test::Unit::TestCase
|
18
16
|
include FlexMock::TestCase
|
@@ -79,7 +77,7 @@ class TestFlexMock < Test::Unit::TestCase
|
|
79
77
|
@mock.blip
|
80
78
|
begin
|
81
79
|
@mock.flexmock_verify
|
82
|
-
rescue
|
80
|
+
rescue assertion_failed_error => err
|
83
81
|
end
|
84
82
|
assert_not_nil err
|
85
83
|
end
|
@@ -94,7 +92,7 @@ class TestFlexMock < Test::Unit::TestCase
|
|
94
92
|
end
|
95
93
|
|
96
94
|
def test_zero_counts
|
97
|
-
assert_raises(
|
95
|
+
assert_raises(assertion_failed_error) do
|
98
96
|
FlexMock.use { |m|
|
99
97
|
s { m.mock_handle(:blip, 0) }
|
100
98
|
m.blip
|
@@ -103,7 +101,7 @@ class TestFlexMock < Test::Unit::TestCase
|
|
103
101
|
end
|
104
102
|
|
105
103
|
def test_file_io_with_use
|
106
|
-
|
104
|
+
FlexMock.use do |m|
|
107
105
|
filedata = ["line 1", "line 2"]
|
108
106
|
s { m.mock_handle(:gets, 3) { filedata.shift } }
|
109
107
|
assert_equal 2, count_lines(m)
|
@@ -112,14 +110,14 @@ class TestFlexMock < Test::Unit::TestCase
|
|
112
110
|
|
113
111
|
def count_lines(stream)
|
114
112
|
result = 0
|
115
|
-
while
|
113
|
+
while stream.gets
|
116
114
|
result += 1
|
117
115
|
end
|
118
|
-
result
|
116
|
+
result
|
119
117
|
end
|
120
118
|
|
121
119
|
def test_use
|
122
|
-
assert_raises(
|
120
|
+
assert_raises(assertion_failed_error) {
|
123
121
|
FlexMock.use do |m|
|
124
122
|
s { m.mock_handle(:blip, 2) }
|
125
123
|
m.blip
|
@@ -145,7 +143,7 @@ class TestFlexMock < Test::Unit::TestCase
|
|
145
143
|
assert_equal 9, @mock.get
|
146
144
|
assert_equal 16, @mock.get
|
147
145
|
end
|
148
|
-
|
146
|
+
|
149
147
|
def test_respond_to_returns_false_for_non_handled_methods
|
150
148
|
assert(!@mock.respond_to?(:blah), "should not respond to blah")
|
151
149
|
end
|
@@ -222,6 +220,6 @@ class TestAnyInstance < Test::Unit::TestCase
|
|
222
220
|
end
|
223
221
|
end
|
224
222
|
m = Dog.new
|
225
|
-
assert_equal :whimper, m.bark
|
223
|
+
assert_equal :whimper, m.bark
|
226
224
|
end
|
227
|
-
end
|
225
|
+
end
|