Given: this rspec file is in PROJECT_ROOT/spec
describe 'codebase' do
let(:lines_with_more_than_80_characters) do
Dir.glob( File.expand_path('../../lib/**/*.rb', __FILE__ ) ).map do |path|
File.open( path ) do |file|
idx = 0
file.lines.map do |line|
idx += 1
next nil if line.length < 80
"#{file.path}:#{idx}"
end
end
end.compact.reduce([],:<<).flatten.compact
end
it 'should not have lines longer than 80 characters.' do
lines_with_more_than_80_characters.should be_empty,
%Q(Expected no entries, got: \n#{lines_with_more_than_80_characters.join("\n")})
end
end
yields the following result on failure:
..........F
Failures:
1) codebase should not have lines longer than 80 characters.
Failure/Error: lines_with_more_than_80_characters.should be_empty,
Expected no entries, got:
/Users/yaauie/projects/project-name/lib/a-source-file.rb:32
/Users/yaauie/projects/project-name/lib/a-source-file.rb:41
/Users/yaauie/projects/project-name/lib/another-source-file.rb:12
/Users/yaauie/projects/project-name/lib/another-source-file.rb:48
# ./spec/codebase.spec.rb:16
Finished in 0.01717 seconds
11 examples, 1 failure
@topfunky -- FWIW, I used to have a spec like this but have switched to using cane. I'm a huge fan of Cane.