I’ve got a question about testing approach, but also about rolling out a new feature to a project (something Thoughtbot have a lot of experience at ).
I work on an open source project that helps people give feedback on development applications. Currently you can write to the local planning authority about an application. We’ve been working on a new feature that allows people to also start an exchange with one of their local councillors.
We’re rolling this out to just a few local areas for starters, and we want to be able to turn the feature on and off globally easily if things need a quick fix.
Does anyone here have experience using a global feature flag like this? Any examples of how it would be implemented and tested would be greatly appreciated.
Here’s what I’m imagining: we can add an environment variable ‘COUNCILLORS_ENABLED’ to toggle the ability to choose who to write to:
scenario "can see councillor messages sections when feature is switched on" do ClimateControl.modify(COUNCILLORS_ENABLED: true) do visit application_path(application) expect(page).to have_content("Who should this go to?") end end
But, I can’t for the life of me get this test to work, I keep getting:
Failure/Error: ClimateControl.modify(COUNCILLORS_ENABLED: true) do NoMethodError: undefined method `keys' for nil:NilClass
UPDATE: The problem was that a was setting the var to a boolean, but it must be a String
I feel like I could be on the wrong track with this whole approach :S
I just saw in the upcase repo the way Decks was switched on https://github.com/thoughtbot/upcase/commit/978662a8a0c75fc26d47cb42737d19a0be6b06ad
Maybe it would be better to have a method
councillors_enabled? that returns
true if the environment variable is set. Then I could stub that method and not have to worry about managing the environment variables in tests. I might try that next.
I hope this is an interesting question I’m sure it’s something relevant to a lot of projects.