...

/

Workflow Tests Without Rails

Workflow Tests Without Rails

Let's learn how we can bypass Rails for speed workflows and associations.

Bypassing Rails for speed workflow

Limiting model tests to use only ActiveRecord doesn’t seem like that big a win overall since, almost by definition, a model test doesn’t explore anything beyond the model.

Ideally, we’d also be able to isolate our workflow object specs since those workflow objects are specifically created to be plain Ruby objects. Also, testing these actions can be particularly slow if we aren’t careful because we potentially create and save many model objects.

Bypassing Rails for speed associations

We can often isolate these objects by using test doubles as replacements for our ActiveRecord objects. However, test doubles can be difficult as replacements for Rails associations (we want to model them as lists, but they aren’t exactly listed). The two techniques can also work together: the code we would write to make it easier to isolate ActiveRecord also often makes the remaining code easier to use with test doubles.

Our existing CreatesProject tests can be isolated without much trouble, although there are rather many dependencies. The header looks like this:

rsync -avr --progress /usercode/* /usr/local/educative/gatherer --exclude course-content --exclude execute1.sh --exclude execute.sh --exclude __ed_script.sh --exclude __ed_stderr.txt --exclude __ed_stdout.txt
 
cd /usr/local/educative/gatherer
 
bundle exec rspec 
Changing the header of the creates_project_spec.rb file in the /spec/workflows directory

About that list of dependencies: it seems long. Especially since four of those require statements, the two devise lines, the role, and the user, are there only to support the User class. We need to ...