flexmock 1.0.0.beta.2 → 1.0.0.beta.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -3,7 +3,7 @@
3
3
  FlexMock is a simple, but flexible, mock object library for Ruby unit
4
4
  testing.
5
5
 
6
- Version :: 1.0.0.beta.2
6
+ Version :: 1.0.0.beta.3
7
7
 
8
8
  = Links
9
9
 
@@ -141,7 +141,7 @@ FlexMock::MockContainer#flexmock for more details.
141
141
  teh base class. This helps prevent tests from becoming stale with
142
142
  incorrectly mocked objects when the method names change.
143
143
 
144
- Use the <code>explicit</code> modifier to
144
+ Use the <code>explicitly</code> modifier to
145
145
  <code>should_receive</code> to override base class restrictions.
146
146
 
147
147
  * <b>partial_mock = flexmock(real_object)</b>
@@ -271,13 +271,13 @@ a mock object. See theFlexMock::Expectation for more details.
271
271
  Define a number of expected messages that have the same constrants, but
272
272
  return different values.
273
273
 
274
- * <b>should_receive(...).explicit</b>
274
+ * <b>should_receive(...).explicitly</b>
275
275
 
276
- If a mock has a base class, use the <code>explicit</code> modifier
276
+ If a mock has a base class, use the <code>explicitly</code> modifier
277
277
  to override the restriction on method names imposed by the base
278
- class. The explicit modifier must come immediately after the
279
- <code>should_receive</code> call and before any other expectation
280
- declarators.
278
+ class. The <code>explicitly</code> modifier must come immediately
279
+ after the <code>should_receive</code> call and before any other
280
+ expectation declarators.
281
281
 
282
282
  If a mock does not have a base class, this method has no effect.
283
283
 
data/lib/flexmock/core.rb CHANGED
@@ -134,13 +134,15 @@ class FlexMock
134
134
  @expectations[method_name]
135
135
  end
136
136
 
137
- def flexmock_spies_on(base_class)
137
+ def flexmock_based_on(base_class)
138
138
  @base_class = base_class
139
+ should_receive(class: base_class)
139
140
  end
140
141
 
141
- def flexmock_was_called_with?(sym, args, options={})
142
+ # True if the mock received the given method and arguments.
143
+ def flexmock_received?(sym, args, options={})
142
144
  count = 0
143
- @calls.each { |call_sym, call_args, call_block|
145
+ @calls.each { |call_sym, call_args|
144
146
  count += 1 if (call_sym == sym) && ArgumentMatching.all_match?(args, call_args)
145
147
  }
146
148
  if options[:times]
@@ -151,6 +153,14 @@ class FlexMock
151
153
  result
152
154
  end
153
155
 
156
+ # Return the list of calls made on this mock. Used in formatting
157
+ # error messages.
158
+ def flexmock_calls
159
+ @calls
160
+ end
161
+
162
+ # Invocke the original non-mocked functionality for the given
163
+ # symbol.
154
164
  def flexmock_invoke_original(sym, args)
155
165
  return FlexMock.undefined
156
166
  end
@@ -383,7 +383,7 @@ class FlexMock
383
383
 
384
384
  # No-op for allowing explicit calls when explicit not explicitly
385
385
  # needed.
386
- def explicit
386
+ def explicitly
387
387
  self
388
388
  end
389
389
 
@@ -16,7 +16,7 @@ class FlexMock
16
16
  @base_class = base_class
17
17
  end
18
18
 
19
- def explicit
19
+ def explicitly
20
20
  @explicit = true
21
21
  self
22
22
  end
@@ -32,7 +32,7 @@ class FlexMock
32
32
  fail NoMethodError, "Cannot stub methods not defined by the base class\n" +
33
33
  " Method: #{@method_name}\n" +
34
34
  " Base Class: #{@base_class}\n" +
35
- " (Use explicit to override)"
35
+ " (Use 'explicitly' to override)"
36
36
  end
37
37
  end
38
38
  end
@@ -158,7 +158,7 @@ class FlexMock
158
158
  yield(mock) if block_given?
159
159
  flexmock_remember(mock)
160
160
  ContainerHelper.add_model_methods(mock, model_class, id) if model_class
161
- mock.flexmock_spies_on(base_class) if base_class
161
+ mock.flexmock_based_on(base_class) if base_class
162
162
  result
163
163
  end
164
164
  alias flexstub flexmock
@@ -34,7 +34,7 @@ class FlexMock
34
34
  MOCK_METHODS = [
35
35
  :should_receive, :new_instances,
36
36
  :flexmock_get, :flexmock_teardown, :flexmock_verify,
37
- :flexmock_was_called_with?,
37
+ :flexmock_received?, :flexmock_calls,
38
38
  ]
39
39
 
40
40
  # Initialize a PartialMockProxy object.
@@ -177,8 +177,13 @@ class FlexMock
177
177
  end
178
178
 
179
179
  # Forward to the mock
180
- def flexmock_was_called_with?(*args)
181
- @mock.flexmock_was_called_with?(*args)
180
+ def flexmock_received?(*args)
181
+ @mock.flexmock_received?(*args)
182
+ end
183
+
184
+ # Forward to the mock
185
+ def flexmock_calls
186
+ @mock.flexmock_calls
182
187
  end
183
188
 
184
189
  # Set the proxy's mock container. This set value is ignored
@@ -19,7 +19,7 @@ class FlexMock
19
19
  @options = {}
20
20
  @options[:times] = @times if @times
21
21
  @options[:with_block] = @needs_block unless @needs_block.nil?
22
- @spy.flexmock_was_called_with?(@method_name, @args, @options)
22
+ @spy.flexmock_received?(@method_name, @args, @options)
23
23
  end
24
24
 
25
25
  def failure_message_for_should
@@ -18,7 +18,11 @@ class FlexMock
18
18
  result << spy.inspect
19
19
  result << times_description(options[:times])
20
20
  result << block_description(options[:with_block])
21
- result << "."
21
+ result << ".\n"
22
+ result << "The following messages have been received:\n"
23
+ spy.flexmock_calls.each do |sym, args|
24
+ result << " " << call_description(sym, args) << "\n"
25
+ end
22
26
  result
23
27
  end
24
28
 
@@ -21,7 +21,7 @@ class FlexMock
21
21
  method_name = args.shift
22
22
  end
23
23
  args = nil if args == [:_]
24
- bool = spy.flexmock_was_called_with?(method_name, args, options)
24
+ bool = spy.flexmock_received?(method_name, args, options)
25
25
  if negative
26
26
  bool = !bool
27
27
  message = describe_spy_negative_expectation(spy, method_name, args, options)
@@ -5,7 +5,7 @@ class FlexMock
5
5
  MINOR = 0,
6
6
  BUILD = 0,
7
7
  BETA = 'beta',
8
- BETAREV = 2,
8
+ BETAREV = 3,
9
9
  ]
10
10
  end
11
11
 
@@ -0,0 +1,52 @@
1
+ require 'test/test_setup'
2
+
3
+ class BaseClassTest < Test::Unit::TestCase
4
+ include FlexMock::TestCase
5
+
6
+ class FooBar
7
+ def foo
8
+ end
9
+
10
+ def method_missing(sym, *args, &block)
11
+ return :poof if sym == :barq
12
+ super
13
+ end
14
+
15
+ def respond_to?(method)
16
+ method == :barq || super
17
+ end
18
+ end
19
+
20
+ def mock
21
+ @mock ||= flexmock(:on, FooBar)
22
+ end
23
+
24
+ def test_auto_mocks_class
25
+ assert_equal FooBar, mock.class
26
+ end
27
+
28
+ def test_can_stub_existing_methods
29
+ mock.should_receive(:foo => :bar)
30
+ assert_equal :bar, mock.foo
31
+ end
32
+
33
+ def test_can_not_stub_non_class_defined_methods
34
+ ex = assert_raises(NoMethodError) do
35
+ mock.should_receive(:baz => :bar)
36
+ end
37
+ assert_match(/can *not stub methods.*base.*class/i, ex.message)
38
+ assert_match(/class:.+FooBar/i, ex.message)
39
+ assert_match(/method:.+baz/i, ex.message)
40
+ end
41
+
42
+ def test_can_explicitly_stub_non_class_defined_methods
43
+ mock.should_receive(:baz).explicitly.and_return(:bar)
44
+ assert_equal :bar, mock.baz
45
+ end
46
+
47
+ def test_can_explicitly_stub_meta_programmed_methods
48
+ mock.should_receive(:barq).explicitly.and_return(:bar)
49
+ assert_equal :bar, mock.barq
50
+ end
51
+
52
+ end
data/test/spys_test.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'test/test_setup'
4
- require 'flexmock/spy_describers'
5
4
 
6
5
  class TestSpys < Test::Unit::TestCase
7
6
  include FlexMock::TestCase
@@ -94,7 +93,7 @@ class TestSpys < Test::Unit::TestCase
94
93
  @spy.should_receive(:foo).and_return(:hi)
95
94
  result = @spy.foo
96
95
  assert_equal result, :hi
97
- assert @spy.flexmock_was_called_with?(:foo, nil)
96
+ assert_spy_called @spy, :foo
98
97
  end
99
98
 
100
99
  def test_calling_non_spy_base_methods_is_an_error
@@ -113,13 +112,13 @@ class TestSpys < Test::Unit::TestCase
113
112
  end
114
113
 
115
114
  def test_cant_put_expectations_on_non_base_class_methods_unless_explicit
116
- exp = @spy.should_receive(:baz).explicit.and_return(:bar)
115
+ exp = @spy.should_receive(:baz).explicitly.and_return(:bar)
117
116
  @spy.baz
118
117
  assert_spy_called @spy, :baz
119
118
  end
120
119
 
121
120
  def test_ok_to_use_explicit_even_when_its_not_needed
122
- exp = @spy.should_receive(:foo).explicit.and_return(:bar)
121
+ exp = @spy.should_receive(:foo).explicitly.and_return(:bar)
123
122
  @spy.foo
124
123
  assert_spy_called @spy, :foo
125
124
  end
@@ -133,7 +132,7 @@ class TestSpys < Test::Unit::TestCase
133
132
  assert_spy_called @foo, :foo
134
133
  end
135
134
 
136
- def test_can_spy_on_class_methods
135
+ def test_can_spy_on_class_defined_methods
137
136
  flexmock(FooBar).should_receive(:new).and_return(:dummy)
138
137
  FooBar.new
139
138
  assert_spy_called FooBar, :new,
data/test/test_setup.rb CHANGED
@@ -25,6 +25,5 @@ class FlexMock
25
25
  end
26
26
  ex
27
27
  end
28
-
29
28
  end
30
29
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: flexmock
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 1.0.0.beta.2
5
+ version: 1.0.0.beta.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jim Weirich
@@ -80,6 +80,7 @@ files:
80
80
  - lib/flexmock.rb
81
81
  - test/aliasing_test.rb
82
82
  - test/assert_spy_called_test.rb
83
+ - test/base_class_test.rb
83
84
  - test/container_methods_test.rb
84
85
  - test/default_framework_adapter_test.rb
85
86
  - test/demeter_mocking_test.rb