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
- ./demo1.xxx.java
- ./demo1.xxx.rb
- ./demo2.xxx.java
- ./demo2.xxx.rb
- ./sub-dir/demo3.yyy.java
- ./sub-dir/demo3.yyy.rb
- ./sub-dir/demo4.yyy.java
- ./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
- http://agilecreativity.com/public/demo1.xxx.java
- http://agilecreativity.com/public/demo1.xxx.rb
- http://agilecreativity.com/public/demo2.xxx.java
- http://agilecreativity.com/public/demo2.xxx.rb
- http://agilecreativity.com/public/sub-dir/demo3.yyy.java
- http://agilecreativity.com/public/sub-dir/demo3.yyy.rb
- http://agilecreativity.com/public/sub-dir/demo4.yyy.java
- 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