Skip to content

Instantly share code, notes, and snippets.

@ozzzzzzzzzp
Forked from ryanb/1_let.rb
Created March 30, 2012 11:39
Show Gist options
  • Save ozzzzzzzzzp/2250984 to your computer and use it in GitHub Desktop.
Save ozzzzzzzzzp/2250984 to your computer and use it in GitHub Desktop.
let vs def
desc "A user's comment" do
let(:user) { User.create! name: "John" }
let(:comment) { user.comments.create! }
it "delegates to user's name" do
comment.name.should eq(user.name)
end
end
desc "A user's comment" do
def user
@user ||= User.create! name: "John"
end
def comment
@comment ||= user.comments.create!
end
it "delegates to user's name" do
comment.name.should eq(user.name)
end
end
desc "A user's comment" do
def user; @user ||= User.create! name: "John"; end
def comment; @comment ||= user.comments.create!; end
it "delegates to user's name" do
comment.name.should eq(user.name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment