Skip to content
This repository has been archived by the owner on Nov 11, 2017. It is now read-only.

Commit

Permalink
Update mock_test with the latest tests from Mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Feb 15, 2013
1 parent 79505d5 commit 1eadca9
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions test/unit/mock_test.rb
Expand Up @@ -4,7 +4,7 @@
# - keep: FakeExpectation test # - keep: FakeExpectation test
require File.expand_path('../../test_helper', __FILE__) require File.expand_path('../../test_helper', __FILE__)
require 'bourne/mock' require 'bourne/mock'
require 'mocha/expectation_error' require 'mocha/expectation_error_factory'
require 'set' require 'set'
require 'simple_counter' require 'simple_counter'


Expand All @@ -13,18 +13,18 @@ class MockTest < Test::Unit::TestCase
include Mocha include Mocha


def test_should_set_single_expectation def test_should_set_single_expectation
mock = build_mock mock = build_mock
mock.expects(:method1).returns(1) mock.expects(:method1).returns(1)
assert_nothing_raised(ExpectationErrorFactory.exception_class) do assert_nothing_raised(ExpectationErrorFactory.exception_class) do
assert_equal 1, mock.method1 assert_equal 1, mock.method1
end end
end end


def test_should_build_and_store_expectations def test_should_build_and_store_expectations
mock = build_mock mock = build_mock
expectation = mock.expects(:method1) expectation = mock.expects(:method1)
assert_not_nil expectation assert_not_nil expectation
assert_equal [expectation], mock.__expectations__.to_a assert_equal [expectation], mock.__expectations__.to_a
end end


def test_should_not_stub_everything_by_default def test_should_not_stub_everything_by_default
Expand Down Expand Up @@ -247,11 +247,34 @@ def test_should_not_respond_to_methods_which_the_responder_does_not_responds_to
assert_equal false, mock.respond_to?(:invoked_method) assert_equal false, mock.respond_to?(:invoked_method)
end end


def test_should_return_itself_to_allow_method_chaining def test_should_respond_to_methods_which_the_responder_instance_does_responds_to
klass = Class.new do
define_method(:respond_to?) { |symbol| true }
end
mock = build_mock
mock.responds_like_instance_of(klass)
assert_equal true, mock.respond_to?(:invoked_method)
end

def test_should_not_respond_to_methods_which_the_responder_instance_does_not_responds_to
klass = Class.new do
define_method(:respond_to?) { |symbol| false }
end
mock = build_mock
mock.responds_like_instance_of(klass)
assert_equal false, mock.respond_to?(:invoked_method)
end

def test_respond_like_should_return_itself_to_allow_method_chaining
mock = build_mock mock = build_mock
assert_same mock.responds_like(Object.new), mock assert_same mock.responds_like(Object.new), mock
end end


def test_respond_like_instance_of_should_return_itself_to_allow_method_chaining
mock = build_mock
assert_same mock.responds_like_instance_of(Object), mock
end

def test_should_not_raise_no_method_error_if_mock_is_not_restricted_to_respond_like_a_responder def test_should_not_raise_no_method_error_if_mock_is_not_restricted_to_respond_like_a_responder
mock = build_mock mock = build_mock
mock.stubs(:invoked_method) mock.stubs(:invoked_method)
Expand Down Expand Up @@ -296,7 +319,7 @@ def test_should_raise_no_method_error_with_message_indicating_that_mock_is_const


def test_should_handle_respond_to_with_private_methods_param_without_error def test_should_handle_respond_to_with_private_methods_param_without_error
mock = build_mock mock = build_mock
assert_nothing_raised{ mock.respond_to?(:object_id, false) } assert_nothing_raised { mock.respond_to?(:object_id, false) }
end end


def test_should_respond_to_any_method_if_stubbing_everything def test_should_respond_to_any_method_if_stubbing_everything
Expand Down

0 comments on commit 1eadca9

Please sign in to comment.