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.