jcs / rubywarden

An unofficial, mostly Bitwarden-compatible API server written in Ruby (Sinatra and ActiveRecord)
ISC License
593 stars 49 forks source link

Spec Helpers: Modularization + "Factory" #83

Closed universal closed 5 years ago

universal commented 5 years ago

tl/dr: move request helpers to module and include in spec_helper add inital stab at "factory" for creating and logging in users

I was just working on the web vault stuff and noticed some repetition in the code. Most tests that check something with the api create a user and log that one in, which is always a long blob of code... and it has to be kept up-to-date whenever the api changes. I think it would be nice to have a factory class that just does this, and that can be called upon in the tests. Right now the factory also does the logging in, and therefore the name is not perfectly fitting, but I haven't come up with a better one so far. I put the code into the Rubywarden::Test namespace to avoid any possible naming conflicts.

In addition I moved all the request helpers like post_json, etc... to a module Rubywarden::Test::RequestHelpers which gets included.

All specs still pass fine. I'm mostly working with rspec, so I hope the style is ok.

I would be glad about any comments and would be happy to incorporate required changes :-)

universal commented 5 years ago

rebased to master :-)