缺少模板关系/创建,应用/创建{:locale => [:en],:formats => [:js,:html],:handlers => [:erb,:builder,:coffee]}

时间:2013-03-02 15:08:34

标签: ruby-on-rails tdd railstutorial.org

我在使用Rspec的第11章遇到了railstutorial.org的问题。测试未通过。

RS-MBP:sample_app rsoutar$ bundle exec rspec spec/
No DRb server is running. Running in local process instead ...
Rack::File headers parameter replaces cache_control after Rack 1.5.
FFFF.......................................................................................................................................................

Failures:

  1) RelationshipsController creating a relationship with Ajax should increment the Relationship count
     Failure/Error: xhr :post, :create, relationship: { followed_id: other_user.id }
     ActionView::MissingTemplate:
       Missing template relationships/create, application/create with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
         * "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007fbd0c6b5910>"
     # ./app/controllers/relationships_controller.rb:7:in `create'
     # ./spec/controllers/relationships_controller_spec.rb:14:in `block (4 levels) in <top (required)>'
     # ./spec/controllers/relationships_controller_spec.rb:13:in `block (3 levels) in <top (required)>'

  2) RelationshipsController creating a relationship with Ajax should respond with success
     Failure/Error: xhr :post, :create, relationship: { followed_id: other_user.id }
     ActionView::MissingTemplate:
       Missing template relationships/create, application/create with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
         * "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007fbd0fce9310>"
     # ./app/controllers/relationships_controller.rb:7:in `create'
     # ./spec/controllers/relationships_controller_spec.rb:19:in `block (3 levels) in <top (required)>'

  3) RelationshipsController destroying a relationship with Ajax should decrement the Relationship count
     Failure/Error: xhr :delete, :destroy, id: relationship.id
     ActionView::MissingTemplate:
       Missing template relationships/destroy, application/destroy with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
         * "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007fbd0ff07d68>"
     # ./app/controllers/relationships_controller.rb:16:in `destroy'
     # ./spec/controllers/relationships_controller_spec.rb:31:in `block (4 levels) in <top (required)>'
     # ./spec/controllers/relationships_controller_spec.rb:30:in `block (3 levels) in <top (required)>'

  4) RelationshipsController destroying a relationship with Ajax should respond with success
     Failure/Error: xhr :delete, :destroy, id: relationship.id
     ActionView::MissingTemplate:
       Missing template relationships/destroy, application/destroy with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
         * "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007fbd0fc5c460>"
     # ./app/controllers/relationships_controller.rb:16:in `destroy'
     # ./spec/controllers/relationships_controller_spec.rb:36:in `block (3 levels) in <top (required)>'

Finished in 9.88 seconds
155 examples, 4 failures

Failed examples:

rspec ./spec/controllers/relationships_controller_spec.rb:12 # RelationshipsController creating a relationship with Ajax should increment the Relationship count
rspec ./spec/controllers/relationships_controller_spec.rb:18 # RelationshipsController creating a relationship with Ajax should respond with success
rspec ./spec/controllers/relationships_controller_spec.rb:29 # RelationshipsController destroying a relationship with Ajax should decrement the Relationship count
rspec ./spec/controllers/relationships_controller_spec.rb:35 # RelationshipsController destroying a relationship with Ajax should respond with success
RS-MBP:sample_app rsoutar$

这是Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.12'
gem 'bootstrap-sass', '2.1'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.4'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'coffee-rails', '~> 3.2.2'
gem 'uglifier', '>= 1.2.3'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :development, :test do
    gem 'sqlite3', '1.3.5'
    gem 'rspec-rails', '2.11.0'
    gem 'guard-rspec', '1.2.1'
    gem 'guard-spork', :github => 'guard/guard-spork'
    gem 'spork', '0.9.2'
    gem 'childprocess', '0.3.6'
end

group :development do
    gem 'annotate', '2.5.0'
end


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.5'


  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

end

gem 'jquery-rails'

group :test do
    gem 'capybara', '1.1.2'
    gem 'rb-fsevent', '0.9.1', :require => false
    gem 'growl', '1.0.3'
    gem 'factory_girl_rails', '4.1.0'
    gem 'database_cleaner', '0.7.0'
end

group :production do
    gem 'pg', '0.12.2'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

这是relationship_controller_spec.rb

require 'spec_helper'

describe RelationshipsController do

  let(:user) { FactoryGirl.create(:user) }
  let(:other_user) { FactoryGirl.create(:user) }

  before { sign_in user }

  describe "creating a relationship with Ajax" do

    it "should increment the Relationship count" do
      expect do
        xhr :post, :create, relationship: { followed_id: other_user.id }
      end.to change(Relationship, :count).by(1)
    end

    it "should respond with success" do
      xhr :post, :create, relationship: { followed_id: other_user.id }
      response.should be_success
    end
  end

  describe "destroying a relationship with Ajax" do

    before { user.follow!(other_user) }
    let(:relationship) { user.relationships.find_by_followed_id(other_user) }

    it "should decrement the Relationship count" do
      expect do
        xhr :delete, :destroy, id: relationship.id
      end.to change(Relationship, :count).by(-1)
    end

    it "should respond with success" do
      xhr :delete, :destroy, id: relationship.id
      response.should be_success
    end
  end
end

这是关系控制器

class RelationshipsController < ApplicationController
  before_filter :signed_in_user

  def create
    @user = User.find(params[:relationship][:followed_id])
    current_user.follow!(@user)
    respond_to do |format|
      format.html { redirect_to @user }
      format.js
    end
  end

  def destroy
    @user = Relationship.find(params[:id]).followed
    current_user.unfollow!(@user)
    respond_to do |format|
      format.html { redirect_to @user }
      format.js
    end
  end
end

我不知道我还应该在这个问题中加入什么。

谢谢。

1 个答案:

答案 0 :(得分:0)

结果我缺少create.js.erb和destroy.js.erb这就是为什么我得到了Missing模板关系/错误

感谢您的帮助。 :)