I am new to test-driven development and rspec, so I am writing an
application to practice. One of the patterns I am trying to
implement is from Ryan B.’ complex-form-examples. Ryan’s example
doesn’t have any tests, so I am trying to write tests for the code.
I am starting with a helper function that he wrote, which makes it
easy to add fields for an association into a form. The method does a
little reflection, renders a fields_for call into a string, and then
that adds the fields to the form.
My question is specifically in regard to testing this method in the
helper. I have written a test which is green, but I am not sure if it
is a good test. Since I am new, I would greatly benefit to some
opinions and critiques of my work.
Some concerns that I have:
- I am doing a lot of method expectations, and doing so makes me think
that I am doing something wrong.
- My test covers functionality specific to the association between
Evaluation and Criterion, while the code is generic.
The spec that I came up with:
The helper method those tests produced:
I have a higher-level cucumber test as well, which I am relying on for
I learned a lot about RSpec doing this, but I am sure that with a few
opinions and critiques I could learn a lot more.