Sha256: b987a82d21a2f001844364424943a4f173b6a43b9ebff0d2573abef3f7b5d5c6

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 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

  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

  #
  # TESTS
  #
  def test_method_missing
    try_it_with 'wonder_bread'
    try_it_with 'whatever'
  end

  def test_methods_that_wont_trigger_method_missing
    mock = Object.new
    mock_control = MyControl.new
    builder = ExpBuilder.new

    exp = Expector.new(mock, mock_control, builder)
    assert_equal mock, exp.instance_eval("@mock")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
minilab-1.0.0-mswin32 vendor/hardmock/test/unit/expector_test.rb