Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 61 lines (51 sloc) 1.649 kB
b986955 @jcf Add a spec to enforce formatting code well
jcf authored
1 require "spec_helper"
2
3 # Borrowed from Bundler
4 # https://github.com/carlhuda/bundler/blob/1-0-stable/spec/quality_spec.rb
5 describe "The library itself" do
6 def check_for_tab_characters(filename)
7 failing_lines = []
8 File.readlines(filename).each_with_index do |line,number|
9 failing_lines << number + 1 if line =~ /\t/
10 end
11
12 unless failing_lines.empty?
13 "#{filename} has tab characters on lines #{failing_lines.join(', ')}"
14 end
15 end
16
17 def check_for_extra_spaces(filename)
18 failing_lines = []
19 File.readlines(filename).each_with_index do |line,number|
20 next if line =~ /^\s+#.*\s+\n$/
21 failing_lines << number + 1 if line =~ /\s+\n$/
22 end
23
24 unless failing_lines.empty?
25 "#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
26 end
27 end
28
29 RSpec::Matchers.define :be_well_formed do
30 failure_message_for_should do |actual|
31 actual.join("\n")
32 end
33
34 match do |actual|
35 actual.empty?
36 end
37 end
38
39 it "has no malformed whitespace" do
40 error_messages = []
41 Dir.chdir(File.expand_path("../..", __FILE__)) do
42 `git ls-files`.split("\n").each do |filename|
43 next if filename =~ /\.gitmodules|fixtures/
44 error_messages << check_for_tab_characters(filename)
45 error_messages << check_for_extra_spaces(filename)
46 end
47 end
48 error_messages.compact.should be_well_formed
49 end
50
51 it "can still be built" do
52 Dir.chdir(File.expand_path('../../', __FILE__)) do
53 `gem build webmock.gemspec`
54 $?.should == 0
55
56 # clean up the .gem generated
57 system("rm webmock-#{WebMock.version}.gem")
58 end
59 end
60 end
Something went wrong with that request. Please try again.