[rspec-users] how can this pass?

Mark Wilden mark at mwilden.com
Tue Feb 10 10:19:02 EST 2009

On Mon, Feb 9, 2009 at 10:18 PM, Sergio Bayona <lists at ruby-forum.com> wrote:
>  describe "responding to GET new" do
>    it "should expose a new property as @property" do
>      @account = mock_model(Account)
>      @account.should_receive(:properties)
>      @property = mock_model(Property, :new_record? => false, :errors =>
> [])
>      @account.properties.should_receive(:build).and_return(@property)
>      get :new
>      assigns[:property].should == @property
>    end
>  end

Another thing is that instance variables shouldn't be used unless
necessary. As a rule of thumb, things should have as limited a scope
as possible. Prefer class variables to global variables, instance
variables to class variables, and local variables to instance

Some reasons are 1) to better communicate your intent, 2) to limit the
places you have to look to see where a variable is being changed, and
3) to limit the amount of code that might depend on the variable.


More information about the rspec-users mailing list