# Second question on using RSpec for a simple Rails 2.0 app

**URL:** <https://www.ruby-forum.com/t/second-question-on-using-rspec-for-a-simple-rails-2-0-app/141713>\
**Category:** Rails\
**Created:** [June 29, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/second-question-on-using-rspec-for-a-simple-rails-2-0-app/141713 "2008-06-29T23:19:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [June 29, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/second-question-on-using-rspec-for-a-simple-rails-2-0-app/141713/1 "2008-06-29T23:19:11Z")

</div>

Hi,

I’ve got a Rails 2.0 app “AIMS\_1” with one model, “Portfolio”. (I’m  
following David C.’s 2007 tutorial at  
[http://blog.davidchelimsky.net/articles/2007/05/14/an-introduction-to-rspec-part-i](http://blog.davidchelimsky.net/articles/2007/05/14/an-introduction-to-rspec-part-i)).  
Portfolio has two attributes: :symbol and :name.  
With great help from this NG, I’ve got a neat set of validations  
for :symbol.

I want to put together a script that will test the validations as part  
of a suite of tests to confirm the app’s validity as I expand it. For  
this purpose, I added a Q&A directory (actually, “\_\_QA”) under AIMS\_1  
and populated it with the following portfolio\_spec.rb file:

# portfolio\_spec.rb

# K:\_Projects\Ruby\_Rails\_Apps\AIMS\_1\_\_QA

require ‘rubygems’  
require ‘spec’  
require ‘spec/story’  
require ‘K:/\_Utilities/ruby186-26\_rc2/ruby/lib/ruby/gems/1.8/gems/  
activerecord-2.0.2/lib/ActiveRecord’  
require ‘…/app/models/portfolio’

describe Portfolio do  
it “should report any invalid :stock entries” do  
pf = Portfolio.new  
end  
end

When I run “spec portfolio\_spec.rb” in a Command window I get the  
diagnostic:

ActiveRecord::ConnectionNotEstablished in ‘Portfolio should report any  
invalid :stock entries’.

I expected some error because I’m creating a Portfolio instance  
outside the AIMS\_1 framework generated by Rails. I have no idea how  
to address this issue.

I’m running ruby 1.8.6, Rails 2.0.2 and SciTE 1.74 over WinXP/SP2.

Any ideas?

Thanks in Advance,  
Richard

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [June 30, 2008, 1:57am UTC](https://www.ruby-forum.com/t/second-question-on-using-rspec-for-a-simple-rails-2-0-app/141713/2 "2008-06-30T01:57:51Z")

</div>

RichardOnRails wrote:

> When I run spec portfolio\_spec.rb in a Command window I get the  
> diagnostic:
> 
> ActiveRecord::ConnectionNotEstablished in ‘Portfolio should report any  
> invalid :stock entries’.
> 
> I expected some error because I’m creating a Portfolio instance  
> outside the AIMS\_1 framework generated by Rails. I have no idea how  
> to address this issue.
> 
> I’m running ruby 1.8.6, Rails 2.0.2 and SciTE 1.74 over WinXP/SP2.
> 
> Any ideas?
> 
> Thanks in Advance,  
> Richard

Are you using the Rspec-Rails plugin?  
Cos that should absorb a lot of this capacity for error.  
(looks like you just want to require “…/…/config/environment” or  
something to fix it, so you load rails, rather than just active\_record)

but…

> **[GitHub - dchelimsky/rspec-rails: RSpec extension library for Ruby on Rails](https://github.com/dchelimsky/rspec-rails/tree/master)**
>
> master

install it as a plugin  
(maybe install rspec as a plugin in the same way else it seems to choke  
if your rspec and rspec-rails versions are different)

then run “ruby script/generate rspec”  
(don’t ask me why this isnt a rake task “spec:setup”… but it isn’t)

and you should have a basic spec\_helper in place.

then try creating a new model

“ruby script/generate rspec\_model Furbie name:string age:integer”

and it should get you a new spec in spec/models/furbie\_spec.rb  
which should work,  
and then make your existing code work the same way…  
see what went wrong the first time…

Regards  
Matthew R.

(recommend me on WorkingWithRails  
[http://workingwithrails.com/person/12394-matthew-rudy-jacobs](http://workingwithrails.com/person/12394-matthew-rudy-jacobs))

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [June 30, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/second-question-on-using-rspec-for-a-simple-rails-2-0-app/141713/3 "2008-06-30T17:32:38Z")

</div>

Hi Matthew,

Thank you very much for your excellent help.

First the good news: Your suggestion about requiring the configuration  
was spot on! So I’m a happy camper and will indeed make the post you  
requested at the end of your response.

While I plan to continue using the rspec gem for this current  
project, I’m very interested in using the two plug-ins you  
recommended on future projects. However, I wasn’t able to get rspec  
plug-in to install. Below are the steps I took to:

1. Get the rspec-rails plug-in installed
2. When that failed, try a different plug-in to show plug-in  
installation is working, generally.

I hope you can decipher my current error. Your unraveling my last  
error was neat!

Best wishes,  
Richard

[snip]\AIMS\_1\>gem uninstall rspec  
[OK]

[snip]\AIMS\_1\>ruby script/plugin discover  
[OK, but showed no dchelimsky]

[snip]\AIMS\_1\>ruby script/plugin source [dchelimsky (David Chelimsky) · GitHub](http://github.com/dchelimsky/)  
[OK]

[snip]\AIMS\_1\>ruby script/plugin install rspec-rails  
Plugin not found: [“rspec-rails”]

[snip]\AIMS\_1\>ruby script/plugin sources  
[http://dev.rubyonrails.com/svn/rails/plugins/](http://dev.rubyonrails.com/svn/rails/plugins/)

> **[dchelimsky - Overview](https://github.com/dchelimsky/)**
>
> dchelimsky has 109 repositories available. Follow their code on GitHub.

[http://svn.6brand.com/projects/plugins/](http://svn.6brand.com/projects/plugins/)

[snip]\ AIMS\_1\>ruby script/plugin install simple\_pages

- ./CHANGELOG
- ./README
- ./Rakefile
- ./app/controllers/simple\_pages\_controller.rb
- ./app/helpers/simple\_pages\_helper.rb
- ./app/models/simple\_page.rb  
[snip]

On Jun 29, 7:57 pm, Matthew R. Jacobs \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [July 1, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/second-question-on-using-rspec-for-a-simple-rails-2-0-app/141713/4 "2008-07-01T15:44:59Z")

</div>

On Mon, Jun 30, 2008 at 10:32 AM, RichardOnRails  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> project, I’m very interested in using the two plug-ins you  
> recommended on future projects. However, I wasn’t able to get rspec  
> plug-in to install.

Check out [Home · dchelimsky/rspec-rails Wiki · GitHub](http://github.com/dchelimsky/rspec-rails/wikis).

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [June 30, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/second-question-on-using-rspec-for-a-simple-rails-2-0-app/141713/5 "2008-06-30T17:37:15Z")

</div>

I have Rspec frozen in the plugins folder, so I know its the exact same  
version as the Rspec-Rails I’m using.  
Thought you might be able to freeze it by doing a “script/plugin  
install”,  
but clearly not.

But if its working for you, then don’t worry.

Enjoy some spec-ing.

Matthew R.

RichardOnRails wrote:

> Hi Matthew,
> 
> Thank you very much for your excellent help.
> 
> First the good news: Your suggestion about requiring the configuration  
> was spot on! So Iï¿½m a happy camper and will indeed make the post you  
> requested at the end of your response.

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [July 3, 2008, 7:40pm UTC](https://www.ruby-forum.com/t/second-question-on-using-rspec-for-a-simple-rails-2-0-app/141713/6 "2008-07-03T19:40:17Z")

</div>

Hi David,

Thanks for that source. I’ll try your plug-ins after the Fourth.

Best wishes,  
Richard
