I am new to test-driven development and rspec, so I am writing an application[1] to practice. One of the patterns I am trying to implement is from Ryan Bates' complex-form-examples[2]. 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 returns a link_to_function which calls a custom javascript function 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: https://github.com/samwgoldman/gradebook/blob/59b48ed4c973d135f54086ad483c09b6e34aec75/spec/helpers/application_helper_spec.rb The helper method those tests produced: https://github.com/samwgoldman/gradebook/blob/59b48ed4c973d135f54086ad483c09b6e34aec75/app/helpers/application_helper.rb I have a higher-level cucumber test as well, which I am relying on for the javascript testing: https://github.com/samwgoldman/gradebook/blob/59b48ed4c973d135f54086ad483c09b6e34aec75/features/create_evaluation.feature#L26 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. Thanks, Sam 1. https://github.com/samwgoldman/gradebook 2. https://github.com/ryanb/complex-form-examples _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users