You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a modular Sinatra application that defines routes using dynamic values that come from a config file.
This works perfectly fine, except for the testing aspect of it - since the Server class is evaluated once before all tests, and the routes are called at class level.
I was able to use the reset! method followed by load, which seems to work, but a) feels hacky, and b) screwes up SimpleCov test coverage.
Is there a better way?
# serverclassServer < ServerBaseifconfig.base_uri# an example of a conditional route based on configgetconfig.base_uridoredirect"#{config.base_uri}/"endend# this catch all route uses a value from the configget"#{config.base_uri}/*"do# ...endend# specsdescribeServerdobefore:alldoServer.reset!config.base_uri='/docs'load'lib/madness/server.rb'endafter:alldoServer.reset!config.resetload'lib/madness/server.rb'end# rest of the specsend
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a modular Sinatra application that defines routes using dynamic values that come from a config file.
This works perfectly fine, except for the testing aspect of it - since the Server class is evaluated once before all tests, and the routes are called at class level.
I was able to use the
reset!
method followed byload
, which seems to work, but a) feels hacky, and b) screwes up SimpleCov test coverage.Is there a better way?
Beta Was this translation helpful? Give feedback.
All reactions