Skip to content

Commit

Permalink
Better handling of missing READMEs.
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviershay committed Apr 21, 2013
1 parent dc0bc7c commit 7e3c288
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 deletions.
13 changes: 1 addition & 12 deletions lib/cane/doc_check.rb
Expand Up @@ -63,18 +63,7 @@ def missing_file_violations
result = []
return result if opts[:no_readme]

filenames = ['README', 'readme']
extensions = [''] + %w(
.markdown
.md
.mdown
.rdoc
.textile
.txt
)
combinations = filenames.product(extensions)

if combinations.none? {|n, x| Cane::File.exists?(n + x) }
if Cane::File.case_insensitive_glob("README*").none?
result << { description: 'Missing documentation',
label: 'No README found' }
end
Expand Down
4 changes: 4 additions & 0 deletions lib/cane/file.rb
Expand Up @@ -21,6 +21,10 @@ def open(path)
def exists?(path)
::File.exists?(path)
end

def case_insensitive_glob(glob)
Dir.glob(glob, ::File::FNM_CASEFOLD)
end
end
end
end
27 changes: 13 additions & 14 deletions spec/doc_check_spec.rb
Expand Up @@ -57,20 +57,7 @@ class Doc; end
it 'creates a violation for missing README' do
file = fire_replaced_class_double("Cane::File")
stub_const("Cane::File", file)
file.should_receive(:exists?).with("README").and_return(false)
file.should_receive(:exists?).with("README.md").and_return(false)
file.should_receive(:exists?).with("README.mdown").and_return(false)
file.should_receive(:exists?).with("README.markdown").and_return(false)
file.should_receive(:exists?).with("README.textile").and_return(false)
file.should_receive(:exists?).with("README.txt").and_return(false)
file.should_receive(:exists?).with("README.rdoc").and_return(false)
file.should_receive(:exists?).with("readme").and_return(false)
file.should_receive(:exists?).with("readme.md").and_return(false)
file.should_receive(:exists?).with("readme.mdown").and_return(false)
file.should_receive(:exists?).with("readme.markdown").and_return(false)
file.should_receive(:exists?).with("readme.textile").and_return(false)
file.should_receive(:exists?).with("readme.txt").and_return(false)
file.should_receive(:exists?).with("readme.rdoc").and_return(false)
file.should_receive(:case_insensitive_glob).with("README*").and_return([])

violations = check("").violations
violations.length.should == 1
Expand All @@ -80,6 +67,18 @@ class Doc; end
]
end

it 'does not create a violation when readme exists' do
file = fire_replaced_class_double("Cane::File")
stub_const("Cane::File", file)
file
.should_receive(:case_insensitive_glob)
.with("README*")
.and_return(%w(readme.md))

violations = check("").violations
violations.length.should == 0
end

it 'skips declared exclusions' do
file_name = make_file <<-FILE.gsub /^\s{6}/, ''
class NeedsDocumentation
Expand Down
25 changes: 25 additions & 0 deletions spec/file_spec.rb
@@ -0,0 +1,25 @@
require 'spec_helper'
require 'tmpdir'

require 'cane/file'

describe Cane::File do
describe '.case_insensitive_glob' do
it 'matches all kinds of readmes' do
expected = %w(
README
readme.md
ReaDME.TEXTILE
)

Dir.mktmpdir do |dir|
Dir.chdir(dir) do
expected.each do |x|
FileUtils.touch(x)
end
Cane::File.case_insensitive_glob("README*").should == expected
end
end
end
end
end

0 comments on commit 7e3c288

Please sign in to comment.