Ruby on rails 失败/错误:response.should呈现_模板(:new)预期(<&引用;新"&燃气轮机;但是使用<&引用&引用&燃气轮机;
posts\u controller.rbRuby on rails 失败/错误:response.should呈现_模板(:new)预期(<&引用;新"&燃气轮机;但是使用<&引用&引用&燃气轮机;,ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,posts\u controller.rb class PostsController < ApplicationController respond_to :html, :xml, :json before_filter :authenticate_user!, :except => [:show, :index] before_filter :admin_only, :except => [:show, :index] def new @post
class PostsController < ApplicationController
respond_to :html, :xml, :json
before_filter :authenticate_user!, :except => [:show, :index]
before_filter :admin_only, :except => [:show, :index]
def new
@post = Post.new
end
end
# 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 'forgery'
require 'populators'
# 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|
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/test/fixtures"
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.after(:suite) do
DatabaseCleaner.clean
end
# 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 = false
end
require File.dirname(__FILE__) + '/../spec_helper'
describe PostsController do
fixtures :all
include Devise::TestHelpers
render_views
before(:each) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.start
end
after(:each) do
DatabaseCleaner.clean
end
it "new action should render new template" do
get :new
response.should render_template(:new)
end
end
发布控制器规范rb
class PostsController < ApplicationController
respond_to :html, :xml, :json
before_filter :authenticate_user!, :except => [:show, :index]
before_filter :admin_only, :except => [:show, :index]
def new
@post = Post.new
end
end
# 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 'forgery'
require 'populators'
# 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|
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/test/fixtures"
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.after(:suite) do
DatabaseCleaner.clean
end
# 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 = false
end
require File.dirname(__FILE__) + '/../spec_helper'
describe PostsController do
fixtures :all
include Devise::TestHelpers
render_views
before(:each) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.start
end
after(:each) do
DatabaseCleaner.clean
end
it "new action should render new template" do
get :new
response.should render_template(:new)
end
end
ruby 1.8.7、rspec 2.11、Rails 3.2.19
我收到此错误预期,但使用渲染如何通过此案例。。。我尝试了许多建议,但没有成功。。请帮我解决这个问题…:(
注意:我无法更改控制器的代码
# Use the sign_in helper to sign in a fixture `User` record.
user = users(:one)
@request.env['warden'].stub(:authenticate!).and_return(user)
@controller.stub(:current_user).and_return(user)
get :new
assert_template 'new'
这对我来说很有用,而thanx@ёёыы为方向:)
这对我来说是有效的,使用thanx@3aöёыыыыы为指示:)在过滤:验证用户之前,您不授权用户执行操作
新建,:Exception=>[:show,:index]
@X3ёыы有什么解决办法吗?很明显,要为用户授权。很抱歉,我是新用户,好的,让我试试。检查此项。您没有为用户授权操作新建
,在过滤之前:验证用户!,:Exception=>[:show,:index]
@X3ёёы有什么解决办法吗?很明显,为用户进行授权。很抱歉,我是新来的,好的,让我试试。检查一下