Sha256: d12640971bc821df2f21ddd948f76b53e32d088c1a4270480de30bb6a5b879a2

Contents?: true

Size: 1.41 KB

Versions: 9

Compression:

Stored size: 1.41 KB

Contents

if defined?(Encoding) && Encoding.default_external != "UTF-8"
  Encoding.default_external = "UTF-8"
end

describe "The library itself" do
  def check_for_tab_characters(filename)
    failing_lines = []
    File.readlines(filename).each_with_index do |line,number|
      failing_lines << number + 1 if line =~ /\t/
    end

    unless failing_lines.empty?
      "#{filename} has tab characters on lines #{failing_lines.join(', ')}"
    end
  end

  def check_for_extra_spaces(filename)
    failing_lines = []
    File.readlines(filename).each_with_index do |line,number|
      next if line =~ /^\s+#.*\s+\n$/
      failing_lines << number + 1 if line =~ /\s+\n$/
    end

    unless failing_lines.empty?
      "#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
    end
  end

  RSpec::Matchers.define :be_well_formed do
    failure_message do |actual|
      actual.join("\n")
    end

    match do |actual|
      actual.empty?
    end
  end

  it "has no malformed whitespace" do
    exempt = /\.gitmodules|\.marshal|fixtures|vendor|ssl_certs|kill|LICENSE/
    error_messages = []
    Dir.chdir(File.expand_path("../..", __FILE__)) do
      `git ls-files`.split("\n").each do |filename|
        next if filename =~ exempt
        error_messages << check_for_tab_characters(filename)
        error_messages << check_for_extra_spaces(filename)
      end
    end
    error_messages.compact.should be_well_formed
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mongo_mapper-0.17.0 spec/quality_spec.rb
mongo_mapper-0.16.0 spec/quality_spec.rb
mongo_mapper-0.15.6 spec/quality_spec.rb
mongo_mapper-0.15.5 spec/quality_spec.rb
mongo_mapper-0.15.4 spec/quality_spec.rb
mongo_mapper-0.15.3 spec/quality_spec.rb
mongo_mapper-0.15.2 spec/quality_spec.rb
mongo_mapper-0.15.1 spec/quality_spec.rb
mongo_mapper-0.15.0 spec/quality_spec.rb