mysociety / fixmystreet

This is mySociety's popular map-based reporting platform: easy to install in new countries and regions
http://fixmystreet.org/
Other
507 stars 235 forks source link

Add generic way to override general.yml config in tests #569

Closed chrismytton closed 11 years ago

chrismytton commented 11 years ago

Currently the tests depend on certain settings in conf/general.yml being correct before they will pass.

It would be good if we could have a generic method that allowed you to override certain parts of the config within the tests. There is already a more specific version of this in the Zurich cobrand's tests.

It would potentially work something like (pseudo-code):

override_config MAPIT_TYPES => [ 'O01' ] {
  # MAPIT_TYPES is overridden for the duration of this code block
}

Relevant IRC discussion with @evdb

If you were happy to touch the code in commonlib you could add a method that let you override the config for tests. It could use the scoping so that when the guard object falls out of scope the config is restored.

and

The config can come from two places - the commonlib stuff, and FixMyStreet.pm direct.

dracos commented 11 years ago

I'd certainly rather leave mySociety::Config alone to simply read in the config as it does (so no need to touch commonlib), and for everywhere in the code to use FixMyStreet->config (currently 36 mySociety::Config in perllib, 52 FixMyStreet->config, so it'll presumably just be hangovers and should be easy to swap). Then a generic override would only be needed in the FixMyStreet test code and presumably could be based on that Zurich code.

dracos commented 11 years ago

Done in 94ac7786132a538a5742ba325eb7fe9eff89cfc9. Called by (actual code):

FixMyStreet::override_config {
    MAPIT_TYPES => [ 'O01' ]
}, sub {
    # ... code ...
};