Skip to content

Commit

Permalink
All tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuck McCallum committed Apr 29, 2015
1 parent dd3315b commit 5f75c7b
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .rspec
@@ -1,3 +1,3 @@
--format documentation
--color
#--require spec_helper
--require spec_helper
2 changes: 1 addition & 1 deletion spec/features/catalog_spec.rb
Expand Up @@ -164,7 +164,7 @@ def expect_poster(id)
it 'works' do
visit '/catalog/1234.pbcore'
expect(page.status_code).to eq(200)
expect(page.source).to eq(File.read(File.dirname(File.dirname(__FILE__)) + '/fixtures/pbcore/clean-MOCK.xml'))
expect(page.source).to eq(File.read(Rails.root + 'spec/fixtures/pbcore/clean-MOCK.xml'))
expect(page.response_headers['Content-Type']).to eq('text/xml; charset=utf-8')
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/media_spec.rb
Expand Up @@ -6,7 +6,7 @@
TARGET = 'lorem ipsum'

def safe_ci
credentials_path = File.dirname(File.dirname(File.dirname(__FILE__))) + '/config/ci.yml'
credentials_path = Rails.root + 'config/ci.yml'
ci = Ci.new(credentials_path: credentials_path)
fail 'Workspace must be empty' unless ci.list_names.empty?
ci
Expand Down
26 changes: 13 additions & 13 deletions spec/models/vocab_map_spec.rb
Expand Up @@ -2,13 +2,13 @@
require_relative '../../app/models/vocab_map'

describe VocabMap do
fixtures = File.dirname(File.dirname(__FILE__)) + '/fixtures/vocab-maps'
fixtures = Rails.root + 'spec/fixtures/vocab-maps/'

# TODO: test xml processing, particularly attribute values.

describe 'when the map is good' do
describe 'acceptance' do
[File.dirname(File.dirname(File.dirname(__FILE__))) + '/config/vocab-maps',
[Rails.root + 'config/vocab-maps',
fixtures].each do |dir|
Dir["#{dir}/*"].reject { |file| file =~ /bad-/ }.each do |yaml|
it "accepts #{yaml}" do
Expand All @@ -19,17 +19,17 @@
end

it '#authorized_names' do
map = VocabMap.new(fixtures + '/good-ordinal-map.yml')
map = VocabMap.new(fixtures + 'good-ordinal-map.yml')
expect(map.authorized_names).to eq ['erste', 'zweite', 'dritte', 'undefined']
end

it 'implicitly case-normalizes' do
map = VocabMap.new(fixtures + '/good-map.yml')
map = VocabMap.new(fixtures + 'good-map.yml')
expect(map.map_string('YesThisIsRight')).to eq 'yesTHISisRIGHT'
end

it 'maps text nodes' do
map = VocabMap.new(fixtures + '/good-map.yml')
map = VocabMap.new(fixtures + 'good-map.yml')

doc = REXML::Document.new('<doc><element>foo</element></doc>')
nodes = REXML::XPath.match(doc, '/doc/element')
Expand All @@ -38,7 +38,7 @@
end

it 'maps attribute values' do
map = VocabMap.new(fixtures + '/good-map.yml')
map = VocabMap.new(fixtures + 'good-map.yml')

doc = REXML::Document.new('<doc attr="foo"></doc>')
nodes = REXML::XPath.match(doc, '/doc/@attr')
Expand All @@ -47,8 +47,8 @@
end

it 'reorders by mapped attribute value' do
card_map = VocabMap.new(fixtures + '/good-cardinal-map.yml')
ord_map = VocabMap.new(fixtures + '/good-ordinal-map.yml')
card_map = VocabMap.new(fixtures + 'good-cardinal-map.yml')
ord_map = VocabMap.new(fixtures + 'good-ordinal-map.yml')

doc = REXML::Document.new(
'<doc><el o="3.">drei</el><el o="second">two</el><el o="primo">I</el></doc>')
Expand All @@ -73,27 +73,27 @@
end

it 'catches case discrepancies on RHS' do
expect { VocabMap.new(fixtures + '/bad-mixed-case.yml') }.to(
expect { VocabMap.new(fixtures + 'bad-mixed-case.yml') }.to(
raise_error(/Case discrepancy on RHS/))
end

it 'catches bad yaml types' do
expect { VocabMap.new(fixtures + '/bad-not-omap.yml') }.to(
expect { VocabMap.new(fixtures + 'bad-not-omap.yml') }.to(
raise_error(/Unexpected datatype/))
end

it 'catches hidden keys' do
expect { VocabMap.new(fixtures + '/bad-hidden-keys.yml') }.to(
expect { VocabMap.new(fixtures + 'bad-hidden-keys.yml') }.to(
raise_error(/Hidden keys \["ShouldNotBeRemapped"\]/))
end

it 'catches hidden substring' do
expect { VocabMap.new(fixtures + '/bad-hidden-substring.yml') }.to(
expect { VocabMap.new(fixtures + 'bad-hidden-substring.yml') }.to(
raise_error(/Hidden keys \["this-prefix-hides", "hidden-by-this-suffix"\]/))
end

it 'catches missing defaults' do
expect { VocabMap.new(fixtures + '/bad-no-default.yml') }.to(
expect { VocabMap.new(fixtures + 'bad-no-default.yml') }.to(
raise_error(/No default mapping/))
end
end
Expand Down
1 change: 0 additions & 1 deletion spec/rails_helper.rb
@@ -1,6 +1,5 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
Expand Down
2 changes: 1 addition & 1 deletion spec/scripts/ci_spec.rb
Expand Up @@ -2,7 +2,7 @@
require 'tmpdir'

describe Ci, not_on_travis: true do
let(:credentials_path) { File.dirname(File.dirname(File.dirname(__FILE__))) + '/config/ci.yml' }
let(:credentials_path) { Rails.root + 'config/ci.yml' }
let(:aapb_workspace_id) { '051303c1c1d24da7988128e6d2f56aa9' } # we make sure NOT to use this.

it 'requires credentials' do
Expand Down
8 changes: 4 additions & 4 deletions spec/scripts/download_clean_ingest_spec.rb
Expand Up @@ -24,7 +24,7 @@ def dci_output(*args)
end

default_flags = '--stdout-log --same-mount --skip-sitemap'
default_mode = "--files #{File.dirname(__FILE__)}/../fixtures/dci/pbcore-dir/pbcore.xml"
default_mode = "--files #{Rails.root + 'spec/fixtures/dci/pbcore-dir/pbcore.xml'}"
{
# Expected to fail:
'' => [/USAGE:/],
Expand All @@ -50,17 +50,17 @@ def dci_output(*args)
/Successfully added .*37-010p2nvv.pbcore/,
/1 succeeded/
],
"#{default_flags} --id-files #{File.dirname(__FILE__)}/../fixtures/dci/id-file.txt" => [
"#{default_flags} --id-files #{Rails.root + 'spec/fixtures/dci/id-file.txt'}" => [
/Downloading .*guid\/37-010p2nvv/,
/Updated solr record cpb-aacip_37-010p2nvv/,
/Successfully added .*37-010p2nvv.pbcore/,
/1 succeeded/
],
"#{default_flags} --dirs #{File.dirname(__FILE__)}/../fixtures/dci/pbcore-dir" => [
"#{default_flags} --dirs #{Rails.root + 'spec/fixtures/dci/pbcore-dir'}" => [
/Updated solr record 1234/,
/1 succeeded/
],
"#{default_flags} --files #{File.dirname(__FILE__)}/../fixtures/dci/pbcore-dir/pbcore.xml" => [
"#{default_flags} --files #{Rails.root + 'spec/fixtures/dci/pbcore-dir/pbcore.xml'}" => [
/Updated solr record 1234/,
/1 succeeded/
],
Expand Down
2 changes: 1 addition & 1 deletion spec/scripts/pb_core_ingester_spec.rb
Expand Up @@ -2,7 +2,7 @@
require 'tmpdir'

describe PBCoreIngester do
let(:path) { File.dirname(File.dirname(__FILE__)) + '/fixtures/pbcore/clean-MOCK.xml' }
let(:path) { Rails.root + 'spec/fixtures/pbcore/clean-MOCK.xml' }

before(:each) do
@ingester = PBCoreIngester.new(is_same_mount: true)
Expand Down
7 changes: 7 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -81,3 +81,10 @@
# # as the one that triggered the failure.
# Kernel.srand config.seed
end

module Rails
# Allow more idiomatic tests everywhere, without loading in all of rails.
def self.root
File.dirname(File.dirname(__FILE__)) + '/'
end
end
5 changes: 2 additions & 3 deletions spec/support/code_style_spec.rb
Expand Up @@ -4,14 +4,13 @@
@merge = []
@error = []

root = File.dirname(File.dirname(File.dirname(__FILE__)))
all_paths = Dir[root + '/{app,config,scripts,spec}/**/*']
all_paths = Dir[Rails.root + '{app,config,scripts,spec}/**/*']
paths_to_check = all_paths.reject do |path|
path=~/\.(jar|ico|png|gif|jpg)$/ ||
File.directory?(path) ||
path == __FILE__
end
puts "Checking #{paths_to_check.count} files under #{root} for cruft..."
puts "Checking #{paths_to_check.count} files under #{Rails.root} for cruft..."
paths_to_check.each do |path|
File.readlines(path).each_with_index do |line, i|
combo = "#{path}:#{i}: #{line}"
Expand Down
2 changes: 1 addition & 1 deletion spec/support/link_checker.rb
Expand Up @@ -5,7 +5,7 @@
class LinkChecker
include Singleton

FILENAME = File.join(File.dirname(__FILE__), '.link-check.txt')
FILENAME = File.dirname(__FILE__) + '/.link-check.txt'
RE_IGNORES = [
/^\/catalog\?/, # too many combos
/^\/catalog\//, # redundant: other tests load each fixture
Expand Down

0 comments on commit 5f75c7b

Please sign in to comment.