2016-11-10 101 views
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

我得到这个错误期待<“新”>但是<“”渲染>我怎么能通过这种情况下......我尝试了许多建议,但没有得到任何成功..请帮助我坚持它... :(

注:我不能改变控制器

+0

您不授权用户操作'new',''before_filter:authenticate_user !,:except => [:show,:index]'。 –

+0

@Зелёный没有任何解决办法呢? –

+0

这是很明显,使用户的授权。 –

回答

相关问题