reload app config before each test

(complements 21bef8e304d05025b72b39e790abc7e8a4f4f5e1)
This commit is contained in:
wvengen 2014-04-04 12:25:57 +02:00
parent ed439d0b08
commit 6d98be6d22
3 changed files with 18 additions and 0 deletions

View file

@ -60,5 +60,11 @@ class FoodsoftConfig
}.merge(config))
end
# reload original configuration file, e.g. in between tests
def reload!(filename = APP_CONFIG_FILE)
APP_CONFIG.clear.merge! YAML.load(File.read(File.expand_path(filename, Rails.root)))
init
end
end
end

View file

@ -3,5 +3,11 @@ begin
task(:spec).clear
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
# Use `rspec` to run a single test. When a test fails in rake but not
# with rspec, you can use the following to run a single test using rake:
#RSpec::Core::RakeTask.new('spec:foo') do |t|
# t.pattern = "spec/integration/foo_spec.rb"
#end
rescue LoadError
end

View file

@ -37,6 +37,12 @@ RSpec.configure do |config|
DatabaseCleaner.clean
end
# reload foodsoft configuration, so that tests can use FoodsoftConfig.config[:foo]=x
# without messing up tests run after that
config.before(:each) do
FoodsoftConfig.send :reload!
end
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.