flexmock 1.3.3 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.autotest +3 -0
  3. data/.gitignore +14 -0
  4. data/.togglerc +7 -0
  5. data/.travis.yml +5 -0
  6. data/.yardopts +2 -0
  7. data/CHANGES +11 -0
  8. data/Gemfile +1 -4
  9. data/README.md +39 -11
  10. data/Rakefile +6 -217
  11. data/doc/examples/rspec_examples_spec.rb +244 -0
  12. data/doc/examples/test_unit_examples_test.rb +240 -0
  13. data/doc/jamis.rb +591 -0
  14. data/flexmock.gemspec +33 -0
  15. data/lib/flexmock.rb +0 -1
  16. data/lib/flexmock/composite_expectation.rb +1 -1
  17. data/lib/flexmock/core.rb +3 -7
  18. data/lib/flexmock/core_class_methods.rb +5 -1
  19. data/lib/flexmock/default_framework_adapter.rb +2 -2
  20. data/lib/flexmock/expectation.rb +29 -3
  21. data/lib/flexmock/expectation_director.rb +1 -1
  22. data/lib/flexmock/minitest.rb +13 -0
  23. data/lib/flexmock/minitest_extensions.rb +26 -0
  24. data/lib/flexmock/minitest_integration.rb +111 -0
  25. data/lib/flexmock/mock_container.rb +1 -2
  26. data/lib/flexmock/partial_mock.rb +61 -104
  27. data/lib/flexmock/recorder.rb +1 -2
  28. data/lib/flexmock/rspec.rb +6 -3
  29. data/lib/flexmock/test_unit_integration.rb +14 -0
  30. data/lib/flexmock/validators.rb +5 -4
  31. data/lib/flexmock/version.rb +1 -9
  32. data/rakelib/metrics.rake +40 -0
  33. data/rakelib/preview.rake +4 -0
  34. data/rakelib/tags.rake +18 -0
  35. data/todo.txt +20 -0
  36. metadata +61 -86
  37. data/Gemfile.lock +0 -20
  38. data/doc/examples/rspec_examples_spec.rdoc +0 -245
  39. data/doc/examples/test_unit_examples_test.rdoc +0 -241
  40. data/test/aliasing_test.rb +0 -66
  41. data/test/assert_spy_called_test.rb +0 -119
  42. data/test/base_class_test.rb +0 -71
  43. data/test/based_partials_test.rb +0 -51
  44. data/test/container_methods_test.rb +0 -118
  45. data/test/default_framework_adapter_test.rb +0 -38
  46. data/test/demeter_mocking_test.rb +0 -191
  47. data/test/deprecated_methods_test.rb +0 -225
  48. data/test/examples_from_readme_test.rb +0 -157
  49. data/test/expectation_description_test.rb +0 -80
  50. data/test/extended_should_receive_test.rb +0 -69
  51. data/test/flexmodel_test.rb +0 -54
  52. data/test/mock_builder_test.rb +0 -68
  53. data/test/naming_test.rb +0 -84
  54. data/test/new_instances_test.rb +0 -215
  55. data/test/object_extensions_test.rb +0 -25
  56. data/test/partial_mock_test.rb +0 -458
  57. data/test/record_mode_test.rb +0 -158
  58. data/test/redirect_error.rb +0 -16
  59. data/test/rspec_integration/integration_spec.rb +0 -56
  60. data/test/rspec_integration/spy_example_spec.rb +0 -207
  61. data/test/samples_test.rb +0 -283
  62. data/test/should_ignore_missing_test.rb +0 -84
  63. data/test/should_receive_test.rb +0 -1155
  64. data/test/spys_test.rb +0 -215
  65. data/test/symbol_extensions_test.rb +0 -8
  66. data/test/test_class_extensions.rb +0 -34
  67. data/test/test_setup.rb +0 -92
  68. data/test/test_unit_integration/auto_test_unit_test.rb +0 -42
  69. data/test/test_unit_integration/minitest_teardown_test.rb +0 -14
  70. data/test/tu_integration_test.rb +0 -99
  71. data/test/undefined_test.rb +0 -87
data/test/spys_test.rb DELETED
@@ -1,215 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/test_setup'
4
-
5
- class TestSpys < Test::Unit::TestCase
6
- include FlexMock::TestCase
7
-
8
- class FooBar
9
- def foo
10
- :foofoo
11
- end
12
- def bar
13
- end
14
- end
15
-
16
- def setup
17
- super
18
- @spy = flexmock(:on, FooBar)
19
- end
20
-
21
- def test_spy_detects_simple_call
22
- @spy.foo
23
- assert_spy_called @spy, :foo
24
- end
25
-
26
- def test_spy_detects_simple_call_ignoring_args
27
- @spy.foo(1)
28
- assert_spy_called @spy, :foo, :_
29
- end
30
-
31
- def test_spy_rejects_a_never_made_call
32
- @spy.foo
33
- assert_spy_not_called @spy, :bar
34
- end
35
-
36
- def test_spy_detects_call_with_literal_arg
37
- @spy.foo(1)
38
- assert_spy_called @spy, :foo, 1
39
- end
40
-
41
- def test_spy_detects_call_with_class_arg
42
- @spy.foo(1)
43
- assert_spy_called @spy, :foo, Integer
44
- end
45
-
46
- def test_spy_rejects_call_with_non_matching_literal_arg
47
- @spy.foo(2)
48
- assert_spy_not_called @spy, :foo, 1
49
- end
50
-
51
- def test_spy_detects_call_with_multiple_arguments
52
- @spy.foo(1, "HI", :foo)
53
- assert_spy_called @spy, :foo, /1/, "HI", Symbol
54
- end
55
-
56
- def test_spy_detects_multiple_calls_with_different_arguments
57
- @spy.foo(1)
58
- @spy.foo(1)
59
- assert_spy_called @spy, {:times => 2}, :foo, 1
60
- end
61
-
62
- def test_spy_rejects_if_times_options_not_matching
63
- @spy.foo(1)
64
- @spy.foo(1)
65
- assert_spy_not_called @spy, {:times => 1}, :foo, 1
66
- end
67
-
68
- def test_spy_detects_a_block
69
- @spy.foo { }
70
- assert_spy_called @spy, :foo, Proc
71
- end
72
-
73
- def test_spy_rejects_a_block
74
- @spy.foo { }
75
- assert_spy_not_called @spy, {:with_block => false}, :foo
76
- end
77
-
78
- def test_spy_detects_a_missing_block
79
- @spy.foo
80
- assert_spy_called @spy, {:with_block => false}, :foo
81
- end
82
-
83
- def test_spy_rejects_a_missing_block
84
- @spy.foo
85
- assert_spy_not_called @spy, :foo, Proc
86
- end
87
-
88
- def test_spy_ignores_block
89
- @spy.foo { }
90
- assert_spy_called @spy, :foo, Proc
91
- end
92
-
93
- def test_spy_accepts_correct_additional_validations
94
- @spy.foo(2)
95
- is_even = proc { |n| assert_equal 0, n%2 }
96
- assert_spy_called @spy, { :and => is_even }, :foo, Integer
97
- end
98
-
99
- def test_spy_accepts_multiple_additional_validations_first_failing
100
- @spy.foo(4)
101
- is_two = proc { |n| assert_equal 2, n }
102
- is_even = proc { |n| assert_equal 0, n%2 }
103
- assert_failed(/2.*expected but was.*4/mi) do
104
- assert_spy_called @spy, { :and => [is_two, is_even] }, :foo, Integer
105
- end
106
- end
107
-
108
- def test_spy_accepts_multiple_additional_validations_second_failing
109
- @spy.foo(4)
110
- is_even = proc { |n| assert_equal 0, n%2 }
111
- is_two = proc { |n| assert_equal 2, n }
112
- assert_failed(/2.*expected but was.*4/mi) do
113
- assert_spy_called @spy, { :and => [is_even, is_two] }, :foo, Integer
114
- end
115
- end
116
-
117
- def test_spy_rejects_incorrect_additional_validations
118
- @spy.foo(3)
119
- is_even = proc { |n| assert_equal 0, n%2 }
120
- assert_failed(/0.*expected but was.*1/mi) do
121
- assert_spy_called @spy, { :and => is_even }, :foo, Integer
122
- end
123
- end
124
-
125
- def test_spy_selectively_applies_additional_validations
126
- @spy.foo(2)
127
- @spy.foo(3)
128
- @spy.foo(4)
129
- is_even = proc { |n| assert_equal 0, n%2 }
130
- assert_failed(/0.*expected but was.*1/mi) do
131
- assert_spy_called @spy, { :and => is_even, :on => 2 }, :foo, Integer
132
- end
133
- end
134
-
135
- def assert_failed(message_pattern)
136
- failed = false
137
- begin
138
- yield
139
- rescue assertion_failed_error => ex
140
- failed = true
141
- assert_match message_pattern, ex.message
142
- end
143
- assert(failed, "Expected block to fail")
144
- end
145
-
146
- def test_spy_methods_can_be_stubbed
147
- @spy.should_receive(:foo).and_return(:hi)
148
- result = @spy.foo
149
- assert_equal result, :hi
150
- assert_spy_called @spy, :foo
151
- end
152
-
153
- def test_spy_cannot_see_normal_methods
154
- foo = FooBar.new
155
- flexmock(foo)
156
- assert_equal :foofoo, foo.foo
157
- assert_spy_not_called foo, :foo
158
- end
159
-
160
- def test_spy_cannot_see_normal_methods2
161
- foo = FooBar.new
162
- flexmock(foo).should_receive(:foo).pass_thru
163
- assert_equal :foofoo, foo.foo
164
- assert_spy_called foo, :foo
165
- end
166
-
167
- def test_calling_non_spy_base_methods_is_an_error
168
- assert_raise(NoMethodError) do
169
- @spy.baz
170
- end
171
- end
172
-
173
- def test_cant_put_expectations_on_non_base_class_methodsx
174
- ex = assert_raise(NoMethodError) do
175
- @spy.should_receive(:baz).and_return(:bar)
176
- end
177
- assert_match(/cannot stub.*defined.*base.*class/i, ex.message)
178
- assert_match(/method: +baz/i, ex.message)
179
- assert_match(/base class: +TestSpys::FooBar/i, ex.message)
180
- end
181
-
182
- def test_cant_put_expectations_on_non_base_class_methods_unless_explicit
183
- @spy.should_receive(:baz).explicitly.and_return(:bar)
184
- @spy.baz
185
- assert_spy_called @spy, :baz
186
- end
187
-
188
- def test_ok_to_use_explicit_even_when_its_not_needed
189
- @spy.should_receive(:foo).explicitly.and_return(:bar)
190
- @spy.foo
191
- assert_spy_called @spy, :foo
192
- end
193
-
194
- def test_can_spy_on_partial_mocks
195
- @foo = FooBar.new
196
- @spy = flexmock(@foo)
197
- @foo.should_receive(:foo => :baz)
198
- result = @foo.foo
199
- assert_equal :baz, result
200
- assert_spy_called @foo, :foo
201
- end
202
-
203
- def test_can_spy_on_class_defined_methods
204
- flexmock(FooBar).should_receive(:new).and_return(:dummy)
205
- FooBar.new
206
- assert_spy_called FooBar, :new
207
- end
208
-
209
- def test_can_spy_on_regular_mocks
210
- mock = flexmock("regular mock")
211
- mock.should_receive(:foo => :bar)
212
- mock.foo
213
- assert_spy_called mock, :foo
214
- end
215
- end
@@ -1,8 +0,0 @@
1
- require 'test/test_setup'
2
-
3
- class SymbolEtentensionsTest < Test::Unit::TestCase
4
- def test_as_name_converts_appropriatly
5
- method_name_class = self.class.instance_methods.first.class
6
- assert_equal method_name_class, :some_name.flexmock_as_name.class
7
- end
8
- end
@@ -1,34 +0,0 @@
1
- require 'test/test_setup'
2
-
3
- class ClassExtensionsTest < Test::Unit::TestCase
4
-
5
- class Dog
6
- def wag
7
- end
8
-
9
- def method_missing(sym, *args, &block)
10
- if sym == :bark
11
- :woof
12
- else
13
- super
14
- end
15
- end
16
-
17
- def responds_to?(sym)
18
- sym == :bark || super
19
- end
20
- end
21
-
22
- def test_class_directly_defines_method
23
- assert Dog.flexmock_defined?(:wag)
24
- end
25
-
26
- def test_class_indirectly_defines_method
27
- assert ! Dog.flexmock_defined?(:bark)
28
- end
29
-
30
- def test_class_does_not_define_method
31
- assert ! Dog.flexmock_defined?(:jump)
32
- end
33
-
34
- end
data/test/test_setup.rb DELETED
@@ -1,92 +0,0 @@
1
- require 'test/unit'
2
- require 'fileutils'
3
-
4
- require 'flexmock'
5
- require 'test/redirect_error'
6
-
7
- class FlexMock
8
- module TestCase
9
- def assertion_failed_error
10
- FlexMock.framework_adapter.assertion_failed_error
11
- end
12
-
13
- # Assertion helper used to assert validation failure. If a
14
- # message is given, then the error message should match the
15
- # expected error message.
16
- def assert_failure(options={}, &block)
17
- message = options[:message]
18
- ex = assert_raises(assertion_failed_error) { yield }
19
- if message
20
- case message
21
- when Regexp
22
- assert_match message, ex.message
23
- when String
24
- assert ex.message.index(message), "Error message '#{ex.message}' should contain '#{message}'"
25
- end
26
- end
27
- ex
28
- end
29
-
30
- # Similar to assert_failure, but assumes that a mock generated
31
- # error object is return, so additional tests on the backtrace are
32
- # added.
33
- def assert_mock_failure(options={}, &block)
34
- ex = assert_failure(options, &block)
35
- file = eval("__FILE__", block.binding)
36
- assert_matching_line(ex, file, options)
37
- end
38
-
39
- # Assert that there is a line matching file in the backtrace.
40
- # Options are:
41
- #
42
- # deep: true -- matching line can be anywhere in backtrace,
43
- # otherwise it must be the first.
44
- #
45
- # line: n -- Add a line number to the match
46
- #
47
- def assert_matching_line(ex, file, options)
48
- line = options[:line]
49
- search_all = options[:deep]
50
- if line
51
- loc_re = /#{Regexp.quote(file)}:#{line}/
52
- else
53
- loc_re = Regexp.compile(Regexp.quote(file))
54
- end
55
-
56
-
57
- if search_all
58
- bts = ex.backtrace.join("\n")
59
- assert_with_block("expected a backtrace line to match #{loc_re}\nBACKTRACE:\n#{bts}") {
60
- ex.backtrace.any? { |bt| loc_re =~ bt }
61
- }
62
- else
63
- assert_match(loc_re, ex.backtrace.first)
64
- end
65
-
66
- ex
67
- end
68
-
69
- unless defined?(refute_match)
70
- def refute_match(*args)
71
- assert_no_match(*args)
72
- end
73
- end
74
-
75
- def assert_with_block(msg=nil)
76
- unless yield
77
- assert(false, msg || "Expected block to yield true")
78
- end
79
- end
80
-
81
- def pending(msg="")
82
- state = "PASSING"
83
- begin
84
- yield
85
- rescue Exception => _
86
- state = "FAILING"
87
- end
88
- where = caller.first.split(/:in/).first
89
- puts "\n#{state} PENDING TEST (#{msg}) #{where}"
90
- end
91
- end
92
- end
@@ -1,42 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #---
4
- # Copyright 2003-2013 by Jim Weirich (jim.weirich@gmail.com).
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/test_setup"
13
-
14
- require "flexmock/base"
15
- require "flexmock/test_unit"
16
-
17
- class TestFlexmockTestUnit < Test::Unit::TestCase
18
- def teardown
19
- failed = false
20
- begin
21
- super
22
- rescue Exception => ex
23
- failed = true
24
- end
25
- assert_equal @should_fail, failed, "Expected failed to be #{@should_fail}"
26
- end
27
-
28
- # This test should pass.
29
- def test_can_create_mocks
30
- m = flexmock("mock")
31
- m.should_receive(:hi).once
32
- m.hi
33
- @should_fail = false
34
- end
35
-
36
- # This test should fail during teardown.
37
- def test_should_fail__mocks_are_auto_verified
38
- m = flexmock("mock")
39
- m.should_receive(:hi).once
40
- @should_fail = true
41
- end
42
- end
@@ -1,14 +0,0 @@
1
- require "minitest/autorun"
2
- require 'flexmock/test_unit'
3
-
4
- class SimpleTest < MiniTest::Unit::TestCase
5
-
6
- # This validates that the minitest teardown method is properly
7
- # aliased when using MiniTest.
8
- #
9
- # (see https://github.com/jimweirich/flexmock/issues/14).
10
- #
11
- def test_flexmock
12
- flexmock()
13
- end
14
- end
@@ -1,99 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #---
4
- # Copyright 2003-2013 by Jim Weirich (jim.weirich@gmail.com).
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/test_setup'
13
-
14
- # The following tests exercise Test::Unit integration. They are
15
- # disabled if actually running under MiniTest because the MiniTest is
16
- # different enough internally that the tests are not worthwhile.
17
-
18
- unless defined?(MiniTest)
19
- class TestTuIntegrationFlexMockMethod < Test::Unit::TestCase
20
- include FlexMock::TestCase
21
-
22
- def test_can_construct_flexmock
23
- mock = flexmock("x")
24
- mock.should_receive(:hi).and_return(:hello)
25
- assert_equal :hello, mock.hi
26
- end
27
-
28
- def test_can_construct_flexmock_with_block
29
- mock = flexmock("x") do |m|
30
- m.should_receive(:hi).and_return(:hello)
31
- end
32
- assert_equal :hello, mock.hi
33
- end
34
- end
35
-
36
- class TestTuIntegrationMockVerificationInTeardown < Test::Unit::TestCase
37
- include FlexMock::TestCase
38
-
39
- def teardown
40
- assert_raise(assertion_failed_error) do
41
- super
42
- end
43
- end
44
-
45
- def test_mock_verification_occurs_during_teardown
46
- flexmock("xyz").should_receive(:hi).with(any).once
47
- end
48
- end
49
-
50
- class TestTuIntegrationMockVerificationWithoutSetup < Test::Unit::TestCase
51
- include FlexMock::TestCase
52
-
53
- def teardown
54
- assert_raise(assertion_failed_error) do
55
- super
56
- end
57
- end
58
-
59
- def test_mock_verification_occurs_during_teardown
60
- flexmock("xyz").should_receive(:hi).with(any).once
61
- end
62
- end
63
-
64
- class TestTuIntegrationMockVerificationForgetfulSetup < Test::Unit::TestCase
65
- include FlexMock::TestCase
66
-
67
- def teardown
68
- assert_raise(assertion_failed_error) do
69
- super
70
- end
71
- end
72
-
73
- def test_mock_verification_occurs_during_teardown
74
- flexmock("xyz").should_receive(:hi).with(any).once
75
- end
76
- end
77
-
78
- class TestTuIntegrationSetupOverridenAndNoMocksOk < Test::Unit::TestCase
79
- include FlexMock::TestCase
80
-
81
- def test_mock_verification_occurs_during_teardown
82
- end
83
- end
84
-
85
- class TestTuIntegrationFailurePreventsVerification < Test::Unit::TestCase
86
- include FlexMock::TestCase
87
-
88
- def test_mock_verification_occurs_during_teardown
89
- flexmock('m').should_receive(:hi).once
90
- simulate_failure
91
- end
92
-
93
- private
94
-
95
- def simulate_failure
96
- @test_passed = false
97
- end
98
- end
99
- end