Permalink
Browse files

Added tests for the new `respond_to()'.

  • Loading branch information...
toddsundsted committed Feb 24, 2012
1 parent 68fb145 commit 110c2ca57abbf977ad9de0dbb2dde00076a0fadc
Showing with 61 additions and 0 deletions.
  1. +61 −0 test/test_miscellaneous.rb
View
@@ -9,4 +9,65 @@ def test_that_isa_does_not_crash_the_server
end
end
+ def test_that_respond_to_returns_verb_details_if_the_caller_is_the_owner
+ run_test_as('programmer') do
+ o = create(:nothing)
+ add_verb(o, ['player', 'x', 'foo'], ['none', 'none', 'none'])
+ add_verb(o, ['player', '', 'bar'], ['none', 'none', 'none'])
+ assert_equal [o, 'foo'], simplify(command(%Q|; return respond_to(#{o}, "foo"); |))
+ assert_equal 0, simplify(command(%Q|; return respond_to(#{o}, "bar"); |))
+ end
+ end
+
+ def test_that_respond_to_returns_verb_details_if_the_caller_is_a_wizard
+ o = nil
+ run_test_as('programmer') do
+ o = create(:nothing)
+ add_verb(o, ['player', 'x', 'foo'], ['none', 'none', 'none'])
+ add_verb(o, ['player', '', 'bar'], ['none', 'none', 'none'])
+ end
+ run_test_as('wizard') do
+ assert_equal [o, 'foo'], simplify(command(%Q|; return respond_to(#{o}, "foo"); |))
+ assert_equal 0, simplify(command(%Q|; return respond_to(#{o}, "bar"); |))
+ end
+ end
+
+ def test_that_respond_to_returns_verb_details_if_the_object_is_readable
+ o = nil
+ run_test_as('programmer') do
+ o = create(:nothing)
+ set(o, 'r', 1)
+ add_verb(o, ['player', 'x', 'foo'], ['none', 'none', 'none'])
+ add_verb(o, ['player', '', 'bar'], ['none', 'none', 'none'])
+ end
+ run_test_as('programmer') do
+ assert_equal [o, 'foo'], simplify(command(%Q|; return respond_to(#{o}, "foo"); |))
+ assert_equal 0, simplify(command(%Q|; return respond_to(#{o}, "bar"); |))
+ end
+ end
+
+ def test_that_respond_to_returns_true_if_the_verb_is_callable
+ o = nil
+ run_test_as('programmer') do
+ o = create(:nothing)
+ set(o, 'r', 0)
+ add_verb(o, ['player', 'x', 'foo'], ['none', 'none', 'none'])
+ end
+ run_test_as('programmer') do
+ assert_equal 1, simplify(command(%Q|; return respond_to(#{o}, "foo"); |))
+ end
+ end
+
+ def test_that_respond_to_returns_false_if_the_verb_is_not_callable
+ o = nil
+ run_test_as('programmer') do
+ o = create(:nothing)
+ set(o, 'r', 0)
+ add_verb(o, ['player', '', 'foo'], ['none', 'none', 'none'])
+ end
+ run_test_as('programmer') do
+ assert_equal 0, simplify(command(%Q|; return respond_to(#{o}, "foo"); |))
+ end
+ end
+
end

0 comments on commit 110c2ca

Please sign in to comment.