hastie 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. data/.autotest +9 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +10 -0
  5. data/LICENSE +21 -0
  6. data/README.textile +136 -0
  7. data/Rakefile +1 -0
  8. data/bin/hastie +64 -0
  9. data/hastie.gemspec +31 -0
  10. data/lib/hastie/config_file.rb +42 -0
  11. data/lib/hastie/config_generator.rb +37 -0
  12. data/lib/hastie/constants.rb +25 -0
  13. data/lib/hastie/report_generator.rb +118 -0
  14. data/lib/hastie/report_publisher.rb +162 -0
  15. data/lib/hastie/report_updater.rb +40 -0
  16. data/lib/hastie/report_watcher.rb +65 -0
  17. data/lib/hastie/server_generator.rb +47 -0
  18. data/lib/hastie/server_reader.rb +81 -0
  19. data/lib/hastie/templates/hastie_config.tt +6 -0
  20. data/lib/hastie/templates/report.markdown.tt +19 -0
  21. data/lib/hastie/templates/report.textile.tt +19 -0
  22. data/lib/hastie/templates/report_index.html.tt +8 -0
  23. data/lib/hastie/templates/server/.gitignore +1 -0
  24. data/lib/hastie/templates/server/_config.yml +25 -0
  25. data/lib/hastie/templates/server/_includes/.gitignore +0 -0
  26. data/lib/hastie/templates/server/_layouts/.gitignore +0 -0
  27. data/lib/hastie/templates/server/_plugins/.gitignore +0 -0
  28. data/lib/hastie/templates/server/_posts/.gitignore +0 -0
  29. data/lib/hastie/templates/server/_reports.yml +0 -0
  30. data/lib/hastie/templates/server/_server_config.yml +15 -0
  31. data/lib/hastie/templates/server/css/.gitignore +0 -0
  32. data/lib/hastie/templates/server/data/.gitignore +0 -0
  33. data/lib/hastie/templates/server/imgs/.gitignore +0 -0
  34. data/lib/hastie/templates/server/index.html +0 -0
  35. data/lib/hastie/templates/server/js/.gitignore +0 -0
  36. data/lib/hastie/version.rb +3 -0
  37. data/lib/hastie.rb +15 -0
  38. data/spec/config_generator_spec.rb +124 -0
  39. data/spec/fakefs_helper.rb +67 -0
  40. data/spec/fixtures/config.ru +29 -0
  41. data/spec/fixtures/hastie_config +2 -0
  42. data/spec/fixtures/report/2110-12-16-report.textile +19 -0
  43. data/spec/fixtures/report/_config.yml +9 -0
  44. data/spec/fixtures/report/data/report/.gitignore +0 -0
  45. data/spec/fixtures/report/imgs/report/.gitignore +0 -0
  46. data/spec/fixtures/report/js/.gitignore +0 -0
  47. data/spec/fixtures/report/report.yml +23 -0
  48. data/spec/fixtures/server/_config.yml +10 -0
  49. data/spec/fixtures/server/_posts/2011-11-11-jfv_mak_snp_analysis.textile +0 -0
  50. data/spec/fixtures/server/_reports.yml +1 -0
  51. data/spec/fixtures/server/css/style.css +126 -0
  52. data/spec/fixtures/server/data/jfv_mak_snp_analysis/.gitignore +0 -0
  53. data/spec/fixtures/server/imgs/favicon.ico +0 -0
  54. data/spec/fixtures/server/imgs/subset_images/.gitignore +0 -0
  55. data/spec/fixtures/server/js/.gitignore +0 -0
  56. data/spec/report_generator_spec.rb +168 -0
  57. data/spec/report_publisher_spec.rb +148 -0
  58. data/spec/report_updater_spec.rb +54 -0
  59. data/spec/report_watcher_spec.rb +99 -0
  60. data/spec/server_generator_spec.rb +68 -0
  61. data/spec/server_reader_spec.rb +120 -0
  62. data/spec/spec_helper.rb +52 -0
  63. metadata +234 -0
@@ -0,0 +1,10 @@
1
+ static:
2
+ - css
3
+ - js
4
+ - imgs
5
+ - _layouts
6
+ - _includes
7
+ - _plugins
8
+ - _config.yml
9
+
10
+ reports_dir: _posts
@@ -0,0 +1 @@
1
+ - jfv_mak_snp_analysis
@@ -0,0 +1,126 @@
1
+ a, a:visited, a:active {
2
+ color: #5d5d5d;
3
+ }
4
+
5
+ a:hover { color: #588EEA; }
6
+
7
+ li {
8
+ color: #404040;
9
+ }
10
+
11
+ h2 {
12
+ margin-bottom: 17px;
13
+ border-bottom: 1px solid #ddd;
14
+ -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
15
+ -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
16
+ box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
17
+ }
18
+
19
+ header {
20
+ height: 35px;
21
+ width: 100%;
22
+ display:block;
23
+ background-color: #222;
24
+ color: white;
25
+ }
26
+
27
+ .brand {
28
+ float: right;
29
+ display: block;
30
+ padding: 8px 20px 0;
31
+ color: white;
32
+ font-size: 20px;
33
+ font-weight: 200;
34
+ line-height: 1;
35
+ }
36
+
37
+ a.brand:hover, a.brand:visited {
38
+ color: white;
39
+ text-decoration: none;
40
+ }
41
+
42
+ span.header_accent {
43
+ font-size: 12px;
44
+ }
45
+
46
+ #toc {
47
+ float: right;
48
+ font-size: 10pt;
49
+ width: 200px;
50
+ padding: 10px 10px 10px 20px;
51
+ background: #FDF5D9;
52
+ border: solid 1px #FCEEC1;
53
+ margin: 5px 0 10px 0;
54
+ }
55
+
56
+ #about {
57
+ float:left;
58
+ width: 500px;
59
+ padding:0;
60
+ margin:0;
61
+ }
62
+
63
+ #about ul {
64
+ list-style: none;
65
+ }
66
+
67
+ .note {
68
+ background-color: #D1EED1;
69
+ padding: 10px;
70
+ border: 2px solid #BFE7BF;
71
+ margin-bottom: 1.5em;
72
+ }
73
+
74
+ .center {
75
+ text-align: center;
76
+ margin: auto;
77
+ }
78
+
79
+ img {
80
+ display:block;
81
+ margin: auto;
82
+ }
83
+
84
+ img.small {
85
+ width: 300px;
86
+ }
87
+
88
+ img.medium {
89
+ width: 600px;
90
+ }
91
+
92
+ img.large {
93
+ width: 900;
94
+ }
95
+
96
+ table.simple {
97
+ width: auto;
98
+ margin: auto;
99
+ }
100
+
101
+ table.grid {
102
+ width: auto;
103
+ margin: auto;
104
+ border: 1px solid #ddd;
105
+ }
106
+
107
+ table.grid th, table.grid td {
108
+ padding:0 5px 0 5px;
109
+ border-right: 1px solid #ddd;
110
+ border-top: 1px solid #ddd;
111
+ }
112
+
113
+ blockquote {
114
+ color: #777;
115
+ }
116
+
117
+ code {
118
+ background-color: #f5f5f5;
119
+ }
120
+
121
+ footer p {
122
+ text-align: center;
123
+ }
124
+
125
+ .collapsed { display: none; }
126
+
File without changes
@@ -0,0 +1,168 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/fakefs_helper')
3
+ require 'hastie/report_generator'
4
+
5
+ class ReportGeneratorChild < Hastie::ReportGenerator
6
+ no_tasks do
7
+ def config_file
8
+ FakeFsHelper::CONFIG_FILE
9
+ end
10
+ end
11
+ end
12
+
13
+ describe Hastie::ReportGenerator do
14
+
15
+ def read_file file
16
+ if File.exists? file
17
+ File.open(file, 'r').read
18
+ else
19
+ ""
20
+ end
21
+ end
22
+
23
+ before :each do
24
+ @config_file = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "hastie_config"))
25
+ @server_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "server"))
26
+ @output_dir = File.expand_path(File.join(File.dirname(__FILE__), "sandbox"))
27
+ @date = "2011-11-31"
28
+ @input = ["sandbox", "-o", @output_dir, "--config_file", @config_file, "--server_root", @server_dir, "--date", @date]
29
+ @expected_report_name = File.join(@output_dir, "#{@date}-#{File.basename(@output_dir)}")
30
+ end
31
+
32
+ after :each do
33
+ FileUtils.rm_r @output_dir if File.exists?(@output_dir)
34
+ end
35
+
36
+ it "should create scaffold files in output directory" do
37
+ content = capture(:stdout) do
38
+ lambda { Hastie::ReportGenerator.start @input }.should_not raise_error SystemExit
39
+ end
40
+
41
+ File.exists?(@expected_report_name + ".textile").should == true
42
+ File.directory?(File.join(@output_dir, "data")).should == true
43
+ File.directory?(File.join(@output_dir, "data", File.basename(@output_dir))).should == true
44
+ File.directory?(File.join(@output_dir, "_layouts")).should == true
45
+ File.directory?(File.join(@output_dir, "css")).should == true
46
+ File.directory?(File.join(@output_dir, "js")).should == true
47
+ File.directory?(File.join(@output_dir, "_plugins")).should == true
48
+ File.directory?(File.join(@output_dir, "_includes")).should == true
49
+ File.exists?(File.join(@output_dir, "_config.yml")).should == true
50
+ File.exists?(File.join(@output_dir, "report.yml")).should == true
51
+ File.exists?(File.join(@output_dir, "index.html")).should == true
52
+ end
53
+
54
+ it "should provide link in index file to html page" do
55
+ content = capture(:stdout) do
56
+ lambda { Hastie::ReportGenerator.start @input }.should_not raise_error SystemExit
57
+ end
58
+
59
+ index_file = File.join(@output_dir, "index.html")
60
+ File.exists?(index_file).should == true
61
+
62
+ index_content = read_file index_file
63
+
64
+ index_content.should match /url=#{File.basename(@expected_report_name)}.html/
65
+
66
+ end
67
+
68
+ ["markdown", "textile"].each do |format|
69
+ it "should have default content" do
70
+ @input << "--type" << format
71
+ content = capture(:stdout) do
72
+ lambda { Hastie::ReportGenerator.start @input }.should_not raise_error SystemExit
73
+ end
74
+
75
+ report_file = File.join(@expected_report_name + "." + format)
76
+ File.exists?(report_file).should == true
77
+ report_file_content = read_file report_file
78
+
79
+ report_file_content.should match /layout: report/
80
+ report_file_content.should match /title: Sandbox/
81
+ report_file_content.should match /data:/
82
+ report_file_content.should match /- data\/#{File.basename(@output_dir)}/
83
+ end
84
+ end
85
+
86
+ describe "input options" do
87
+ it "--type" do
88
+ @input << "--type" << "markdown"
89
+ content = capture(:stdout) do
90
+ lambda { Hastie::ReportGenerator.start @input }.should_not raise_error SystemExit
91
+ end
92
+
93
+ File.exists?(File.join(@expected_report_name + ".markdown")).should == true
94
+ end
95
+
96
+ it "--analyst" do
97
+ @input << "--analyst" << "mcm"
98
+ content = capture(:stdout) do
99
+ lambda { Hastie::ReportGenerator.start @input }.should_not raise_error SystemExit
100
+ end
101
+ report_file = File.join(@expected_report_name + ".textile")
102
+
103
+ File.exists?(report_file).should == true
104
+ report_file_content = read_file report_file
105
+
106
+ report_file_content.should match /analyst: mcm/
107
+ end
108
+
109
+ it "--pi" do
110
+ @input << "--pi" << "dad"
111
+ content = capture(:stdout) do
112
+ lambda { Hastie::ReportGenerator.start @input }.should_not raise_error SystemExit
113
+ end
114
+ report_file = File.join(@expected_report_name + ".textile")
115
+
116
+ File.exists?(report_file).should == true
117
+ report_file_content = read_file report_file
118
+
119
+ report_file_content.should match /pi: dad/
120
+ end
121
+
122
+ it "--researcher" do
123
+ @input << "--researcher" << "odd"
124
+ content = capture(:stdout) do
125
+ lambda { Hastie::ReportGenerator.start @input }.should_not raise_error SystemExit
126
+ end
127
+ report_file = File.join(@expected_report_name + ".textile")
128
+
129
+ File.exists?(report_file).should == true
130
+ report_file_content = read_file report_file
131
+
132
+ report_file_content.should match /researcher: odd/
133
+ end
134
+ end
135
+ end
136
+
137
+ describe Hastie::ReportGenerator, fakefs: true do
138
+ before :each do
139
+ # tested in server_reader_spec.rb
140
+ FakeFsHelper.stub_config_file
141
+ FakeFsHelper.stub_reports_file
142
+ FakeFsHelper.stub_server_config
143
+ end
144
+
145
+ describe "existing report present" do
146
+ it "should report existing report and exit" do
147
+ project = "existing_project"
148
+
149
+ FakeFsHelper.add_published_report project
150
+
151
+ content = capture(:stdout) do
152
+ lambda { ReportGeneratorChild.start [project] }.should raise_error SystemExit
153
+ end
154
+ content.should match /#{project} is already/
155
+ end
156
+ end
157
+
158
+ describe "create report framework" do
159
+ it "should create template report file" do
160
+ project = "fake_project_name"
161
+
162
+ # content = capture(:stdout) {ReportGeneratorChild.start [project] }
163
+ # puts content
164
+ # File.exists?(File.join(project, "#{project}.markdown")).should == true
165
+
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,148 @@
1
+ require 'grit'
2
+ require 'fileutils'
3
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
4
+ require File.expand_path(File.dirname(__FILE__) + '/fakefs_helper')
5
+ require 'hastie/report_publisher'
6
+
7
+ describe Hastie::ReportPublisher do
8
+
9
+ def read_file file
10
+ if File.exists? file
11
+ File.open(file, 'r').read
12
+ else
13
+ ""
14
+ end
15
+ end
16
+
17
+ before :each do
18
+ @config_file = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "hastie_config"))
19
+ @org_server_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "server"))
20
+ @org_report_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "report"))
21
+
22
+ @sandbox = File.expand_path(File.join(File.dirname(__FILE__), "sandbox"))
23
+
24
+ @server_dir = File.join(@sandbox, "server")
25
+ @report_dir = File.join(@sandbox, "report")
26
+
27
+ FileUtils.mkdir_p @sandbox
28
+
29
+ FileUtils.cp_r @org_server_dir, @server_dir
30
+ FileUtils.cp_r @org_report_dir, @report_dir
31
+
32
+ @report_name = File.basename(Dir.glob(File.join(@report_dir, "*.textile"))[0])
33
+ FileUtils.cd(@server_dir) do
34
+ system("git init .")
35
+ system("git add .")
36
+ system("git commit -m \"initial commit\"")
37
+ system("git branch server")
38
+ system("git checkout server")
39
+ end
40
+
41
+ @input = [@report_dir, "--config_file", @config_file, "--server_root", @server_dir]
42
+ end
43
+
44
+ after :each do
45
+ FileUtils.rm_r @sandbox if File.exists?(@sandbox)
46
+ end
47
+
48
+ it "should copy new report into reports_dir" do
49
+ content = capture(:stdout) do
50
+ lambda { Hastie::ReportPublisher.start @input }.should_not raise_error SystemExit
51
+ end
52
+
53
+ File.exists?(File.join(@server_dir, "_posts", @report_name)).should == true
54
+ File.exists?(File.join(@server_dir, "data", "report")).should == true
55
+ end
56
+
57
+ it "should add report to _reports.yml" do
58
+ content = capture(:stdout) do
59
+ lambda { Hastie::ReportPublisher.start @input }.should_not raise_error SystemExit
60
+ end
61
+ reports_content = read_file(File.join(@server_dir, "_reports.yml"))
62
+ reports_content.should match /#{File.basename(@report_dir)}/
63
+ end
64
+
65
+ it "should update git repository with new commit" do
66
+ content = capture(:stdout) do
67
+ lambda { Hastie::ReportPublisher.start @input }.should_not raise_error SystemExit
68
+ end
69
+
70
+ commits = Grit::Repo.new(@server_dir).commits('server',1)
71
+ commits[0].message.should match /update with report: report/
72
+ end
73
+
74
+ end
75
+
76
+ describe Hastie::ReportPublisher, fakefs: true do
77
+ before :each do
78
+ # tested in server_reader_spec.rb
79
+ FakeFsHelper.stub_config_file
80
+ FakeFsHelper.stub_reports_file
81
+ FakeFsHelper.stub_server_config
82
+
83
+ @report_dir = "/tmp/test_report"
84
+ FileUtils.mkdir_p @report_dir
85
+ File.exists?(@report_dir).should == true
86
+ end
87
+
88
+ it "should error if input directory is not a report" do
89
+ input = [@report_dir, "--config_file", FakeFsHelper::CONFIG_FILE, "--server_root", FakeFsHelper::SERVER_DIR]
90
+
91
+ content = capture(:stdout) do
92
+ lambda { Hastie::ReportPublisher.start input }.should raise_error SystemExit
93
+ end
94
+ content.should match /[Cc]annot .* report.yml/
95
+ end
96
+
97
+ it "should error if reports_dir not in server config" do
98
+ FileUtils.touch File.join(@report_dir, "report.yml")
99
+ input = [@report_dir, "--config_file", FakeFsHelper::CONFIG_FILE, "--server_root", FakeFsHelper::SERVER_DIR]
100
+
101
+ content = capture(:stdout) do
102
+ lambda { Hastie::ReportPublisher.start input }.should raise_error SystemExit
103
+ end
104
+ content.should match /[Mm]issing reports_dir/
105
+ end
106
+
107
+ it "should error if report_file not in local config" do
108
+ FileUtils.touch File.join(@report_dir, "report.yml")
109
+ input = [@report_dir, "--config_file", FakeFsHelper::CONFIG_FILE, "--server_root", FakeFsHelper::SERVER_DIR]
110
+
111
+ content = capture(:stdout) do
112
+ lambda { Hastie::ReportPublisher.start input }.should raise_error SystemExit
113
+ end
114
+ content.should match /[Mm]issing report_file/
115
+ end
116
+
117
+ it "should error if report_id not in local config" do
118
+ FileUtils.touch File.join(@report_dir, "report.yml")
119
+ input = [@report_dir, "--config_file", FakeFsHelper::CONFIG_FILE, "--server_root", FakeFsHelper::SERVER_DIR]
120
+
121
+ content = capture(:stdout) do
122
+ lambda { Hastie::ReportPublisher.start input }.should raise_error SystemExit
123
+ end
124
+ content.should match /[Mm]issing report_id/
125
+ end
126
+
127
+ it "should copy report if all required configs are present" do
128
+ report_file = File.join(@report_dir, "report.yml")
129
+ FileUtils.touch report_file
130
+ File.open(report_file, 'w') do |f|
131
+ f.puts "report_id: report"
132
+ f.puts "report_file: report.textile"
133
+ end
134
+
135
+ FileUtils.touch File.join(@report_dir, "report.textile")
136
+
137
+ FakeFsHelper.add_reports_dir
138
+
139
+ input = [@report_dir, "--config_file", FakeFsHelper::CONFIG_FILE,
140
+ "--server_root", FakeFsHelper::SERVER_DIR]
141
+
142
+ content = capture(:stdout) do
143
+ lambda { Hastie::ReportPublisher.start input }.should_not raise_error SystemExit
144
+ end
145
+
146
+ File.exist?(File.join(FakeFsHelper::SERVER_DIR, "_posts", "report.textile")).should == true
147
+ end
148
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/fakefs_helper')
3
+ require 'hastie/report_updater'
4
+
5
+ describe Hastie::ReportUpdater do
6
+ def read_file file
7
+ if File.exists? file
8
+ File.open(file, 'r').read
9
+ else
10
+ ""
11
+ end
12
+ end
13
+
14
+ before :each do
15
+ @config_file = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "hastie_config"))
16
+ @org_server_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "server"))
17
+ @org_report_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "report"))
18
+
19
+ @sandbox = File.expand_path(File.join(File.dirname(__FILE__), "sandbox"))
20
+
21
+ @server_dir = File.join(@sandbox, "server")
22
+ @report_dir = File.join(@sandbox, "report")
23
+
24
+ FileUtils.mkdir_p @sandbox
25
+
26
+ FileUtils.cp_r @org_server_dir, @server_dir
27
+ FileUtils.cp_r @org_report_dir, @report_dir
28
+
29
+ @report_name = File.basename(Dir.glob(File.join(@report_dir, "*.textile"))[0])
30
+
31
+ # Grit::Repo.init(@server_dir)
32
+
33
+ @input = [@report_dir, "--config_file", @config_file, "--server_root", @server_dir]
34
+ end
35
+
36
+ after :each do
37
+ FileUtils.rm_r @sandbox if File.exists?(@sandbox)
38
+ end
39
+
40
+ it "should copy modified files to report dir" do
41
+
42
+ File.open(File.join(@server_dir, "css", "style.css"), 'w') do |file|
43
+ file.puts "brick: house"
44
+ end
45
+
46
+ content = capture(:stdout) do
47
+ lambda { Hastie::ReportUpdater.start @input }.should_not raise_error SystemExit
48
+ end
49
+
50
+ css_content = read_file(File.join(@report_dir, "css", "style.css"))
51
+ css_content.should match /brick: house/
52
+
53
+ end
54
+ end
@@ -0,0 +1,99 @@
1
+ require 'fileutils'
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require File.expand_path(File.dirname(__FILE__) + '/fakefs_helper')
4
+ require 'hastie/report_watcher'
5
+
6
+ describe Hastie::ReportWatcher do
7
+
8
+ def read_file file
9
+ if File.exists? file
10
+ File.open(file, 'r').read
11
+ else
12
+ ""
13
+ end
14
+ end
15
+
16
+ before :each do
17
+ @config_file = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "hastie_config"))
18
+ @config_ru_file = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "config.ru"))
19
+ @org_server_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "server"))
20
+ @org_report_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "report"))
21
+
22
+ @sandbox = File.expand_path(File.join(File.dirname(__FILE__), "sandbox"))
23
+
24
+ @report_dir = File.join(@sandbox, "report")
25
+
26
+ FileUtils.mkdir_p @sandbox
27
+
28
+ FileUtils.cp_r @org_report_dir, @report_dir
29
+
30
+ @report_name = File.basename(Dir.glob(File.join(@report_dir, "*.textile"))[0])
31
+
32
+ @input = [@report_dir]
33
+
34
+ end
35
+
36
+ after :each do
37
+ FileUtils.rm_r @sandbox if File.exists?(@sandbox)
38
+ end
39
+
40
+ it "should not error if in a report dir" do
41
+ content = ""
42
+ pid = fork do
43
+ content = capture(:stderr) do
44
+ lambda { Hastie::ReportWatcher.start @input }.should_not raise_error SystemExit
45
+ end
46
+ end
47
+
48
+ sleep 5
49
+
50
+ Process.kill 'INT', pid
51
+ Process.wait pid
52
+ puts content
53
+ end
54
+
55
+ it "should raise errror if not in a report dir" do
56
+ input = [@sandbox]
57
+ content = capture(:stdout) do
58
+ lambda { Hastie::ReportWatcher.start input }.should raise_error SystemExit
59
+ end
60
+ end
61
+
62
+ it "should start sinatra if config.ru file is present" do
63
+ FileUtils.cp_r @config_ru_file, @report_dir
64
+
65
+ # Hastie::ReportWatcher.start @input
66
+
67
+ content = ""
68
+ pid = fork do
69
+ content = capture(:stderr) do
70
+ lambda { Hastie::ReportWatcher.start @input }#.should_not raise_error SystemExit
71
+ end
72
+ end
73
+
74
+ sleep 5
75
+
76
+ Process.kill 'INT', pid
77
+ Process.wait pid
78
+ puts "SINATRA:"
79
+ puts content
80
+ end
81
+
82
+ end
83
+
84
+ describe Hastie::ReportWatcher, fakefs: true do
85
+ before :each do
86
+ # tested in server_reader_spec.rb
87
+ FakeFsHelper.stub_config_file
88
+ FakeFsHelper.stub_reports_file
89
+ FakeFsHelper.stub_server_config
90
+
91
+ @report_dir = "/tmp/test_report"
92
+ FileUtils.mkdir_p @report_dir
93
+ File.exists?(@report_dir).should == true
94
+ end
95
+
96
+ it "should be happy" do
97
+
98
+ end
99
+ end
@@ -0,0 +1,68 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'hastie/server_generator'
3
+
4
+
5
+ describe Hastie::ServerGenerator do
6
+
7
+ def read_file file
8
+ if File.exists? file
9
+ File.open(file, 'r').read
10
+ else
11
+ ""
12
+ end
13
+ end
14
+
15
+ before :each do
16
+ @template_server_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "server"))
17
+ @output_dir = File.expand_path(File.join(File.dirname(__FILE__), "sandbox"))
18
+ @input = [@output_dir]
19
+ end
20
+
21
+ after :each do
22
+ FileUtils.rm_r @output_dir if File.exists?(@output_dir)
23
+ end
24
+
25
+ it "should create server scaffold in output directory" do
26
+ content = capture(:stdout) do
27
+ lambda { Hastie::ServerGenerator.start @input }.should_not raise_error SystemExit
28
+ end
29
+
30
+ template_files = Dir.glob(File.join(@template_server_dir, "*"))
31
+
32
+ template_files.each do |file|
33
+ base_file = file.gsub(@template_server_dir, @output_dir)
34
+ File.exists?(base_file).should == true
35
+ end
36
+ end
37
+
38
+ it "should put static section in _config.yml" do
39
+ content = capture(:stdout) do
40
+ lambda { Hastie::ServerGenerator.start @input }.should_not raise_error SystemExit
41
+ end
42
+
43
+ config_file = File.join(@output_dir, "_config.yml")
44
+ File.exists?(config_file).should == true
45
+ config_content = read_file config_file
46
+ config_content.should match /static:/
47
+ end
48
+
49
+ it "should put reports_dir section in _config.yml" do
50
+ content = capture(:stdout) do
51
+ lambda { Hastie::ServerGenerator.start @input }.should_not raise_error SystemExit
52
+ end
53
+
54
+ config_file = File.join(@output_dir, "_config.yml")
55
+ File.exists?(config_file).should == true
56
+ config_content = read_file config_file
57
+ config_content.should match /reports_dir:/
58
+ end
59
+
60
+ it "should be a git repository" do
61
+ content = capture(:stdout) do
62
+ lambda { Hastie::ServerGenerator.start @input }.should_not raise_error SystemExit
63
+ end
64
+ git_proof = File.join(@output_dir, ".git")
65
+ File.directory?(git_proof).should == true
66
+ end
67
+ end
68
+