Skip to content

Commit

Permalink
Create have_a_valid_manifest matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Mar 15, 2018
1 parent 5a1543b commit b151280
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 51 deletions.
28 changes: 28 additions & 0 deletions common/spec/spec_helper_foot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,31 @@ def sort(x)
"expected no dependency to be created from #{expected.inspect}"
end
end

RSpec::Matchers.define :have_a_valid_manifest do
match do |actual|
manifest_lines = File.readlines(actual + '.manifest').map(&:chomp).reject(&:empty?)
gemspec_lines = eval(File.read(actual + '.gemspec'), binding, actual + '.gemspec').files

@missing_from_manifest = gemspec_lines - manifest_lines
@extra_in_manifest = manifest_lines - gemspec_lines

@missing_from_manifest.empty? && @extra_in_manifest.empty?
end

description do
'have a valid manifest'
end

failure_message do |_actual|
reasons = []
if @missing_from_manifest.any?
reasons << "file(s) missing from manifest (#{@missing_from_manifest.join(', ')})"
end
if @extra_in_manifest.any?
reasons << "file(s) extra in manifest (#{@extra_in_manifest.join(', ')})"
end

"expected manifest to be valid (problems: #{reasons.join(' and ')})"
end
end
19 changes: 2 additions & 17 deletions nanoc-external/spec/manifest_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
# frozen_string_literal: true

describe 'manifest', chdir: false do
let(:manifest_lines) do
File.readlines('nanoc-external.manifest').map(&:chomp).reject(&:empty?)
end

let(:gemspec_lines) do
gemspec = eval(File.read('nanoc-external.gemspec'), binding, 'nanoc-external.gemspec')
gemspec.files
end

it 'contains all files in gemspec' do
missing_from_manifest = gemspec_lines - manifest_lines
expect(missing_from_manifest).to be_empty, "Found files that appear in the gemspec, but not in the manifest: #{missing_from_manifest.join(', ')}"
end

it 'contains no files not in gemspec' do
extra_in_manifest = manifest_lines - gemspec_lines
expect(extra_in_manifest).to be_empty, "Found files that appear in the manifest, but not in the gemspec: #{extra_in_manifest.join(', ')}"
example do
expect('nanoc-external').to have_a_valid_manifest
end
end
19 changes: 2 additions & 17 deletions nanoc-live/spec/manifest_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
# frozen_string_literal: true

describe 'manifest', chdir: false do
let(:manifest_lines) do
File.readlines('nanoc-live.manifest').map(&:chomp).reject(&:empty?)
end

let(:gemspec_lines) do
gemspec = eval(File.read('nanoc-live.gemspec'), binding, 'nanoc-live.gemspec')
gemspec.files
end

it 'contains all files in gemspec' do
missing_from_manifest = gemspec_lines - manifest_lines
expect(missing_from_manifest).to be_empty, "Found files that appear in the gemspec, but not in the manifest: #{missing_from_manifest.join(', ')}"
end

it 'contains no files not in gemspec' do
extra_in_manifest = manifest_lines - gemspec_lines
expect(extra_in_manifest).to be_empty, "Found files that appear in the manifest, but not in the gemspec: #{extra_in_manifest.join(', ')}"
example do
expect('nanoc-live').to have_a_valid_manifest
end
end
19 changes: 2 additions & 17 deletions nanoc/spec/manifest_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
# frozen_string_literal: true

describe 'manifest', chdir: false do
let(:manifest_lines) do
File.readlines('nanoc.manifest').map(&:chomp).reject(&:empty?)
end

let(:gemspec_lines) do
gemspec = eval(File.read('nanoc.gemspec'), binding, 'nanoc.gemspec')
gemspec.files
end

it 'contains all files in gemspec' do
missing_from_manifest = gemspec_lines - manifest_lines
expect(missing_from_manifest).to be_empty, "Found files that appear in the gemspec, but not in the manifest: #{missing_from_manifest.join(', ')}"
end

it 'contains no files not in gemspec' do
extra_in_manifest = manifest_lines - gemspec_lines
expect(extra_in_manifest).to be_empty, "Found files that appear in the manifest, but not in the gemspec: #{extra_in_manifest.join(', ')}"
example do
expect('nanoc').to have_a_valid_manifest
end
end

0 comments on commit b151280

Please sign in to comment.