← Back to Upcase

Need to make sure my app is tested before I add more features

(Charlieanna ) #1

I have developed an app just to learn stuff about rails and tdd. But I have not written any specs yet. There a couple of good features in it like creating a calender using Angular and Rails. Reading a CSV file and inviting people. But now before add more views and features I want to make sure the app works as I want to. What should I do right now considering there no specs yet?

Should I start the app from scratch but using TDD or is there any other way to approach it. ?


(Aaron Mc Adam) #2

I wouldn’t say you’d need to write it from scratch, though you would probably do a much better job now that you’ve learned some Rails patterns.

One technique you could use is to write high-level acceptance tests (RSpec feature specs are perfect for this) that define the behaviour of the the app from the User’s perspective. Then you can rewrite different chunks of the app’s behaviour one at a time, adding unit tests while you go. This is known as Outside-In testing.

(Geoff Harcourt) #3

Add specs every time you change code. You can’t make the debt you’ve created by not writing specs go away immediately, but you can make a dent at a sustainable pace by starting to enforce TDD discipline now. @aaronmcadam’s advice about writing some acceptance tests is another good strategy you can employ to start spec-ing your app now.

I would only do the rewrite if you felt like your understanding of Ruby or Rails at the time you began the app was very elementary. Rewrites have a terrible track record, but I’d say the exception to the “fix it rather than rewrite” dictum would be if the app was one of the very first exercises you did in a language or framework, more of a code spike for learning rather than a thing built to last.

(Jared Smith) #4

Rebuilding it will yield you better code over all since you know how to build it, but you need to ask yourself is this a wise choice. If it will just take you 2 hrs to do. I’d say go for it, and its TDD practice on something you know how to build.

If you do not think it will be a quick rebuild and do not want to throw away a decent amount of code, add some integration tests to cover major functionality and create that first test island, as you work and improve things add more and more tests to your app. This is good practice for working with legacy code bases, its hard to throw away code in a large or old code base. Rarely ever will business concerns and engineering concerns align enough to allow a rebuild from scratch.

You will probably need to use jasmine js or some other client-side testing framework to test the angular portion of your app. Using Rspec to do this is a pain in the butt and it comes with a lot of gotchas. I had quite a few issues just trying to get tests to run against angular even with browser engines like selenium or webkit. So I switched to using jasmine for angular apps.