You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 30, 2024. It is now read-only.
describe Post do
subject { Post.new(post_attributes) }
let(:post_attributes) { { } }
its(:description) { should be_empty }
describe "with a title" do
let(:post_attributes) { { title: "10 things about yak shaving you're doing wrong" } }
its(:description) { should == "10 things about yak shaving you're doing wrong" }
describe "with an author" do
let(:post_attributes) { { title: "10 things about yak shaving you're doing wrong", author: "Ernest Holbrecht" } }
its(:description) { should == "10 things about yak shaving you're doing wrong by Ernest Holbrecht" }
end
end
end
The Post.new call is DRYed up into the top of the spec, and each nested describe block defined what's different from its parent block. Except: here, the innermost describe block's definition of post_attributes repeats the title from the one above it.
I'd prefer to say something like this:
context "with an author" do
let(:post_attributes) { super.merge( author: "Ernest Holbrecht" ) }
its(:description) { should == "10 things about yak shaving you're doing wrong by Ernest Holbrecht" }
end
Unfortunately, I don't think we can use super, it would have to be super() (which is uglier) or else we'd get the error "Implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly."
So this issue is here to decide two things:
Is this a good thing to add to RSpec?
If so, what's the right word to use to refer to the inherited value of a let?