Search⌘ K
AI Features

Expectations and lit

Explore how to apply RSpec's let and let! methods to manage test data efficiently while writing Ruby on Rails tests. Understand implicit and predicate matchers to improve test readability and maintainability. This lesson equips you with techniques to write clearer, more idiomatic RSpec tests, enhancing your Test-Driven Development workflow.

In addition to examining code for potential refactoring, it’s a good idea to look at the duplication tests.

Ruby
require "rails_helper"
RSpec.describe Project do
it "considers a project with no tasks to be done" do
project = Project.new
expect(project.done?).to be_truthy
end
it "knows that a project with an incomplete task is not done" do
project = Project.new
task = Task.new
project.tasks << task
expect(project.done?).to be_falsy
end
end

In this case, in the spec/models/project_spec.rb file, we have a single line of common setup, project = Project.new ...