RSpec testing with rails Beginner-friendly??

Hello,

I am a beginner at Rails and testing is completely new to me. This is the first time I am writing a test. I have no idea what I am doing. So far, I learned about TDD and BDD.

Most of the examples I have come across don't even explain anything why would I write the test first?

How is the file structure to call on the classes?

What are the classes that we are referring to in the test, the CSS class?

is there a beginners step by step guide, It's all very confusing?

Please give me some insight

Thank you

6 thoughts on “RSpec testing with rails Beginner-friendly??”

  1. As far as TDD, I can give you a very brief simple explanation — I think we all agree that tested code is good, and that testing all the code would be great. That way we could refactor things and have the tests tell us if we broke something. But, to get total coverage, we have to reverse engineer all the logic that is written, just to write tests for what it intended to do. What if instead we wrote the test to express intent first? Then only write as much code as is necessary to pass that test. This should be fully tested code and the intent is codified in the tests. And so an application built like that will be well tested and easy to refactor.

    Also, and this is a subtler point — writing code in a way that is easily testable leads to good _design_ not just good coverage. That’s why it’s Test Driven Design and not Development. Dependency injection and other methods used to enable testing are good design and lead to well decoupled code. And so on for lots of other software engineering principles.

    Reply
  2. Your question about which classes are being referred to is throwing me off a bit. Maybe you should first do a course on Ruby the language, before diving into testing and especially TDD. In general I think TDD is already a bit outdated as a practice. There might be situations where you’d do it, but not as a main way to develop.

    My advise is, if you don’t know what a class is, learn Ruby first and forget about tests for a while.

    After the basics, learn minitest first, not rspec

    Reply

Leave a Comment