小编Jac*_*cob的帖子

RSpec - @controller是零

我有一个非常基本的RoR网站,需要开始为它编写一些RSpec测试.我有一个"关于"页面,不需要登录用户,并由我的PagesController控制.从浏览器运行时,about页面效果很好.我试图简单地尝试测试它,就像在RoR教程中那样.

我正在使用Rails 3,RSpec 2.7.0,Windows

pages_controller.rb:

class PagesController < ApplicationController
    def about
    end
end
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

对于它的价值,这是我的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
Run Code Online (Sandbox Code Playgroud)

但是当我进行测试时,我得到:

Failures:

1) PagesController GET 'about' should be successful
  Failure/Error: get 'about' …
Run Code Online (Sandbox Code Playgroud)

controller rspec ruby-on-rails

9
推荐指数
1
解决办法
6218
查看次数

标签 统计

controller ×1

rspec ×1

ruby-on-rails ×1