flexmock 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/CHANGELOG +10 -1
  2. data/README +390 -209
  3. data/Rakefile +31 -10
  4. data/doc/GoogleExample.rdoc +275 -0
  5. data/doc/releases/flexmock-0.6.0.rdoc +136 -0
  6. data/lib/flexmock.rb +3 -1160
  7. data/lib/flexmock/argument_matchers.rb +57 -0
  8. data/lib/flexmock/argument_types.rb +42 -0
  9. data/lib/flexmock/base.rb +22 -0
  10. data/lib/flexmock/composite.rb +10 -0
  11. data/lib/flexmock/core.rb +206 -0
  12. data/lib/flexmock/core_class_methods.rb +92 -0
  13. data/lib/flexmock/default_framework_adapter.rb +31 -0
  14. data/lib/flexmock/expectation.rb +334 -0
  15. data/lib/flexmock/expectation_director.rb +59 -0
  16. data/lib/flexmock/mock_container.rb +159 -0
  17. data/lib/flexmock/noop.rb +13 -0
  18. data/lib/flexmock/partial_mock.rb +226 -0
  19. data/lib/flexmock/recorder.rb +71 -0
  20. data/lib/flexmock/rspec.rb +34 -0
  21. data/lib/flexmock/test_unit.rb +32 -0
  22. data/lib/flexmock/test_unit_integration.rb +53 -0
  23. data/lib/flexmock/validators.rb +77 -0
  24. data/test/rspec_integration/integration_spec.rb +36 -0
  25. data/test/test_container_methods.rb +119 -0
  26. data/test/test_default_framework_adapter.rb +39 -0
  27. data/test/test_example.rb +1 -1
  28. data/test/test_extended_should_receive.rb +63 -0
  29. data/test/test_mock.rb +1 -1
  30. data/test/test_naming.rb +1 -1
  31. data/test/{test_any_instance.rb → test_new_instances.rb} +15 -8
  32. data/test/{test_stubbing.rb → test_partial_mock.rb} +44 -44
  33. data/test/test_record_mode.rb +1 -1
  34. data/test/test_samples.rb +6 -8
  35. data/test/test_should_receive.rb +7 -3
  36. data/test/test_tu_integration.rb +1 -1
  37. data/test/test_unit_integration/test_auto_test_unit.rb +34 -0
  38. metadata +30 -5
  39. data/test/test_class_interception.rb +0 -140
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  #---
4
- # Copyright 2006 by Jim Weirich (jweirich@one.net).
4
+ # Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org).
5
5
  # All rights reserved.
6
6
 
7
7
  # Permission is granted for use, copying, modification, distribution,
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  #---
4
- # Copyright 2006 by Jim Weirich (jweirich@one.net).
4
+ # Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org).
5
5
  # All rights reserved.
6
6
 
7
7
  # Permission is granted for use, copying, modification, distribution,
@@ -10,10 +10,12 @@
10
10
  #+++
11
11
 
12
12
  require 'test/unit'
13
+ require 'flexmock'
13
14
 
14
15
  # Sample FlexMock Usage.
15
16
 
16
17
  class TestSamples < Test::Unit::TestCase
18
+ include FlexMock::TestCase
17
19
 
18
20
  # This is a basic example where we setup a mock object to mimic an
19
21
  # IO object. We know that the +count_lines+ method uses gets, so we
@@ -21,10 +23,9 @@ class TestSamples < Test::Unit::TestCase
21
23
  # elements of an array (just as the real +gets+ returns successive
22
24
  # elements of a file.
23
25
  def test_file_io
24
- file = FlexMock.new
25
- filedata = ["line 1", "line 2"]
26
- file.mock_handle(:gets) { filedata.shift }
27
- assert_equal 2, count_lines(file)
26
+ mock_file = flexmock("file")
27
+ mock_file.should_receive(:gets).and_return("line 1", "line 2", nil)
28
+ assert_equal 2, count_lines(mock_file)
28
29
  end
29
30
 
30
31
  # Count the number of lines in a file. Used in the test_file_io
@@ -36,8 +37,5 @@ class TestSamples < Test::Unit::TestCase
36
37
  end
37
38
  n
38
39
  end
39
-
40
- def test_x
41
- end
42
40
  end
43
41
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  #---
4
- # Copyright 2006 by Jim Weirich (jweirich@one.net).
4
+ # Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org).
5
5
  # All rights reserved.
6
6
 
7
7
  # Permission is granted for use, copying, modification, distribution,
@@ -588,11 +588,15 @@ class TestFlexMockShoulds < Test::Unit::TestCase
588
588
  end
589
589
 
590
590
  def test_expectation_formating
591
- m = FlexMock.new("m")
592
- exp = m.should_receive(:f).with(1,"two", /^3$/).and_return(0).at_least.once
591
+ exp = FlexMock.new("m").should_receive(:f).with(1,"two", /^3$/).and_return(0).at_least.once
593
592
  assert_equal 'f(1, "two", /^3$/)', exp.to_s
594
593
  end
595
594
 
595
+ def test_multi_expectation_formatting
596
+ exp = FlexMock.new.should_receive(:f, :g).with(1)
597
+ assert_equal "[f(1), g(1)]", exp.to_s
598
+ end
599
+
596
600
  def test_explicit_ordering_with_limits_allow_multiple_return_values
597
601
  FlexMock.use('mock') do |m|
598
602
  m.should_receive(:f).with(2).once.and_return { :first_time }
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  #---
4
- # Copyright 2006 by Jim Weirich (jweirich@one.net).
4
+ # Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org).
5
5
  # All rights reserved.
6
6
 
7
7
  # Permission is granted for use, copying, modification, distribution,
@@ -0,0 +1,34 @@
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
+
14
+ require "flexmock/base"
15
+ require "flexmock/test_unit"
16
+
17
+ class TestFlexmockTestUnit < Test::Unit::TestCase
18
+ def teardown
19
+ super
20
+ end
21
+
22
+ # This test should pass.
23
+ def test_can_create_mocks
24
+ m = flexmock("mock")
25
+ m.should_receive(:hi).once
26
+ m.hi
27
+ end
28
+
29
+ # This test should fail during teardown.
30
+ def test_should_fail__mocks_are_auto_verified
31
+ m = flexmock("mock")
32
+ m.should_receive(:hi).once
33
+ end
34
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: flexmock
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.1
7
- date: 2007-04-09 00:00:00 -04:00
6
+ version: 0.6.0
7
+ date: 2007-04-14 00:00:00 -04:00
8
8
  summary: Simple and Flexible Mock Objects for Testing
9
9
  require_paths:
10
10
  - lib
@@ -33,24 +33,47 @@ files:
33
33
  - Rakefile
34
34
  - README
35
35
  - lib/flexmock.rb
36
- - test/test_any_instance.rb
37
- - test/test_class_interception.rb
36
+ - lib/flexmock/argument_matchers.rb
37
+ - lib/flexmock/argument_types.rb
38
+ - lib/flexmock/base.rb
39
+ - lib/flexmock/composite.rb
40
+ - lib/flexmock/core.rb
41
+ - lib/flexmock/core_class_methods.rb
42
+ - lib/flexmock/default_framework_adapter.rb
43
+ - lib/flexmock/expectation.rb
44
+ - lib/flexmock/expectation_director.rb
45
+ - lib/flexmock/mock_container.rb
46
+ - lib/flexmock/noop.rb
47
+ - lib/flexmock/partial_mock.rb
48
+ - lib/flexmock/recorder.rb
49
+ - lib/flexmock/rspec.rb
50
+ - lib/flexmock/test_unit.rb
51
+ - lib/flexmock/test_unit_integration.rb
52
+ - lib/flexmock/validators.rb
53
+ - test/test_container_methods.rb
54
+ - test/test_default_framework_adapter.rb
38
55
  - test/test_example.rb
56
+ - test/test_extended_should_receive.rb
39
57
  - test/test_mock.rb
40
58
  - test/test_naming.rb
59
+ - test/test_new_instances.rb
60
+ - test/test_partial_mock.rb
41
61
  - test/test_record_mode.rb
42
62
  - test/test_samples.rb
43
63
  - test/test_should_receive.rb
44
- - test/test_stubbing.rb
45
64
  - test/test_tu_integration.rb
65
+ - test/rspec_integration/integration_spec.rb
66
+ - test/test_unit_integration/test_auto_test_unit.rb
46
67
  - flexmock.blurb
47
68
  - install.rb
69
+ - doc/GoogleExample.rdoc
48
70
  - doc/releases/flexmock-0.4.0.rdoc
49
71
  - doc/releases/flexmock-0.4.1.rdoc
50
72
  - doc/releases/flexmock-0.4.2.rdoc
51
73
  - doc/releases/flexmock-0.4.3.rdoc
52
74
  - doc/releases/flexmock-0.5.0.rdoc
53
75
  - doc/releases/flexmock-0.5.1.rdoc
76
+ - doc/releases/flexmock-0.6.0.rdoc
54
77
  test_files: []
55
78
 
56
79
  rdoc_options:
@@ -62,12 +85,14 @@ rdoc_options:
62
85
  extra_rdoc_files:
63
86
  - README
64
87
  - CHANGELOG
88
+ - doc/GoogleExample.rdoc
65
89
  - doc/releases/flexmock-0.4.0.rdoc
66
90
  - doc/releases/flexmock-0.4.1.rdoc
67
91
  - doc/releases/flexmock-0.4.2.rdoc
68
92
  - doc/releases/flexmock-0.4.3.rdoc
69
93
  - doc/releases/flexmock-0.5.0.rdoc
70
94
  - doc/releases/flexmock-0.5.1.rdoc
95
+ - doc/releases/flexmock-0.6.0.rdoc
71
96
  executables: []
72
97
 
73
98
  extensions: []
@@ -1,140 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #---
4
- # Copyright 2006 by Jim Weirich (jweirich@one.net).
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
-
15
- class Bark
16
- def listen
17
- :woof
18
- end
19
- def Bark.identify
20
- :barking
21
- end
22
- end
23
-
24
- class Meow
25
- def listen
26
- :meow
27
- end
28
- end
29
-
30
- class Dog
31
- def bark
32
- Bark.new
33
- end
34
- def bark_id
35
- Bark.identify
36
- end
37
- end
38
-
39
- class TestClassInterception < Test::Unit::TestCase
40
- include FlexMock::TestCase
41
-
42
- def test_original_functionality
43
- dog = Dog.new
44
- assert_equal :woof, dog.bark.listen
45
- end
46
-
47
- def test_interception
48
- interceptor = intercept(Bark).in(Dog).with(Meow)
49
- assert_kind_of FlexMock::ClassProxy, Dog::Bark
50
- assert_equal Meow, Dog::Bark.proxied_class
51
- dog = Dog.new
52
- assert_equal :meow, dog.bark.listen
53
- ensure
54
- interceptor.restore if interceptor
55
- end
56
-
57
- # Since interception leaves a proxy class behind, we want to make
58
- # sure interception works twice on the same object. So we repeat
59
- # this test in full. We don't know which tests will _actually_ run
60
- # first, but it doesn't matter as long as it is done twice.
61
- def test_interception_repeated
62
- test_interception
63
- end
64
-
65
- def test_interception_with_strings
66
- interceptor = intercept("Bark").in("Dog").with("Meow")
67
- assert_equal :meow, Dog.new.bark.listen
68
- ensure
69
- interceptor.restore if interceptor
70
- end
71
-
72
- def test_interception_with_symbols
73
- interceptor = intercept(:Bark).in(:Dog).with(:Meow)
74
- assert_equal :meow, Dog.new.bark.listen
75
- ensure
76
- interceptor.restore if interceptor
77
- end
78
-
79
- def test_interception_with_mixed_identifiers
80
- interceptor = intercept(:Bark).in("Dog").with(Meow)
81
- assert_equal :meow, Dog.new.bark.listen
82
- ensure
83
- interceptor.restore if interceptor
84
- end
85
-
86
- def test_interception_proxy_forward_other_methods
87
- d = Dog.new
88
- assert_equal :barking, d.bark_id
89
-
90
- interceptor = intercept(:Bark).in("Dog").with(Meow)
91
- interceptor.restore
92
-
93
- d = Dog.new
94
- assert_equal :barking, d.bark_id
95
- end
96
-
97
- def test_interceptions_fails_with_bad_class_names
98
- ex = assert_raises(FlexMock::BadInterceptionError) {
99
- intercept("BADNAME").in("Dog").with("Meow")
100
- }
101
- assert_match(/intercepted/, ex.message)
102
- assert_match(/BADNAME/, ex.message)
103
-
104
- ex = assert_raises(FlexMock::BadInterceptionError) {
105
- intercept(Bark).in("BADNAME").with("Meow")
106
- }
107
- assert_match(/target/, ex.message)
108
- assert_match(/BADNAME/, ex.message)
109
-
110
- ex = assert_raises(FlexMock::BadInterceptionError) {
111
- intercept(Bark).in("Dog").with("BADNAME")
112
- }
113
- assert_match(/replacement/, ex.message)
114
- assert_match(/BADNAME/, ex.message)
115
- end
116
-
117
- end
118
-
119
- class TestClassInterceptionExample < Test::Unit::TestCase
120
- include FlexMock::TestCase
121
-
122
- def setup
123
- @dog = Dog.new
124
- @mock = flexmock('bark')
125
- intercept(Bark).in(Dog).with(@mock)
126
- end
127
-
128
- def test_interception
129
- @mock.should_receive(:new).with_no_args.once.and_return(:purr)
130
- assert_equal :purr, @dog.bark
131
- end
132
- end
133
-
134
- class TestMockFactory < Test::Unit::TestCase
135
- def test_mock_returns_factory
136
- m = FlexMock.new("m")
137
- f = m.mock_factory
138
- assert_equal m, f.new
139
- end
140
- end