ascii_binder 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +16 -0
  3. data/ascii_binder.gemspec +5 -3
  4. data/bin/asciibinder +53 -44
  5. data/features/command_help.feature +8 -0
  6. data/features/command_version.feature +8 -0
  7. data/features/repo_build.feature +34 -0
  8. data/features/repo_clean.feature +20 -0
  9. data/features/repo_clone.feature +22 -0
  10. data/features/repo_create.feature +13 -0
  11. data/features/repo_package.feature +15 -0
  12. data/features/step_definitions/steps.rb +182 -0
  13. data/features/support/_clone_distro_map.yml +14 -0
  14. data/features/support/_invalid_distro_map.yml +14 -0
  15. data/features/support/env.rb +468 -0
  16. data/features/support/test_distro/.gitignore +9 -0
  17. data/features/support/test_distro/_distro_map.yml +29 -0
  18. data/features/support/test_distro/_images/asciibinder-logo-horizontal.png +0 -0
  19. data/features/support/test_distro/_images/asciibinder_web_logo.svg +125 -0
  20. data/features/support/test_distro/_images/book_pages_bg.jpg +0 -0
  21. data/features/support/test_distro/_images/favicon.ico +0 -0
  22. data/features/support/test_distro/_images/favicon32x32.png +0 -0
  23. data/features/support/test_distro/_javascripts/.gitkeep +0 -0
  24. data/features/support/test_distro/_stylesheets/asciibinder.css +568 -0
  25. data/features/support/test_distro/_templates/_css.html.erb +3 -0
  26. data/features/support/test_distro/_templates/_nav.html.erb +31 -0
  27. data/features/support/test_distro/_templates/page.html.erb +92 -0
  28. data/features/support/test_distro/_topic_map.yml +36 -0
  29. data/features/support/test_distro/index-main.html +10 -0
  30. data/features/support/test_distro/index-test.html +10 -0
  31. data/features/support/test_distro/main_only_topic_group/index.adoc +17 -0
  32. data/features/support/test_distro/test_only_topic_group/index.adoc +17 -0
  33. data/features/support/test_distro/welcome/index.adoc +17 -0
  34. data/features/support/test_distro/welcome/subtopics/index.adoc +17 -0
  35. data/features/support/test_distro/welcome/subtopics/main_only_topic.adoc +17 -0
  36. data/features/support/test_distro/welcome/subtopics/test_only_topic.adoc +17 -0
  37. data/features/support/test_distro/welcome/subtopics/wildcard_all.adoc +17 -0
  38. data/lib/ascii_binder.rb +4 -2
  39. data/lib/ascii_binder/distro.rb +111 -0
  40. data/lib/ascii_binder/distro_branch.rb +93 -0
  41. data/lib/ascii_binder/distro_map.rb +67 -0
  42. data/lib/ascii_binder/engine.rb +581 -0
  43. data/lib/ascii_binder/helpers.rb +42 -856
  44. data/lib/ascii_binder/site.rb +52 -0
  45. data/lib/ascii_binder/site_info.rb +22 -0
  46. data/lib/ascii_binder/site_map.rb +24 -0
  47. data/lib/ascii_binder/topic_entity.rb +255 -0
  48. data/lib/ascii_binder/topic_map.rb +61 -0
  49. data/lib/ascii_binder/version.rb +1 -1
  50. data/templates/_templates/page.html.erb +1 -1
  51. metadata +118 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81f89642e2ac1db79b24ef73783da62f0addea2b
4
- data.tar.gz: 4a0cd477ba230e682f67b80fc24170787ba360ba
3
+ metadata.gz: 6157f325397b76b4332f318aba16ada7f930093c
4
+ data.tar.gz: c0b13db6c9254db35c9d2b64a56755a88f929499
5
5
  SHA512:
6
- metadata.gz: ef945848b9d34f7f3617380978be87d880e0e0d26089826433e4926aabd24dacd2a90fb0349bdb81d3f24739f47cb365741337bccd69cc5e13b0df1b171b25ec
7
- data.tar.gz: 58716e1317b74cf487a423400af981715f82662970d6df8194dfb3ffe81679f7713998237d2d1e44dc0688c49803424c46406ea7a948fe5a4d25d8e3669e0d52
6
+ metadata.gz: 5709a933e576d0d1f7e4beb5a26ae35d54a70798b2bce6630382925387352fbd81b2fdb2ba084f54255e81f6a31bf2ce7bbf0a22f3da7f294489f73fa21c6c76
7
+ data.tar.gz: 7660ad1cf7c7d8df27a7a1c9da6dae59a87f6d130b09d9085c9a3e334d5f89a2ddf26b5831d1c297c361f03beda0c624f27db908a1630849b14ae5af82846c00
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3.3
6
+ after_install: gem list
7
+ script:
8
+ - git config --global user.name "Travis Test"
9
+ - git config --global user.email "travis@mailinator.com"
10
+ - bundle exec cucumber
11
+ notifications:
12
+ irc:
13
+ channels:
14
+ - "irc.freenode.org#asciibinder"
15
+ on_success: change
16
+ on_failure: always
@@ -19,10 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "cucumber", "~> 2.3.3"
23
+ spec.add_development_dependency "diff_dirs", "~> 0.1.2"
22
24
  spec.add_dependency "rake", "~> 10.0"
23
25
 
24
- spec.add_dependency 'asciidoctor', '~> 1.5.4'
25
- spec.add_dependency 'asciidoctor-diagram'
26
+ spec.add_dependency 'asciidoctor', '~> 1.5.6'
27
+ spec.add_dependency 'asciidoctor-diagram', '~> 1.5.5'
26
28
  spec.add_dependency 'git'
27
29
  spec.add_dependency 'guard'
28
30
  spec.add_dependency 'guard-shell'
@@ -32,6 +34,6 @@ Gem::Specification.new do |spec|
32
34
  spec.add_dependency 'pandoc-ruby'
33
35
  spec.add_dependency 'sitemap_generator', '~> 5.1.0'
34
36
  spec.add_dependency 'trollop', '~> 2.1.2'
35
- spec.add_dependency 'yajl-ruby'
37
+ spec.add_dependency 'yajl-ruby', '~> 1.3.0'
36
38
  spec.add_dependency 'tilt'
37
39
  end
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'ascii_binder/engine'
3
4
  require 'ascii_binder/helpers'
4
5
  require 'ascii_binder/version'
5
6
  require 'pathname'
6
7
  require 'trollop'
7
8
 
9
+ include AsciiBinder::Engine
8
10
  include AsciiBinder::Helpers
9
11
 
10
12
  def call_generate(branch_group, distro, page)
@@ -19,40 +21,47 @@ def call_generate(branch_group, distro, page)
19
21
  end
20
22
  end
21
23
 
22
- def repo_check(repo_dir)
24
+ def repo_check(docs_basedir)
23
25
  missing_files = false
24
26
  # These must all be present
25
- ['.git','_distro_map.yml','_templates'].each do |file|
26
- unless File.exist?(File.join(repo_dir, file))
27
+ ['_distro_map.yml','_templates'].each do |file|
28
+ unless File.exist?(File.join(docs_basedir, file))
27
29
  missing_files = true
28
30
  end
29
31
  end
30
32
  # Either of these must be present
31
- unless File.exist?(File.join(repo_dir, '_build_cfg.yml')) or File.exist?(File.join(repo_dir, '_topic_map.yml'))
33
+ unless File.exist?(File.join(docs_basedir, '_build_cfg.yml')) or File.exist?(File.join(docs_basedir, '_topic_map.yml'))
32
34
  missing_files = true
33
35
  end
34
- if missing_files
35
- Trollop::die "The specified repo directory '#{repo_dir}' does not appear to be an AsciiBinder repo."
36
+ if missing_files or not in_git_repo(docs_basedir)
37
+ Trollop::die "The specified docs base directory '#{docs_basedir}' does not appear to be part of an AsciiBinder-compatible repo."
36
38
  end
37
39
  end
38
40
 
41
+ def in_git_repo(dir)
42
+ git_path = File.join(dir,'.git')
43
+ return true if File.exist?(git_path) and File.directory?(git_path)
44
+ return false if dir == '/'
45
+ in_git_repo(File.expand_path('..',dir))
46
+ end
47
+
39
48
  SUB_COMMANDS = %w{help version build watch package clean create clone}
40
49
  Trollop::options do
41
50
  version AsciiBinder::VERSION
42
51
  banner <<-EOF
43
52
  Usage:
44
- #$0 <command> <repo_dir>
53
+ #$0 <command> <docs_basedir>
45
54
 
46
55
  Commands:
47
56
  build (default action)
48
- Builds the HTML docs in the indicated repo dir
57
+ Builds the HTML docs within the indicated docs base directory
49
58
  create
50
59
  Generates a new AsciiBinder repo at the indicated dir
51
60
  clone
52
61
  Clones an existing AsciiBinder repo to the local filesystem
53
62
  watch
54
63
  Starts Guard, which automatically regenerates changed HTML
55
- files on the working branch in the repo dir
64
+ files on the working branch in the docs base directory dir
56
65
  package
57
66
  Builds and packages the static HTML for all of the sites
58
67
  defined in the _distro_config.yml file
@@ -66,13 +75,13 @@ EOF
66
75
  end
67
76
 
68
77
  cmd = ARGV.shift
69
- repo_dir = nil
78
+ docs_basedir = nil
70
79
 
71
80
  if cmd.nil?
72
81
  cmd = "build"
73
82
  elsif !SUB_COMMANDS.include?(cmd)
74
83
  if ARGV.empty?
75
- repo_dir = Pathname.new(cmd)
84
+ docs_basedir = Pathname.new(cmd)
76
85
  cmd = "build"
77
86
  else
78
87
  Trollop::die "'#{cmd}' is not a valid asciibinder subcommand. Legal values are '#{SUB_COMMANDS.join('\', \'')}'."
@@ -84,13 +93,13 @@ cmd_opts = case cmd
84
93
  Trollop::options do
85
94
  banner <<-EOF
86
95
  Usage:
87
- #$0 build <options> <repo_dir>
96
+ #$0 build <options> <docs_basedir>
88
97
 
89
98
  Description:
90
99
  This is the default behavior for the asciibinder utility. When run,
91
100
  AsciiBinder reads the _distro_config.yml file out of the working
92
- branch of the indicated repo directory and based on that, proceeds to
93
- build the working branch version of the documentation for each distro.
101
+ branch of the indicated docs base directory and based on that, proceeds
102
+ to build the working branch version of the documentation for each distro.
94
103
 
95
104
  If you use the --all_branches flag, AsciiBinder behaves as described
96
105
  above, and then once the working branch version is built, AsciiBinder
@@ -128,7 +137,7 @@ EOF
128
137
  Trollop::options do
129
138
  banner <<-EOF
130
139
  Usage:
131
- #$0 create <new_repo_dir>
140
+ #$0 create <new_docs_basedir>
132
141
 
133
142
  Description:
134
143
  Creates a new, bare AsciiBinder repo in the specified directory.
@@ -155,11 +164,11 @@ EOF
155
164
  Trollop::options do
156
165
  banner <<-EOF
157
166
  Usage:
158
- #$0 watch <repo_dir>
167
+ #$0 watch <docs_basedir>
159
168
 
160
169
  Description:
161
170
  In watch mode, AsciiBinder starts a Guard process in the foreground.
162
- This process watches the repo_dir for changes to the AsciiDoc (.adoc)
171
+ This process watches the docs_basedir for changes to the AsciiDoc (.adoc)
163
172
  files. When a change occurs, AsciiBinder regenerates the specific
164
173
  HTML output of the file that was changed, for the working branch only.
165
174
 
@@ -181,7 +190,7 @@ EOF
181
190
  Trollop::options do
182
191
  banner <<-EOF
183
192
  Usage:
184
- #$0 package <options> <repo_dir>
193
+ #$0 package <options> <docs_basedir>
185
194
 
186
195
  Description:
187
196
  Publish mode is similar to 'build' mode, but once all of the branches' of
@@ -201,26 +210,26 @@ EOF
201
210
  exit 0
202
211
  end
203
212
 
204
- if (not repo_dir.nil? and not ARGV.empty?) or (repo_dir.nil? and ARGV.length > 1)
213
+ if (not docs_basedir.nil? and not ARGV.empty?) or (docs_basedir.nil? and ARGV.length > 1)
205
214
  Trollop::die "Too many arguments provided to ascii_binder: '#{ARGV.join(' ')}'. Exiting."
206
- elsif repo_dir.nil?
215
+ elsif docs_basedir.nil?
207
216
  if ARGV.length == 1
208
217
  if cmd == 'clone'
209
218
  cmd_opts[:giturl] = ARGV.shift
210
219
  if cmd_opts[:dir] != ''
211
- repo_dir = Pathname.new(cmd_opts[:dir])
220
+ docs_basedir = Pathname.new(cmd_opts[:dir])
212
221
  else
213
- repo_dir = Pathname.new(File.join(Pathname.pwd, cmd_opts[:giturl].split('/')[-1].split('.')[0]))
222
+ docs_basedir = Pathname.new(File.join(Pathname.pwd, cmd_opts[:giturl].split('/')[-1].split('.')[0]))
214
223
  end
215
224
  else
216
- repo_dir = Pathname.new(ARGV.shift)
225
+ docs_basedir = Pathname.new(ARGV.shift)
217
226
  end
218
227
  else
219
228
  if cmd != 'create'
220
229
  if cmd == 'clone'
221
230
  Trollop::die "Provide a git URL to clone from."
222
231
  else
223
- repo_dir = Pathname.pwd
232
+ docs_basedir = Pathname.pwd
224
233
  end
225
234
  else
226
235
  Trollop::die "Specify a name for the new repo directory."
@@ -228,39 +237,39 @@ elsif repo_dir.nil?
228
237
  end
229
238
  end
230
239
 
231
- # Validate the repo_dir path
240
+ # Validate the docs_basedir path
232
241
  if cmd == 'create' or cmd == 'clone'
233
- if repo_dir.exist?
234
- Trollop::die "The specified new repo directory '#{repo_dir}' already exists."
242
+ if docs_basedir.exist?
243
+ Trollop::die "The specified new repo directory '#{docs_basedir}' already exists."
235
244
  end
236
245
  else
237
- if !repo_dir.exist?
238
- Trollop::die "The specified repo directory '#{repo_dir}' does not exist."
239
- elsif !repo_dir.directory?
240
- Trollop::die "The specified repo directory path '#{repo_dir}' is not a directory."
241
- elsif !repo_dir.readable?
242
- Trollop::die "The specified repo directory '#{repo_dir}' is not readable."
243
- elsif !repo_dir.writable?
244
- Trollop::die "The specified repo directory '#{repo_dir}' cannot be written to."
246
+ if !docs_basedir.exist?
247
+ Trollop::die "The specified docs directory '#{docs_basedir}' does not exist."
248
+ elsif !docs_basedir.directory?
249
+ Trollop::die "The specified docs directory path '#{docs_basedir}' is not a directory."
250
+ elsif !docs_basedir.readable?
251
+ Trollop::die "The specified docs directory '#{docs_basedir}' is not readable."
252
+ elsif !docs_basedir.writable?
253
+ Trollop::die "The specified docs directory '#{docs_basedir}' cannot be written to."
245
254
  else
246
- repo_check(repo_dir)
255
+ repo_check(docs_basedir)
247
256
  end
248
257
  end
249
258
 
250
259
  # Set the repo root
251
- set_source_dir(File.expand_path(repo_dir))
260
+ set_docs_root_dir(File.expand_path(docs_basedir))
252
261
 
253
262
  # Cloning? Time to try it.
254
263
  if cmd == 'clone'
255
- puts "Cloning #{cmd_opts[:giturl]} to #{repo_dir}"
256
- system("git clone #{cmd_opts[:giturl]} #{repo_dir}")
264
+ puts "Cloning #{cmd_opts[:giturl]} to #{docs_basedir}"
265
+ system("git clone #{cmd_opts[:giturl]} #{docs_basedir}")
257
266
  Trollop::die "The git URL could not be cloned: #{err}" if $?.exitstatus != 0
258
267
 
259
268
  # Make sure this cloned repo is legit.
260
- repo_check(repo_dir)
269
+ repo_check(docs_basedir)
261
270
 
262
271
  if cmd_opts[:branches]
263
- Dir.chdir(repo_dir)
272
+ Dir.chdir(docs_basedir)
264
273
  puts "Tracking branch setup:"
265
274
  distro_branches.each do |doc_branch|
266
275
  next if doc_branch == 'master'
@@ -279,7 +288,7 @@ end
279
288
  # Change to the repo dir. This is necessary in order for
280
289
  # AsciiDoctor to work properly.
281
290
  if cmd != 'create'
282
- Dir.chdir source_dir
291
+ Dir.chdir docs_basedir
283
292
  end
284
293
 
285
294
  # Do the things with the stuff
@@ -304,10 +313,10 @@ when "watch"
304
313
  end
305
314
  when "clean"
306
315
  clean_up
307
- puts "Cleaned up #{repo_dir}."
316
+ puts "Cleaned up #{docs_basedir}."
308
317
  when "create"
309
318
  create_new_repo
310
- puts "Created new repo in #{repo_dir}."
319
+ puts "Created new repo in #{docs_basedir}."
311
320
  end
312
321
 
313
322
  exit
@@ -0,0 +1,8 @@
1
+ Feature: asciibinder help
2
+
3
+ Displays help information for the asciibinder utility
4
+
5
+ Scenario: A user wants to see help information for the utility
6
+ Given a nonexistant repo directory
7
+ When the user runs `asciibinder help` on that repo directory
8
+ Then the program displays help information
@@ -0,0 +1,8 @@
1
+ Feature: asciibinder version
2
+
3
+ This command returns the version of the installed utility
4
+
5
+ Scenario: A user wants to display the version of the asciibinder utility
6
+ Given a nonexistant repo directory
7
+ When the user runs `asciibinder version` on that repo directory
8
+ Then the program prints the current version of the utility
@@ -0,0 +1,34 @@
1
+ Feature: asciibinder build
2
+
3
+ Causes the utility to process one or more distro/branch combinations,
4
+ transforming AsciiDoc files to a unified docs set in HTML
5
+
6
+ Scenario: A user wants to do any build in a repo with an invalid distro map
7
+ Given an invalid AsciiBinder docs repo due to a malformed distro map
8
+ When the user runs `asciibinder build` on that repo directory
9
+ Then the program exits with a warning
10
+
11
+ Scenario: A user wants to build all distros against the current repo branch
12
+ Given a valid AsciiBinder docs repo with multiple distros
13
+ When the user runs `asciibinder build` on that repo directory
14
+ Then the program generates preview content for all distros in the current branch
15
+
16
+ Scenario: A user wants to build a single distro against the current repo branch
17
+ Given a valid AsciiBinder docs repo with multiple distros
18
+ When the user runs `asciibinder build --distro=distro_test` on that repo directory
19
+ Then the program generates preview content for only the `distro_test` distro
20
+
21
+ Scenario: A user wants to build all distros against all relevant branches
22
+ Given a valid AsciiBinder docs repo with multiple distros
23
+ When the user runs `asciibinder build --all-branches` on that repo directory
24
+ Then the program generates preview content for all relevant distro/branch combos
25
+
26
+ Scenario: A user wants to build a specific page in the current branch
27
+ Given a valid AsciiBinder docs repo with multiple distros
28
+ When the user runs `asciibinder build --page=welcome:index` on that repo directory
29
+ Then the program generates preview content for the specified page in all distros
30
+
31
+ Scenario: A user wants to build from a repo where the docs root is not the repo root
32
+ Given a valid AsciiBinder docs repo where the docs root is not at the repo root
33
+ When the user runs `asciibinder build` on that docs root directory
34
+ Then the program generates preview content for all distros in the current branch
@@ -0,0 +1,20 @@
1
+ Feature: asciibinder clean
2
+
3
+ This command cleans up any files generated by AsciiBinder
4
+
5
+ Scenario: A user wants to clean a docs repo of generated content
6
+ Given a valid AsciiBinder docs repo
7
+ And the docs repo contains generated content
8
+ When the user runs `asciibinder clean` on that repo directory
9
+ Then the generated content is removed
10
+
11
+ Scenario: A user cleans a docs repo with no generated content
12
+ Given a valid AsciiBinder docs repo
13
+ And the docs repo contains no generated content
14
+ When the user runs `asciibinder clean` on that repo directory
15
+ Then the program exits without errors
16
+
17
+ Scenario: A user cleans a directory that is not a docs repo
18
+ Given an invalid AsciiBinder docs repo
19
+ When the user runs `asciibinder clean` on that repo directory
20
+ Then the program exits with a warning
@@ -0,0 +1,22 @@
1
+ Feature: asciibinder clone
2
+
3
+ This command clones a remote docs repo to a local directory and
4
+ sets up tracking branches for each branch listed in the distro map
5
+
6
+ Scenario: A user tries to clone a nonexistant remote repo
7
+ Given a nonexistant remote repo
8
+ And a nonexistant repo directory
9
+ When the user runs `asciibinder clone` on that repo directory
10
+ Then the program exits with a warning
11
+
12
+ Scenario: A user tries to clone a remote repo into an existing directory
13
+ Given an existing remote repo
14
+ And an existing repo directory
15
+ When the user runs `asciibinder clone` on that repo directory
16
+ Then the program exits with a warning
17
+
18
+ Scenario: A user tries to clone a remote repo into a nonexistant directory
19
+ Given an existing remote repo
20
+ And a nonexistant repo directory
21
+ When the user runs `asciibinder clone` on that repo directory
22
+ Then the program clones the remote repo into the local directory
@@ -0,0 +1,13 @@
1
+ Feature: asciibinder create
2
+
3
+ This command creates a new base docs repo to be managed by AsciiBinder
4
+
5
+ Scenario: A user tries to create a repo in an existing directory
6
+ Given an existing repo directory
7
+ When the user runs `asciibinder create` on that repo directory
8
+ Then the program exits with a warning
9
+
10
+ Scenario: A user tries to create a repo in a nonexistant directory
11
+ Given a nonexistant repo directory
12
+ When the user runs `asciibinder create` on that repo directory
13
+ Then the program generates a new base docs repo
@@ -0,0 +1,15 @@
1
+ Feature: asciibinder package
2
+
3
+ Causes the utility to run a `build` operation and then marshall
4
+ together all of the distro / branch combinations that will be
5
+ published into "sites". Each site has a distinct home page.
6
+
7
+ Scenario: A user wants to package all of the sites contained in their docs repo
8
+ Given a valid AsciiBinder docs repo with multiple distros
9
+ When the user runs `asciibinder package` on that repo directory
10
+ Then the program generates a site directory for each site in the distro map
11
+
12
+ Scenario: A user wants to package one of the sites contained in their docs repo
13
+ Given a valid AsciiBinder docs repo with multiple distros
14
+ When the user runs `asciibinder package --site=test` on that repo directory
15
+ Then the program generates a site directory for only the `test` site in the distro map
@@ -0,0 +1,182 @@
1
+ require 'ascii_binder/version'
2
+ require 'cucumber'
3
+ require 'fileutils'
4
+ require 'open3'
5
+ require 'diff_dirs'
6
+
7
+ Given(/^an existing repo directory$/) do
8
+ Dir.mkdir(working_dir)
9
+ end
10
+
11
+ Given(/^a nonexistant repo directory$/) do
12
+ working_dir
13
+ end
14
+
15
+ Given(/^a valid AsciiBinder docs repo(.*)$/) do |repo_condition|
16
+ multiple_distros = false
17
+ offset_docs_root = false
18
+ if repo_condition == ' with multiple distros'
19
+ multiple_distros = true
20
+ elsif repo_condition == ' where the docs root is not at the repo root'
21
+ multiple_distros = true
22
+ offset_docs_root = true
23
+ end
24
+ initialize_test_repo(true,multiple_distros,offset_docs_root)
25
+ end
26
+
27
+ Given(/^an invalid AsciiBinder docs repo(.*)$/) do |invalid_condition|
28
+ if invalid_condition == ' due to a malformed distro map'
29
+ initialize_test_repo(true,true)
30
+ invalidate_distro_map
31
+ else
32
+ initialize_test_repo(false)
33
+ end
34
+ end
35
+
36
+ Given(/^the docs repo contains generated content$/) do
37
+ output = run_command('package')
38
+ has_error = false
39
+ [preview_dir,package_dir].each do |subdir|
40
+ unless Dir.exist?(subdir)
41
+ puts "ERROR: expected directory '#{subdir}' was not created."
42
+ has_error = true
43
+ end
44
+ unless Dir.entries(subdir).select{ |item| not ['.','..'].include?(item) }.length > 0
45
+ puts "ERROR: directory '#{subdir}' is empty."
46
+ has_error = true
47
+ end
48
+ end
49
+ if has_error
50
+ print_output(output)
51
+ exit 1
52
+ end
53
+ end
54
+
55
+ Given(/^the docs repo contains no generated content$/) do
56
+ [preview_dir,package_dir].each do |subdir|
57
+ next unless Dir.exist?(subdir)
58
+ FileUtils.rm_rf(subdir)
59
+ end
60
+ end
61
+
62
+ Given(/^a nonexistant remote repo$/) do
63
+ @remote_repo_url = 'http://example.com/repo.git'
64
+ end
65
+
66
+ Given(/^an existing remote repo$/) do
67
+ # We're going to set up a local repo as a remote.
68
+ @remote_repo_dir = initialize_remote_repo
69
+ @remote_repo_url = "file://#{@remote_repo_dir}"
70
+ end
71
+
72
+ When(/^the user runs `asciibinder (.+)` on that (.+) directory$/) do |command_string,target_dir|
73
+ @command_args = command_string.split(' ')
74
+ run_dir = target_dir == 'docs root' ? File.join(working_dir,'docs') : working_dir
75
+ command = @command_args.shift
76
+ if command == 'clone'
77
+ @step_output = run_command(command,["-d #{working_dir}"],@remote_repo_url)
78
+ else
79
+ @step_output = run_command(command,@command_args,run_dir)
80
+ end
81
+ end
82
+
83
+ Then(/^the generated content is removed$/) do
84
+ has_error = false
85
+ [preview_dir,package_dir].each do |subdir|
86
+ unless Dir.exist?(subdir)
87
+ puts "ERROR: expected to find directory '#{subdir}' but didn't"
88
+ has_error = true
89
+ end
90
+ unless Dir.entries(subdir).select{ |item| not ['.','..'].include?(item) }.length == 0
91
+ puts "ERROR: expected directory '#{subdir}' to be empty"
92
+ has_error
93
+ end
94
+ end
95
+ if has_error
96
+ print_output(@step_output)
97
+ exit 1
98
+ end
99
+ end
100
+
101
+ Then(/^the program exits without errors$/) do
102
+ status_check(@step_output,'running `asciibinder clean`.')
103
+ end
104
+
105
+ Then(/^the program exits with a warning$/) do
106
+ if @step_output[:status].exitstatus == 0
107
+ puts "ERROR: testing `asciibinder clean`; expected an exit code other than 0."
108
+ print_output(@step_output)
109
+ exit 1
110
+ end
111
+ end
112
+
113
+ Then(/^the program clones the remote repo into the local directory$/) do
114
+ diffs = diff_dirs(@remote_repo_dir, working_dir)
115
+ non_git_diffs = diffs.select{ |entry| not entry[1].start_with?('.git') }
116
+ remote_branches = Git.open(@remote_repo_dir).branches.local.map{ |branch| branch.name }.sort
117
+ local_branches = Git.open(working_dir).branches.local.map{ |branch| branch.name }.sort
118
+ branch_matches = remote_branches & local_branches
119
+ unless branch_matches.length == local_branches.length and non_git_diffs.length == 0
120
+ puts "ERROR: cloned repo doesn't match remote repo."
121
+ exit 1
122
+ end
123
+ end
124
+
125
+ Then(/^the program generates a new base docs repo$/) do
126
+ diffs = diff_dirs(repo_template_dir, working_dir)
127
+ unless diffs.length == 1 and diffs[0][0] == :new and diffs[0][1] == '.git'
128
+ puts "ERROR: template repo copy produced differences - #{diffs.inspect}"
129
+ exit 1
130
+ end
131
+ end
132
+
133
+ Then(/^the program displays help information$/) do
134
+ status_check(@step_output,'`asciibinder help` command failed.')
135
+ unless @step_output[:stderr] == '' and @step_output[:stdout].start_with?('Usage:')
136
+ puts "ERROR: unexpected help output"
137
+ print_output(@step_output)
138
+ exit 1
139
+ end
140
+ end
141
+
142
+ Then(/^the program prints the current version of the utility$/) do
143
+ status_check(@step_output,'`asciibinder version` command failed.')
144
+ unless @step_output[:stderr] == '' and @step_output[:stdout].chomp == AsciiBinder::VERSION
145
+ puts "ERROR: unexpected help output"
146
+ print_output(@step_output)
147
+ exit 1
148
+ end
149
+ end
150
+
151
+ Then(/^the program generates preview content for (.+)$/) do |build_target|
152
+ status_check(@step_output,'`asciibinder build` command failed.')
153
+ case build_target
154
+ when 'all distros in the current branch'
155
+ build_check(:default)
156
+ when 'only the `distro_test` distro'
157
+ distro = @command_args.select{ |arg| arg.starts_with?('--distro=') }.map{ |arg| arg.split('=')[1] }[0]
158
+ build_check(:distro,distro)
159
+ when 'all relevant distro/branch combos'
160
+ build_check(:all_branches)
161
+ when 'the specified page in all distros'
162
+ page = @command_args.select{ |arg| arg.starts_with?('--page=') }.map{ |arg| arg.split('=')[1] }[0]
163
+ build_check(:page,page)
164
+ else
165
+ puts "ERROR: unrecognized test case '#{build_target}'"
166
+ exit 1
167
+ end
168
+ end
169
+
170
+ Then(/^the program generates a site directory for (.+) in the distro map$/) do |package_target|
171
+ status_check(@step_output,'`asciibinder package` command failed.')
172
+ case package_target
173
+ when 'each site'
174
+ package_check()
175
+ when 'only the `test` site'
176
+ site = @command_args.select{ |arg| arg.starts_with?('--site=') }.map{ |arg| arg.split('=')[1] }[0]
177
+ package_check(site)
178
+ else
179
+ puts "ERROR: unrecognized test case '#{build_target}'"
180
+ exit 1
181
+ end
182
+ end