Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

Are Controller Specs Supposed to be Repetitive?

I've been working at trying to understand Rails from the ground up since scaffolding has felt more like myseterious magic and I've read that scaffolding is not recommended to be used. I've only gotten as far as creating modes and controllers(with a few routes), but it really feels like my controller specs end up being almost carbon copies of each other with a few minor details(like the names of parameters that I'm passing in to or variables that I'm reading from). In general, are controller specs supposed to be nearly identical to each other or do they end up being a bit more distinct?

Travis Eubanks
Travis Eubanks
12,566 Points

Hey, so each model will have its own controller. In General at least in smaller apps I've worked with, the controllers are the same, just with specific data connected to each of its own. In the long run modifications will be made, and you will eventually want to do different things than the next controller. But the basis is to have the CRUD working!

Travis Eubanks
Travis Eubanks
12,566 Points

Hey, so each model will have its own controller. In General at least in smaller apps I've worked with, the controllers are the same, just with specific data connected to each of its own. In the long run modifications will be made, and you will eventually want to do different things than the next controller. But the basis is to have the CRUD working!

2 Answers

Hi James, I'm not an expert on testing, but my two pennies worth is that there probably is a way to refactor and dry up the code between controllers, having one spec running for multiple controllers, but I don't think it's worth doing that in the early stages unless it's a super-small app, because with most apps you end up changing quite a lot of things in your controllers.

Travis Eubanks
Travis Eubanks
12,566 Points

Hey, so each model will have its own controller. In General at least in smaller apps I've worked with, the controllers are the same, just with specific data connected to each of its own. In the long run modifications will be made, and you will eventually want to do different things than the next controller. But the basis is to have the CRUD working!

I understand that controllers themselves are going to be quite similar, but I was more concerned with the spec files for testing being nearly identical. It just feels like a lot could be refactored out for those tests. Then have the differences in the seperate spec files.