gpt4 book ai didi

ruby-on-rails - Rails rspec 未定义的局部变量或方法 `render_views'

转载 作者:行者123 更新时间:2023-12-04 16:24:51 24 4
gpt4 key购买 nike

运行 rspec 时,我得到:

C:/www/kill/spec/games_controller_spec.rb:4:in block in <top
(required)>': undefined local variable or method
render_views'



games_controller_spec.rb
require 'spec_helper'

describe GamesController, "creating a new game" do
render_views
fixtures :games

it "should redirect to index with a notice on successful save" do
Game.any_instance.stubs(:valid?).returns(true)
post 'create'
assigns[:game].should_not be_new_record
flash[:notice].should_not be_nil
response.should redirect_to(menu_items_path)
end
end

spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
#config.mock_with :rspec

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true

# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
end

gem :

C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-2.7.0

C:/Ruby192/lib/ruby/gems/1.9.1/gems/mocha-0.10.0

最佳答案

您的 Controller 规范应该在 spec/controllers/ 中文件夹。但是,出于某种原因,您可能希望拥有其他一些运行 Controller 规范的文件(例如,我正在一个单独的测试文件中测试标记验证)。

你可以这样做 :

describe GamesController, "creating a new game", :type => :controller do

这应该可以解决问题!

关于ruby-on-rails - Rails rspec 未定义的局部变量或方法 `render_views',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8029137/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com