ruby on rails - Failure/Error: response.should render_template(:new) expecting <"new"> but rendering with <""> -


posts_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 = post.new   end end 

spec_helper.rb

# file copied spec/ when 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 custom matchers , macros, etc, # in spec/support/ , subdirectories. dir[rails.root.join("spec/support/**/*.rb")].each {|f| require f}  rspec.configure |config|   config.mock_with :rspec    # remove line if you're not using activerecord or activerecord fixtures   config.fixture_path = "#{::rails.root}/test/fixtures"    config.before(:suite)     databasecleaner.strategy = :truncation   end    config.after(:suite)     databasecleaner.clean   end    # if you're not using activerecord, or you'd prefer not run each of   # examples within transaction, remove 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   fixtures :all   include devise::testhelpers   render_views    before(:each)     databasecleaner.strategy = :truncation     databasecleaner.start   end    after(:each)     databasecleaner.clean   end   "new action should render new template"     :new     response.should render_template(:new)   end end 

ruby 1.8.7, rspec 2.11, rails 3.2.19

i error expecting <"new"> rendering <""> how can pass case ... tried many suggestions didnt success .. please stuck ... :(

note: cant change code of controller

# use sign_in helper sign in fixture `user` record. user = users(:one)  @request.env['warden'].stub(:authenticate!).and_return(user) @controller.stub(:current_user).and_return(user)  :new assert_template 'new' 

this works me using https://github.com/plataformatec/devise/wiki/how-to:-stub-authentication-in-controller-specs , thanx @Зелёный direction :)


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -