hardmock 1.3.6 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,7 +1,11 @@
1
+ Hardmock 1.3.7
2
+
3
+ * BUG FIX: expects! could not setup expectations for more than one concrete method on an object, since the method aliasing and rewriting was only taking place when the background mock instance was first created. This logic has been updated and now you can do all the things you'd expect.
4
+
1
5
  Hardmock 1.3.6
2
6
 
3
7
  * BUG FIX: In Rails apps (and others) Hardmock and Fixtures battled viciously over "setup" and "teardown" and "method_added" (and any other clever test enhancement tool, namely Mocha) causing unpredictable results, notably failure to auto-verify mocks after teardown (leading to false positive tests).
4
- ** The newly-added TestUnitBeforeAfter provides TestCase.before_setup and TestCase.after_teardown -- formal test wrapping hooks -- lets Hardmock provide its preparation and auto-verify behavior without contending for setup/teardown supremacy.
8
+ * The newly-added TestUnitBeforeAfter provides TestCase.before_setup and TestCase.after_teardown -- formal test wrapping hooks -- lets Hardmock provide its preparation and auto-verify behavior without contending for setup/teardown supremacy.
5
9
 
6
10
  Hardmock 1.3.5
7
11
 
data/README CHANGED
@@ -66,5 +66,6 @@ This puts the implicit conveniences into your spec context, like "create_mocks"
66
66
  "verify_mocks" after each Example is run.
67
67
 
68
68
  == Author
69
+
69
70
  * David Crosby crosby at http://atomicobject.com
70
71
  * (c) 2006,2007 Atomic Object LLC
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rake'
2
2
  require 'rubygems'
3
3
 
4
- HARDMOCK_VERSION = "1.3.6"
4
+ HARDMOCK_VERSION = "1.3.7"
5
5
 
6
6
  Dir["rake_tasks/*.rake"].each { |f| load f }
7
7
 
@@ -109,16 +109,22 @@ module Hardmock
109
109
 
110
110
  method_name = method_name.to_s
111
111
 
112
- if @_my_mock.nil?
113
- @_my_mock = Mock.new(_my_name, $main_mock_control)
112
+ @_my_mock = Mock.new(_my_name, $main_mock_control) if @_my_mock.nil?
113
+
114
+ unless Hardmock.has_replaced_method?(self, method_name)
115
+ # Track the method as replaced
114
116
  Hardmock::ReplacedMethod.new(self, method_name)
115
117
 
116
- if methods.include?(method_name.to_s)
118
+ # Preserver original implementation of the method by aliasing it away
119
+ if methods.include?(method_name)
117
120
  hm_meta_eval do
118
121
  alias_method "_hardmock_original_#{method_name}".to_sym, method_name.to_sym
119
122
  end
120
123
  end
121
124
 
125
+ # Re-define the method to utilize our patron mock instance.
126
+ # (This global-temp-var thing is hokey but I was having difficulty generating
127
+ # code for the meta class.)
122
128
  begin
123
129
  $method_text_temp = %{
124
130
  def #{method_name}(*args,&block)
@@ -131,7 +137,6 @@ module Hardmock
131
137
  ensure
132
138
  $method_text_temp = nil
133
139
  end
134
-
135
140
  end
136
141
 
137
142
  return @_my_mock.expects(method_name, *args, &block)
@@ -11,10 +11,9 @@ module Test #:nodoc:#
11
11
  # Use after_teardown to define one or more actions to be executed after teardown for ALL tests.
12
12
  #
13
13
  # COMING SOON?
14
- # * Hook for running actions prior to setup
15
- # * Hooks for before_teardown, after_setup, on_error
16
- # * Options for positional control, eg, after_teardown :before_other_actions
17
- # * Provide tagging/filtering so action execution can be controlled specifically?
14
+ # * (maybe?) Hooks for before_teardown, after_setup, on_error
15
+ # * (maybe?) Options for positional control, eg, after_teardown :before_other_actions
16
+ # * (maybe?) Provide tagging/filtering so action execution can be controlled specifically?
18
17
  #
19
18
  # == Usage
20
19
  #
@@ -313,6 +313,80 @@ class StubbingTest < Test::Unit::TestCase
313
313
  reset_stubs
314
314
  end
315
315
 
316
+ it "can mock several different class methods at once" do
317
+ sim_code = lambda do |input|
318
+ record = Multitool.find_record(input)
319
+ report = Multitool.generate_report(record)
320
+ Multitool.format_output(report)
321
+ end
322
+
323
+ @identifier = "the id"
324
+ @record = "the record"
325
+ @report = "the report"
326
+ @output = "the output"
327
+
328
+ Multitool.expects!(:find_record).with(@identifier).returns(@record)
329
+ Multitool.expects!(:generate_report).with(@record).returns(@report)
330
+ Multitool.expects!(:format_output).with(@report).returns(@output)
331
+
332
+ result = sim_code.call(@identifier)
333
+ assert_equal @output, result, "Wrong output"
334
+ end
335
+
336
+ it "can handle a mix of different and repeat class method mock calls" do
337
+ prep = lambda {
338
+ Multitool.expects!(:find_record).with("A").returns("1")
339
+ Multitool.expects!(:generate_report).with("1")
340
+ Multitool.expects!(:find_record).with("B").returns("2")
341
+ Multitool.expects!(:generate_report).with("2")
342
+ }
343
+
344
+ prep[]
345
+ Multitool.generate_report(Multitool.find_record("A"))
346
+ Multitool.generate_report(Multitool.find_record("B"))
347
+
348
+ prep[]
349
+ Multitool.generate_report(Multitool.find_record("A"))
350
+ assert_error Hardmock::ExpectationError, /Wrong arguments/, /find_record\("B"\)/, /find_record\("C"\)/ do
351
+ Multitool.generate_report(Multitool.find_record("C"))
352
+ end
353
+ clear_expectations
354
+ end
355
+
356
+ it "can mock several concrete instance methods at once" do
357
+ inst = OtherMultitool.new
358
+ sim_code = lambda do |input|
359
+ record = inst.find_record(input)
360
+ report = inst.generate_report(record)
361
+ inst.format_output(report)
362
+ end
363
+
364
+ @identifier = "the id"
365
+ @record = "the record"
366
+ @report = "the report"
367
+ @output = "the output"
368
+
369
+ inst.expects!(:find_record).with(@identifier).returns(@record)
370
+ inst.expects!(:generate_report).with(@record).returns(@report)
371
+ inst.expects!(:format_output).with(@report).returns(@output)
372
+
373
+ result = sim_code.call(@identifier)
374
+ assert_equal @output, result, "Wrong output"
375
+ end
376
+
377
+ it "verifies all concrete expects! from several different expectations" do
378
+ Multitool.expects!(:find_record)
379
+ Multitool.expects!(:generate_report)
380
+ Multitool.expects!(:format_output)
381
+
382
+ Multitool.find_record
383
+ Multitool.generate_report
384
+
385
+ assert_error Hardmock::VerifyError, /unmet expectations/i, /format_output/i do
386
+ verify_mocks
387
+ end
388
+ end
389
+
316
390
  it "will not allow expects! to be used on a mock object" do
317
391
  create_mock :cow
318
392
  assert_error Hardmock::StubbingError, /expects!/, /mock/i, /something/ do
@@ -377,5 +451,29 @@ class StubbingTest < Test::Unit::TestCase
377
451
  end
378
452
  end
379
453
 
454
+ class Multitool
455
+ def self.find_record(*a)
456
+ raise "The real Multitool.find_record was called with #{a.inspect}"
457
+ end
458
+ def self.generate_report(*a)
459
+ raise "The real Multitool.generate_report was called with #{a.inspect}"
460
+ end
461
+ def self.format_output(*a)
462
+ raise "The real Multitool.format_output was called with #{a.inspect}"
463
+ end
464
+ end
465
+
466
+ class OtherMultitool
467
+ def find_record(*a)
468
+ raise "The real OtherMultitool#find_record was called with #{a.inspect}"
469
+ end
470
+ def generate_report(*a)
471
+ raise "The real OtherMultitool#generate_report was called with #{a.inspect}"
472
+ end
473
+ def format_output(*a)
474
+ raise "The real OtherMultitool#format_output was called with #{a.inspect}"
475
+ end
476
+ end
477
+
380
478
  end
381
479
 
@@ -182,7 +182,7 @@ class TestUnitBeforeAfter < Test::Unit::TestCase
182
182
  "test_something(MyExampleTest):",
183
183
  "RuntimeError: Error in 2nd before_setup",
184
184
  "_test_file_temp.rb:10",
185
- "/hardmock/lib/test_unit_before_after.rb:136:in `call'"
185
+ "/hardmock/lib/test_unit_before_after.rb:"
186
186
  see_results :tests => 1, :assertions => 0, :failures => 0, :errors => 1
187
187
  end
188
188
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hardmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.6
4
+ version: 1.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Crosby
@@ -9,7 +9,7 @@ autorequire: hardmock
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2007-12-11 00:00:00 -05:00
12
+ date: 2009-11-08 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -62,7 +62,9 @@ files:
62
62
  - CHANGES
63
63
  - LICENSE
64
64
  has_rdoc: true
65
- homepage: http://hardmock.rubyforge.org
65
+ homepage: http://atomicobject.github.com/hardmock
66
+ licenses: []
67
+
66
68
  post_install_message:
67
69
  rdoc_options:
68
70
  - --line-numbers
@@ -88,9 +90,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
90
  requirements: []
89
91
 
90
92
  rubyforge_project: hardmock
91
- rubygems_version: 0.9.5
93
+ rubygems_version: 1.3.5
92
94
  signing_key:
93
- specification_version: 2
95
+ specification_version: 3
94
96
  summary: A strict, ordered, expectation-oriented mock object library.
95
97
  test_files:
96
98
  - test/functional/assert_error_test.rb