~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to vendor/gems/mocha-0.5.6/test/acceptance/mocked_methods_dispatch_acceptance_test.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mfrom: (1.1.8 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080726154345-c03m49twzxewdwjn
Tags: 0.24.5-2
* Fix puppetlast to work with 0.24.5
* Adjust logcheck to match against new log messages in 0.24.5
* Update standards version to 3.8.0 (no changes)
* Update changelog to reduce length of line to make lintian happy

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require File.join(File.dirname(__FILE__), "..", "test_helper")
 
2
require 'mocha'
 
3
require 'test_runner'
 
4
 
 
5
class MockedMethodDispatchAcceptanceTest < Test::Unit::TestCase
 
6
 
 
7
  include TestRunner
 
8
 
 
9
  def test_should_find_latest_matching_expectation
 
10
    test_result = run_test do
 
11
      mock = mock()
 
12
      mock.stubs(:method).returns(1)
 
13
      mock.stubs(:method).returns(2)
 
14
      assert_equal 2, mock.method
 
15
      assert_equal 2, mock.method
 
16
      assert_equal 2, mock.method
 
17
    end
 
18
    assert_passed(test_result)
 
19
  end
 
20
 
 
21
  def test_should_find_latest_expectation_which_has_not_stopped_matching
 
22
    test_result = run_test do
 
23
      mock = mock()
 
24
      mock.stubs(:method).returns(1)
 
25
      mock.stubs(:method).once.returns(2)
 
26
      assert_equal 2, mock.method
 
27
      assert_equal 1, mock.method
 
28
      assert_equal 1, mock.method
 
29
    end
 
30
    assert_passed(test_result)
 
31
  end
 
32
 
 
33
  def test_should_keep_finding_later_stub_and_so_never_satisfy_earlier_expectation
 
34
    test_result = run_test do
 
35
      mock = mock()
 
36
      mock.expects(:method).returns(1)
 
37
      mock.stubs(:method).returns(2)
 
38
      assert_equal 2, mock.method
 
39
      assert_equal 2, mock.method
 
40
      assert_equal 2, mock.method
 
41
    end
 
42
    assert_failed(test_result)
 
43
  end
 
44
 
 
45
  def test_should_find_later_expectation_until_it_stops_matching_then_find_earlier_stub
 
46
    test_result = run_test do
 
47
      mock = mock()
 
48
      mock.stubs(:method).returns(1)
 
49
      mock.expects(:method).returns(2)
 
50
      assert_equal 2, mock.method
 
51
      assert_equal 1, mock.method
 
52
      assert_equal 1, mock.method
 
53
    end
 
54
    assert_passed(test_result)
 
55
  end
 
56
 
 
57
  def test_should_find_latest_expectation_with_range_of_expected_invocation_count_which_has_not_stopped_matching
 
58
    test_result = run_test do
 
59
      mock = mock()
 
60
      mock.stubs(:method).returns(1)
 
61
      mock.stubs(:method).times(2..3).returns(2)
 
62
      assert_equal 2, mock.method
 
63
      assert_equal 2, mock.method
 
64
      assert_equal 2, mock.method
 
65
      assert_equal 1, mock.method
 
66
      assert_equal 1, mock.method
 
67
    end
 
68
    assert_passed(test_result)
 
69
  end
 
70
 
 
71
end
 
 
b'\\ No newline at end of file'