From 6d98be6d22e0a052bf1e2349c6745a8cafbd62ca Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 4 Apr 2014 12:25:57 +0200 Subject: [PATCH] reload app config before each test (complements 21bef8e304d05025b72b39e790abc7e8a4f4f5e1) --- lib/foodsoft_config.rb | 6 ++++++ lib/tasks/rspec.rake | 6 ++++++ spec/spec_helper.rb | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/lib/foodsoft_config.rb b/lib/foodsoft_config.rb index bbc37527..e19acaf5 100644 --- a/lib/foodsoft_config.rb +++ b/lib/foodsoft_config.rb @@ -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 diff --git a/lib/tasks/rspec.rake b/lib/tasks/rspec.rake index a7d67ae5..4ebbe191 100644 --- a/lib/tasks/rspec.rake +++ b/lib/tasks/rspec.rake @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c27ce50f..865e926f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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.