# Testing: be\_new\_record

**URL:** <https://www.ruby-forum.com/t/testing-be-new-record/172368>\
**Category:** Rails\
**Created:** [July 20, 2009, 11:37am UTC](https://www.ruby-forum.com/t/testing-be-new-record/172368 "2009-07-20T11:37:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthias\_Baumgart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Matthias\_Baumgart](https://www.ruby-forum.com/u/Matthias_Baumgart)\
**Post date:** [July 20, 2009, 11:37am UTC](https://www.ruby-forum.com/t/testing-be-new-record/172368/1 "2009-07-20T11:37:30Z")

</div>

Hello,

in the railscast episode 71, Ryan uses in a test be\_new\_record.  
Running tests with be\_new\_record causes a NameError: undefined local  
variable or method.

The episode isn’t on git and I didn’t find the code. I installed rspec  
and mocha, but didn’t find on google the origin of this function. Is  
this just a self implemented helper function or is it a function out  
of a testing framework? Which one?

Matthias.

---

<div class="post-metadata">

**Author:** ![Matthias\_Baumgart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Matthias\_Baumgart](https://www.ruby-forum.com/u/Matthias_Baumgart)\
**Post date:** [July 20, 2009, 1:35pm UTC](https://www.ruby-forum.com/t/testing-be-new-record/172368/2 "2009-07-20T13:35:34Z")

</div>

Rspec has a really cool feature where, if you assert that something  
should be\_something\_else it’ll assume there’s a method called  
something\_else?

So for example;

Suppose you had a model called Sushi.

In your spec you could write:

describe Sushi do

it “should be awesome”  
@sushi.should be\_awesome  
end

end

This will assume there is a method called awesome? available to @sushi  
and will call it and expect it to return true.

ActiveRecord::Base, which all of your models will inherit from has a  
method called “new\_record?”.  
By using “@model.should be\_new\_record” or “@model.should  
be\_a\_new\_record” you’re essentially saying that the new\_record? method  
should be called and should return true.

If you’re getting a NoMethod error specifically on “be\_a\_new\_record”  
then you might want to ensure you have the latest versions of rspec  
and rspec-rails.

Hope that helps?

Gavin

> **[Ruby on Rails tips & Tutorials](https://handyrailstips.com/)**
>
> Ruby on Rails tips and tutorials

---

<div class="post-metadata">

**Author:** ![Matthias\_Baumgart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Matthias\_Baumgart](https://www.ruby-forum.com/u/Matthias_Baumgart)\
**Post date:** [July 21, 2009, 8:26pm UTC](https://www.ruby-forum.com/t/testing-be-new-record/172368/3 "2009-07-21T20:26:26Z")

</div>

> If you’re getting a NoMethod error specifically on “be\_a\_new\_record”  
> then you might want to ensure you have the latest versions of rspec  
> and rspec-rails.

Hmm. Actually I got this error, but I have installed rspec and rspec-  
rails and put it to the config/environments/test with the following  
lines:

config.gem “rspec”, :lib =\> false, :version =\> “\>= 1.2.0”  
config.gem “rspec-rails”, :lib =\> false, :version =\> “\>= 1.2.0”  
config.gem “mocha”

be\_new\_record is a function of rspec?

Matthias.
