Sha256: f12a42eff43f65f7b2e5dfe6e28ef93a26d84c7adf64687563afc058b706bd89

Contents?: true

Size: 1.74 KB

Versions: 14

Compression:

Stored size: 1.74 KB

Contents

#!/usr/bin/env ruby

#---
# Copyright 2003-2012 by Jim Weirich (jim.weirich@gmail.com).
# All rights reserved.

# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.
#+++

require "test/test_setup"

module ExtendedShouldReceiveTests
  def test_accepts_expectation_hash
    @mock.should_receive( :foo => :bar, :baz => :froz )
    assert_equal :bar, @obj.foo
    assert_equal :froz, @obj.baz
  end

  def test_accepts_list_of_methods
    @mock.should_receive(:foo, :bar, "baz")
    assert_nil @obj.foo
    assert_nil @obj.bar
    assert_nil @obj.baz
  end

  def test_contraints_apply_to_all_expectations
    @mock.should_receive(:foo, :bar => :baz).with(1)
    ex = assert_raise(assertion_failed_error) { @obj.foo(2) }
    ex = assert_raise(assertion_failed_error) { @obj.bar(2) }
    assert_equal :baz, @obj.bar(1)
  end

  def test_count_contraints_apply_to_all_expectations
    @mock.should_receive(:foo, :bar => :baz).once
    @obj.foo
    assert_raise(assertion_failed_error) { @mock.flexmock_verify }
  end

  def test_multiple_should_receives_are_allowed
    @mock.should_receive(:hi).and_return(:bye).
      should_receive(:hello => :goodbye)
    assert_equal :bye, @obj.hi
    assert_equal :goodbye, @obj.hello
  end
end

class TestExtendedShouldReceiveOnFullMocks < Test::Unit::TestCase
  include FlexMock::TestCase
  include ExtendedShouldReceiveTests

  def setup
    @mock = flexmock("mock")
    @obj = @mock
  end

end

class TestExtendedShouldReceiveOnPartialMockProxies < Test::Unit::TestCase
  include FlexMock::TestCase
  include ExtendedShouldReceiveTests

  def setup
    @obj = Object.new
    @mock = flexmock(@obj, "mock")
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
flexmock-1.3.2 test/extended_should_receive_test.rb
flexmock-1.3.1 test/extended_should_receive_test.rb
flexmock-1.3.0 test/extended_should_receive_test.rb
flexmock-1.2.0 test/extended_should_receive_test.rb
flexmock-1.1.0 test/extended_should_receive_test.rb
flexmock-1.0.4 test/extended_should_receive_test.rb
flexmock-1.0.3 test/extended_should_receive_test.rb
flexmock-1.0.2 test/extended_should_receive_test.rb
flexmock-1.0.1 test/extended_should_receive_test.rb
flexmock-1.0.0 test/extended_should_receive_test.rb
flexmock-1.0.0.beta.4 test/extended_should_receive_test.rb
flexmock-1.0.0.beta.3 test/extended_should_receive_test.rb
flexmock-1.0.0.beta.2 test/extended_should_receive_test.rb
flexmock-1.0.0.beta.1 test/extended_should_receive_test.rb