SD Ruby,
Over the holidays I embarked on a long-needed upgrade of the first Rails app I built, taking it from 2.3 to 3.1. I plan to move it to 4.0 by the time I'm done.
Since this app was created over 6 years ago, before I understood the value of having test coverage, it has very little. I've been remedying that via RSpec (2.14) and FactoryGirl and I'm pleased with the progress I've made and even discovered some bugs that weren't apparent pre-test.
The app is rather large and I need to get this upgrade done quickly since my customers are clamoring for more features. I'm trying to balance basic "sanity checking" test coverage with the need for speed.
I use simple_navigation to provide the links between the main menus and controller actions. I thought it would be worthwhile to gin-up a bunch of request specs for the URLs that the menu links hit. It seemed to me I'd at least have a basic "does the page for that menu link blow up?" scenario as a rudimentary check of the app. But that doesn't seem to work the way I expected.
For example, hitting a URL via a request spec and checking for a 200 status passes. But if I go to that same page in the browser I find vestiges of rails 2.3 that have been removed, like "error_messages_for" and the page throws an error.
So I'm getting a false positive on the request spec -- how come? Perhaps my understanding of what a request spec provides is flawed but I assumed an error in the page wouldn't allow the spec to pass.
My next attempt was to create controller specs for the controllers hit by the menus. I use a before_filter in application_controller to set the current chapter and in trying to check that value is assigned isn't working.
In the snippet below MemberController < ApplicationController. The expect fails because the assigns(:chapter) returns nil.
require 'spec_helper'
describe MemberController do
before :each do
@chapter = FactoryGirl.create(:chapter)
controller.stub!(:current_chapter).and_return(@chapter)
end
describe "GET my_home" do
it "assigns @chapter" do
get :my_home
expect(assigns(:chapter)).to eq @chapter
end
end
end
I'm a n00bie with RSpec so perhaps my understanding is flawed. How should this be setup? Is there a better way?
Thanks,
Chris