Skip to content

Instantly share code, notes, and snippets.

@Telmo
Forked from ryanb/1_let.rb
Created April 14, 2012 13:51
Show Gist options
  • Save Telmo/2384588 to your computer and use it in GitHub Desktop.
Save Telmo/2384588 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