let vs instance variables in RSpec
merit of "let"
1. When you refactor from local variables into a "let", you should not add @ to variables prefix.
2. "let" is subjective.
3. "let" is lower cost than initialize instance methods by each. e.g. before(:each) { @foo = "foo" }.
Maybe instance variables is useful when you shouldn't save cost.
sample
# let context 'foo' do let(:bar) { :bar } it { bar.should eq(:bar) } end # instance variables context 'foo' do before do @user.role = Role.new(:role => :admin) end it { @bar.should eq(:bar) } end