DEV Community

Discussion on: 49 Days of Ruby: Day 47 -- Testing Frameworks: RSpec

Collapse
cseeman profile image
christine

Nice writup on Rspec! I like to use describe/context for grouping tests and telling the story about what the class should and shouldn't do. Like you said, Rspec is all about making it human readable, so if you don't like how your test output reads, change it! Also helpful when you start getting into a bigger code base is to use shared examples with Rspec. So when you start pulling in concerns and modules that a class may use, you can easily set up spec that align with that concern but then test it in the class actually using the concern.

So for ex. if your Coffee was extend Drinkable in your rspec (coffee_spec.rb) you could call it_behaves_like "drinkable" which would call off to a RSpec.shared_examples "drinkable" example that you could define.

Collapse
bengreenberg profile image
Ben Greenberg Author

Exactly! I end up defaulting to RSpec for almost all my testing needs in real production code, because of that human readability, and all the great features inherent in it that help you write tests that make sense to you when you look back at them 2 months later, and forgot what you initially did. :)