Skip to content

Commit

Permalink
Merge pull request #134 from projecthydra/config_spec_test_refactor
Browse files Browse the repository at this point in the history
Refactor config tests so the subject is the config object which fixes…
  • Loading branch information
jeremyf committed Mar 31, 2017
2 parents 5895de1 + dc3600f commit 15de20c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
5 changes: 3 additions & 2 deletions lib/hydra/derivatives.rb
Expand Up @@ -46,8 +46,9 @@ def self.reset_config!
@config = Config.new
end

[:ffmpeg_path, :libreoffice_path, :temp_file_base, :fits_path, :kdu_compress_path,
:kdu_compress_recipes, :enable_ffmpeg, :source_file_service, :output_file_service].each do |method|
CONFIG_METHODS = [:ffmpeg_path, :libreoffice_path, :temp_file_base, :fits_path, :kdu_compress_path,
:kdu_compress_recipes, :enable_ffmpeg, :source_file_service, :output_file_service].freeze
CONFIG_METHODS.each do |method|
module_eval <<-RUBY
def self.#{method}
config.#{method}
Expand Down
3 changes: 3 additions & 0 deletions spec/processors/jpeg2k_spec.rb
Expand Up @@ -31,6 +31,9 @@
@sample_cfg = YAML.load_file(File.expand_path('../../fixtures/jpeg2k_config.yml', __FILE__))['test']
Hydra::Derivatives.kdu_compress_recipes = @sample_cfg['jp2_recipes']
end
after(:all) do
Hydra::Derivatives.reset_config!
end

it "can get the recipe from a config file" do
args = { recipe: :myrecipe }
Expand Down
12 changes: 1 addition & 11 deletions spec/units/config_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'

describe "the configuration" do
subject { Hydra::Derivatives }
subject { Hydra::Derivatives::Config.new }

before do
# It's not always /tmp; it depends on OS and ENV vars
Expand Down Expand Up @@ -41,14 +41,4 @@
subject.source_file_service = source_file_service
expect(subject.source_file_service).to eq(source_file_service)
end

it "lets you reset the configuration" do
subject.ffmpeg_path = '/usr/local/ffmpeg-1.0/bin/ffmpeg'
subject.reset_config!
expect(subject.ffmpeg_path).to eq('ffmpeg')

subject.kdu_compress_path = '/usr/local/bin/kdu_compress'
subject.reset_config!
expect(subject.kdu_compress_path).to eq('kdu_compress')
end
end
25 changes: 25 additions & 0 deletions spec/units/derivatives_spec.rb
Expand Up @@ -30,4 +30,29 @@ class CustomFile < ActiveFedora::Base
end
end
end

Hydra::Derivatives::CONFIG_METHODS.each do |method|
describe method.to_s do
it 'returns the config value' do
expect(subject.send(method)).to eq subject.config.send(method)
end
end
describe "#{method}=" do
it 'stores config changes' do
expect { subject.send("#{method}=", "new_value") }.to change { subject.config.send(method) }.from(subject.config.send(method)).to("new_value")
end
end
end

describe 'reset_config!' do
it "resets the configuration" do
subject.ffmpeg_path = '/usr/local/ffmpeg-1.0/bin/ffmpeg'
subject.reset_config!
expect(subject.ffmpeg_path).to eq('ffmpeg')

subject.kdu_compress_path = '/usr/local/bin/kdu_compress'
subject.reset_config!
expect(subject.kdu_compress_path).to eq('kdu_compress')
end
end
end

0 comments on commit 15de20c

Please sign in to comment.