1
posts_controller.rb失敗/エラー:response.should render_template(新しい)<"new">を期待したが<"">
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
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 '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
posts_controller_spec.rbでレンダリング
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
私はが<「新しい」期待し、このエラーを取得します>が、私はこのような場合は...私は多くの提案を試みたが、いずれかの成功を得るdidntは渡すことができますどのように..助けてくださいAmが立ち往生>「」<でレンダリングそれに... :(
注:私はこれは私がhttps://github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specsを使用すると、@Зелёныありがとう働くコントローラのコード
のためにあなたは、アクション 'new'、' before_filterをユーザーに許可していない[:ショーを、:インデックス] '。 –
@Зелёныйには何か回避策がありますか? –
明らかに、ユーザーの承認を得ています。 –