The Construction of an Explorer

Adding rspec to your rails app | September 22, 2010

group :development do
gem ‘rspec-rails’, ’2.0.0.beta.18′
end
group :test do
gem ‘rspec’, ’2.0.0.beta.18′
end
save gemfile
do “bundle install” in terminal or command line
to use rspec instead of rails default test::unit you have to:
rails generate rspec:install
if you are using git you can remove the tests for views and helpers
git rm -r spec/helpers
git rm -r spec/views
rspec spec/:
rspec runs the program and spec/ runs the particular directory.
rspec results come green and red.  green means the test passes while red means it fails.
TTD writes a failing test first to make sure we are testing for the right thing.
describe “GET ‘about’” do
it “should be successful” do
get ‘about’
response.should be_success
end
end
the first line will be the REST function for the about page.  the 2nd line will be what is spit back out.  the third line will get that page, and the 4th line is the method performed in the test.
“render_views” must be added to test the views along with the controller.
this test should fail because there is no about page.
Advertisement

Follow

Get every new post delivered to your Inbox.