March 2025
Intermediate to advanced
472 pages
12h 10m
English
RSpec is an alternative to MiniTest, which Rails uses. It’s different in almost every way, and many developers prefer it. Here’s what one of our existing tests might look like written in RSpec:
| | RSpec.describe Cart do |
| | |
| | let(:cart) { Cart.create } |
| | let(:book_one) { products(:ruby) } |
| | let(:book_two) { products(:two) } |
| | |
| | before do |
| | cart.add_product(book_one).save! |
| | cart.add_product(book_two).save! |
| | end |
| | |
| | it "can have multiple products added" do |
| | expect(cart.line_items.size).to eq(2) |
| | end |
| | |
| | it "calculates the total price of all products" do |
| | expect(cart.total_price).to eq(book_one.price + book_two.price) |
| | end |
| | end |
It almost looks like a different programming ...
Read now
Unlock full access