Sha256: 0b61fcf9e322fec56352bb657ee68ffe962fc06d641658e77c60c4f1e2899352

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
require 'hardmock'

class ExpectorTest < Test::Unit::TestCase

  class MyControl
    attr_reader :added
    def add_expectation(expectation)
      @added ||= []
      @added << expectation
    end
  end

  class ExpBuilder
    attr_reader :options
    def build_expectation(options)
      @options = options
      "dummy expectation"
    end
  end

  #
  # TESTS
  #

  def test_method_missing
    try_it_with 'wonder_bread'
    try_it_with 'whatever'
  end

  def test_methods_that_wont_trigger_method_missing
    try_it_with 'instance_eval'
  end

  def try_it_with(method_name)
    mock = Object.new
    mock_control = MyControl.new
    builder = ExpBuilder.new

    exp = Expector.new(mock, mock_control, builder)
    output = exp.send(method_name,:with, 1, 'sauce')

    assert_same mock, builder.options[:mock]
    assert_equal method_name, builder.options[:method].to_s
    assert_equal [:with,1,'sauce'], builder.options[:arguments]
    assert_nil builder.options[:block]
    assert_equal [ "dummy expectation" ], mock_control.added,
      "Wrong expectation added to control"

    assert_equal "dummy expectation", output, "Expectation should have been returned"
  end


end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hardmock-1.1.0 test/unit/expector_test.rb
hardmock-1.2.0 test/unit/expector_test.rb