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 55 56
|
require "test_helper"
require "blankslate"
class SnapshotTest < Minitest::Test
include Introspection
def test_should_report_methods_added
instance = Class.new.new
before = Snapshot.new(instance)
instance.__metaclass__.send(:define_method, :foo) {}
after = Snapshot.new(instance)
diff = before.diff(after)
assert_equal 1, diff[:added].length
assert_equal instance.__metaclass__, diff[:added][0].owner
assert_equal :foo, diff[:added][0].name
end
def test_should_report_methods_removed
instance = Class.new.new
instance.__metaclass__.send(:define_method, :foo) {}
before = Snapshot.new(instance)
instance.__metaclass__.send(:remove_method, :foo)
after = Snapshot.new(instance)
diff = before.diff(after)
assert_equal 1, diff[:removed].length
assert_equal instance.__metaclass__, diff[:removed][0].owner
assert_equal :foo, diff[:removed][0].name
end
def test_should_indicate_snapshot_has_changed_when_method_is_added
instance = Class.new.new
assert_snapshot_changed(instance) do
instance.__metaclass__.send(:define_method, :foo) {}
end
end
def test_should_indicate_snapshot_has_changed_when_method_is_removed
instance = Class.new.new
instance.__metaclass__.send(:define_method, :foo) {}
assert_snapshot_changed(instance) do
instance.__metaclass__.send(:remove_method, :foo)
end
end
def test_should_indicate_snapshot_has_not_changed_when_method_no_methods_are_added_or_removed
instance = Class.new.new
assert_snapshot_unchanged(instance) {}
end
def test_should_cope_with_blankslate_object
# Should not raise anything
Snapshot.new(BlankSlate.new)
end
end
|