Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4633

How do instance variables in rspec work?

$
0
0

Here is a bit of code from M Hartl's Ruby on Rails Tutorial. Can anyone explain why an instance variable (@user) is necessary and why not use a local variable. Also, since instance variables are supposed to be the variables in the instance of a class, which class is @user instantiated from?

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

Viewing all articles
Browse latest Browse all 4633

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>