blob: 9382e0737cc6e4305670bb1a2398518e73ee97e8 (
plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
require 'test/unit'
require 'fileutils'
class BehaviorsTasksTest < Test::Unit::TestCase
include FileUtils
def setup
@here = File.expand_path(File.dirname(__FILE__))
@base_cmd = RUBY_PLATFORM[/mswin/] ? 'rake.cmd ' : 'rake '
end
#
# HELPERS
#
def run_behaviors_task
run_cmd "behaviors"
end
def run_behaviors_html_task
run_cmd "behaviors_html"
end
def run_cmd(cmd)
cd "#{@here}/tasks_test" do
@report = %x[ #{@base_cmd} #{cmd} ]
end
end
def see_html_task_output_message
@html_output_filename = "#{@here}/tasks_test/behaviors_doc/behaviors.html"
assert_match(/Wrote #{@html_output_filename}/, @report)
end
def see_that_html_report_file_exits
assert File.exists?(@html_output_filename), "html output file should exist"
end
def html_report_file_should_contain(user_behaviors)
file_contents = File.read(@html_output_filename)
user_behaviors.each do |line|
assert_match(/#{line}/, file_contents)
end
rm_rf File.dirname(@html_output_filename)
end
#
# TESTS
#
def test_that_behaviors_tasks_should_list_behavioral_definitions_for_the_classes_under_test
run_behaviors_task
user_behaviors = [
"User should:",
" - be able set user name and age during construction",
" - be able to get user name and age",
" - be able to ask if a user is an adult"
]
assert_match(/#{user_behaviors.join("\n")}/, @report)
end
def test_that_behaviors_tasks_should_list_behavioral_definitions_for_the_classes_under_test_in_html_output
run_behaviors_html_task
see_html_task_output_message
see_that_html_report_file_exits
user_behaviors = [
"User should:",
"be able set user name and age during construction",
"be able to get user name and age",
"be able to ask if a user is an adult"
]
html_report_file_should_contain user_behaviors
end
end
|