Reputation: 91
I've got a very basic RoR website and need to start writing some RSpec tests for it. I have an 'about' page that doesn't require a logged-in user, and is controlled by my PagesController. The about page works great when run from a browser. I am trying to simply trying to test that, kind of like in the RoR Tutorial.
I'm using Rails 3, RSpec 2.7.0, Windows
pages_controller.rb:
class PagesController < ApplicationController
def about
end
end
pages_controller_spec.rb:
require 'spec_helper'
describe "PagesController" do
describe "GET 'about'" do
render_views
it "should be successful" do
get 'about'
response.should be_success
end
end
end
For what it's worth, here's my spec_helper.rb:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.include RSpec::Rails::ControllerExampleGroup
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
end
But when I run the test, I get:
Failures:
1) PagesController GET 'about' should be successful
Failure/Error: get 'about'
RuntimeError:
@controller is nil: make sure you set it in your test's setup method.
# ./spec/controllers/pages_controller_spec.rb:12:in `block (3 levels) in <top (required)>'
Any help appreciated. I know this has to be an easy one! Thanks!! Jacob
Upvotes: 9
Views: 7651
Reputation: 20724
Try to change
describe "PagesController" do
to
describe PagesController do
Upvotes: 42