Sha256: cdb5fee139085af965d63b29914038436388baf5bb8aabb0c5b56526a341140f

Contents?: true

Size: 1.4 KB

Versions: 42

Compression:

Stored size: 1.4 KB

Contents

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

class ExpectorTest < Test::Unit::TestCase
  include Hardmock

  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

42 entries across 39 versions & 3 rubygems

Version Path
ceedling-0.31.1 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.31.0 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.30.0 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.28.3 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.28.2 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.28.1 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.27.0 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.25.0 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.24.0 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.22.0 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.21.0 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.20.3 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.20.2 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.19.0 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.18.0 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.17.0 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.16.0 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.15.6 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.15.5 vendor/hardmock/test/unit/expector_test.rb
ceedling-0.15.4 vendor/hardmock/test/unit/expector_test.rb