Debian Codegraph @

vendor/behaviors/test/behaviors_tasks_test.rb

raw
1 require 'test/unit'
2 require 'fileutils'
3
4 class BehaviorsTasksTest < Test::Unit::TestCase
5 include FileUtils
6
7 def setup
8 @here = File.expand_path(File.dirname(__FILE__))
9 @base_cmd = RUBY_PLATFORM[/mswin/] ? 'rake.cmd ' : 'rake '
10 end
11
12 #
13 # HELPERS
14 #
15 def run_behaviors_task
16 run_cmd "behaviors"
17 end
18
19 def run_behaviors_html_task
20 run_cmd "behaviors_html"
21 end
22
23 def run_cmd(cmd)
24 cd "#{@here}/tasks_test" do
25 @report = %x[ #{@base_cmd} #{cmd} ]
26 end
27 end
28
29 def see_html_task_output_message
30 @html_output_filename = "#{@here}/tasks_test/behaviors_doc/behaviors.html"
31 assert_match(/Wrote #{@html_output_filename}/, @report)
32 end
33
34 def see_that_html_report_file_exits
35 assert File.exists?(@html_output_filename), "html output file should exist"
36 end
37
38 def html_report_file_should_contain(user_behaviors)
39 file_contents = File.read(@html_output_filename)
40 user_behaviors.each do |line|
41 assert_match(/#{line}/, file_contents)
42 end
43 rm_rf File.dirname(@html_output_filename)
44 end
45
46 #
47 # TESTS
48 #
49 def test_that_behaviors_tasks_should_list_behavioral_definitions_for_the_classes_under_test
50 run_behaviors_task
51 user_behaviors = [
52 "User should:",
53 " - be able set user name and age during construction",
54 " - be able to get user name and age",
55 " - be able to ask if a user is an adult"
56 ]
57 assert_match(/#{user_behaviors.join("\n")}/, @report)
58 end
59
60 def test_that_behaviors_tasks_should_list_behavioral_definitions_for_the_classes_under_test_in_html_output
61 run_behaviors_html_task
62 see_html_task_output_message
63 see_that_html_report_file_exits
64 user_behaviors = [
65 "User should:",
66 "be able set user name and age during construction",
67 "be able to get user name and age",
68 "be able to ask if a user is an adult"
69 ]
70 html_report_file_should_contain user_behaviors
71 end
72
73 end