Sha256: 24793f9d09dfa7fa50ddc5dd146eead15bd420e256413262a6dbfe0b3e224df0

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

#!/usr/bin/env ruby

require 'test/unit'

class DummyModel
end

class ChildModel < DummyModel
end

######################################################################
class TestFlexModel < Test::Unit::TestCase
  include FlexMock::TestCase

  def test_initial_conditions
    model = flexmock(:model, DummyModel)
    assert_match(/^DummyModel_\d+/, model.flexmock_name)
    assert_equal model.id.to_s, model.to_params
    assert ! model.new_record?
    assert model.is_a?(DummyModel)
    # TODO: Make these work!!!
    assert_equal DummyModel, model.class
    assert model.instance_of?(DummyModel)
    assert model.kind_of?(DummyModel)
  end

  def test_classifying_mock_models
    model = flexmock(:model, ChildModel)

    assert model.kind_of?(ChildModel)
    assert model.instance_of?(ChildModel)

    assert model.kind_of?(DummyModel)
    assert ! model.instance_of?(DummyModel)
  end

  def test_mock_models_have_different_ids
    m1 = flexmock(:model, DummyModel)
    m2 = flexmock(:model, DummyModel)
    assert m2.id != m1.id
  end

  def test_mock_models_can_have_quick_defs
    model = flexmock(:model, DummyModel, :xyzzy => :ok)
    assert_equal :ok, model.xyzzy
  end

  def test_mock_models_can_have_blocks
    model = flexmock(:model, DummyModel) do |m|
      m.should_receive(:xyzzy => :okdokay)
    end
    assert_equal :okdokay, model.xyzzy
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flexmock-0.8.0 test/test_flexmodel.rb
flexmock-0.7.0 test/test_flexmodel.rb
flexmock-0.7.1 test/test_flexmodel.rb