这是 M Hartl 的 Ruby on Rails 教程中的一些代码。谁能解释为什么需要实例变量(@user)以及为什么不使用局部变量。另外,由于实例变量应该是类实例中的变量,@user 是从哪个类实例化的?
require 'spec_helper'
describe User do
before { @user = User.new(name: "Example User", email: "user@example.com") }
subject { @user }
it { should respond_to(:name) }
it { should respond_to(:email) }
end