File: flexmodel_test.rb

package info (click to toggle)
ruby-flexmock 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 836 kB
  • sloc: ruby: 7,572; makefile: 6
file content (54 lines) | stat: -rw-r--r-- 1,365 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env ruby

require 'test_helper'

class DummyModel
end

class ChildModel < DummyModel
end

######################################################################
class TestFlexModel < Minitest::Test
  include FlexMock::Minitest

  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