Debian Codegraph @

vendor/behaviors/test/behaviors_test.rb

raw
1 require 'test/unit'
2 require File.expand_path(File.dirname(__FILE__)) + '/../lib/behaviors'
3 require 'stringio'
4
5 loading_developer_test_class_stdout = StringIO.new
6 saved_stdout = $stdout.dup
7 $stdout = loading_developer_test_class_stdout
8
9 class DeveloperTest
10 extend Behaviors
11 attr_accessor :flunk_msg, :tested_code
12
13 should "test their code" do
14 @tested_code = true
15 end
16 should "go to meetings"
17 end
18
19 $stdout = saved_stdout
20 loading_developer_test_class_stdout.rewind
21 $loading_developer_test_class_output = loading_developer_test_class_stdout.read
22
23 class BehaviorsTest < Test::Unit::TestCase
24
25
26 def setup
27 @target = DeveloperTest.new
28 assert_nil @target.tested_code, "block called too early"
29 end
30
31 #
32 # TESTS
33 #
34 def test_should_called_with_a_block_defines_a_test
35 assert @target.methods.include?("test_should_test their code"), "Missing test method"
36
37 @target.send("test_should_test their code")
38
39 assert @target.tested_code, "block not called"
40 end
41
42 def test_should_called_without_a_block_does_not_create_a_test_method
43 assert [email protected]?("test_should_go to meetings"), "Should not have method"
44 end
45
46 def test_should_called_without_a_block_will_give_unimplemented_output_when_class_loads
47 unimplemented_output = "UNIMPLEMENTED CASE: Developer should go to meetings"
48 assert_match(/#{unimplemented_output}/, $loading_developer_test_class_output)
49 end
50 end