require 'fileutils' require_relative '../spec_helper' describe IndexHtml do let(:files) do CodeLister.files base_dir: 'spec/fixtures', exts: %w(xxx.rb), recursive: true end context '#basenames!' do it 'excludes full path of the files' do expect(IndexHtml.basenames!(files, basename: true)).to eq ['demo1.xxx.rb', 'demo2.xxx.rb'] end it 'includes full path of the files' do expect(IndexHtml.basenames!(files)).to eq ['./demo1.xxx.rb', './demo2.xxx.rb'] expect(IndexHtml.basenames!(files, basename: false)).to eq ['./demo1.xxx.rb', './demo2.xxx.rb'] end end context '#escape_uris!' do it 'works correctly with full path' do expect(IndexHtml.escape_uris!(files, encoded: true)).to eq ['.%2Fdemo1.xxx.rb', '.%2Fdemo2.xxx.rb'] end end context '#htmlify' do let :files do CodeLister.files base_dir: 'spec/fixtures', exts: %w(rb java), recursive: true end it 'generates simple index file' do FileUtils.rm_rf('index.html') IndexHtml.htmlify files, indent: 6, output: 'index.html', base_dir: 'spec/fixtures' expect(capture(:stdout) { system('cat index.html') }).to eq \ <<-EOT File Listing
File List
  1. ./demo1.xxx.java
  2. ./demo1.xxx.rb
  3. ./demo2.xxx.java
  4. ./demo2.xxx.rb
  5. ./sub-dir/demo3.yyy.java
  6. ./sub-dir/demo3.yyy.rb
  7. ./sub-dir/demo4.yyy.java
  8. ./sub-dir/demo4.yyy.rb
EOT end it 'generates simple index file with prefix' do FileUtils.rm_rf('index.html') IndexHtml.htmlify files, indent: 6, output: 'index.html', prefix: 'http://agilecreativity.com/public', base_dir: 'spec/fixtures' # Note: must not puts the '/' at the end! expect(capture(:stdout) { system('cat index.html') }).to eq \ <<-EOT File Listing
File List
  1. http://agilecreativity.com/public/demo1.xxx.java
  2. http://agilecreativity.com/public/demo1.xxx.rb
  3. http://agilecreativity.com/public/demo2.xxx.java
  4. http://agilecreativity.com/public/demo2.xxx.rb
  5. http://agilecreativity.com/public/sub-dir/demo3.yyy.java
  6. http://agilecreativity.com/public/sub-dir/demo3.yyy.rb
  7. http://agilecreativity.com/public/sub-dir/demo4.yyy.java
  8. http://agilecreativity.com/public/sub-dir/demo4.yyy.rb
EOT end end context '#make_links' do it 'works with prefix' do result = IndexHtml.make_links files, base_dir: 'spec/fixtures', prefix: 'public' expect(capture(:stdout) { puts result }).to eq \ <<-EOT
  • public/demo1.xxx.rb
  • public/demo2.xxx.rb
  • EOT end it 'works without prefix' do result = IndexHtml.make_links(files, base_dir: 'spec/fixtures') expect(capture(:stdout) { puts result }).to eq \ <<-EOT
  • ./demo1.xxx.rb
  • ./demo2.xxx.rb
  • EOT end it 'works with base_dir starting with dot' do files = CodeLister.files base_dir: './spec/fixtures', exts: %w(xxx.rb), recursive: true result = IndexHtml.make_links(files, base_dir: './spec/fixtures/') expect(capture(:stdout) { puts result }).to eq \ <<-EOT
  • ./demo1.xxx.rb
  • ./demo2.xxx.rb
  • EOT end it 'works with base_dir not starting with dot' do files = CodeLister.files base_dir: 'spec/fixtures', exts: %w(xxx.rb), recursive: true result = IndexHtml.make_links(files, base_dir: 'spec/fixtures/') expect(capture(:stdout) { puts result }).to eq \ <<-EOT
  • ./demo1.xxx.rb
  • ./demo2.xxx.rb
  • EOT end end end