我无法使用haml和rails6运行基本的rspec测试

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (286)

我开始了一个简单的项目,使用rails 6和haml-rails和rspec,我的基本测试在基本的get:home指向一个简单的haml模板失败 - 我真的不知道它是haml-rails,haml还是rspec问题。

我得到的错误

# rspec spec/controllers/static_pages_controller_spec.rb
DEPRECATION WARNING: Single arity template handlers are deprecated.  Template handlers must
now accept two parameters, the view object and the source for the view object.
Change:
  >> Class#call(template)
To:
  >> Class#call(template, source)
 (called from <top (required)> at /home/kuku/Projects/Permission/config/application.rb:22)
DEPRECATION WARNING: action_view.finalize_compiled_template_methods is deprecated and has no effect (called from <top (required)> at /home/kuku/Projects/Permission/config/environment.rb:7)
DEPRECATION WARNING: formats is deprecated and will be removed from Rails 6.1 (called from block (3 levels) in <top (required)> at /home/kuku/Projects/Permission/spec/controllers/static_pages_controller_spec.rb:8)
DEPRECATION WARNING: formats is deprecated and will be removed from Rails 6.1 (called from block (3 levels) in <top (required)> at /home/kuku/Projects/Permission/spec/controllers/static_pages_controller_spec.rb:8)
DEPRECATION WARNING: formats is deprecated and will be removed from Rails 6.1 (called from block (3 levels) in <top (required)> at /home/kuku/Projects/Permission/spec/controllers/static_pages_controller_spec.rb:8)
F

Failures:

  1) StaticPagesController GET #home returns http success
     Failure/Error: get :home

     ActionView::Template::Error:
       wrong number of arguments (given 2, expected 1)
     # ./spec/controllers/static_pages_controller_spec.rb:8:in `block (3 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # ArgumentError:
     #   wrong number of arguments (given 2, expected 1)
     #   ./spec/controllers/static_pages_controller_spec.rb:8:in `block (3 levels) in <top (required)>'

Finished in 0.01728 seconds (files took 0.9926 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/controllers/static_pages_controller_spec.rb:7 # StaticPagesController GET #home returns http success

我的测试 - get :home是第8行

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe StaticPagesController, type: :controller do
  describe 'GET #home' do
    it 'returns http success' do
      get :home
      expect(response).to have_http_status(:success)
    end
  end
end

我的控制器

class StaticPagesController < ApplicationController
  def home; end
end

routes.rb

Rails.application.routes.draw do
  root to: 'static_pages#home'
end

我试图使用来自master分支的haml-rails和haml,它似乎有一些rails6修复,但我得到的错误是相同的错误:

gem 'haml', github: 'haml/haml', branch: 'master'
gem 'haml-rails', github: 'indirect/haml-rails', branch: 'master'
提问于
用户回答回答于

我更新了rspec,现在它通过了 - 似乎rspec还没有为rails 6做好准备

gem 'rspec-rails', github: 'rspec/rspec-rails', branch: '4-0-dev' 
gem 'rspec', github: 'rspec/rspec', branch: 'master' 
gem 'rspec-core', github: 'rspec/rspec-core', branch: 'master' 
gem 'rspec-mocks', github: 'rspec/rspec-mocks', branch: 'master' 
gem 'rspec-expectations', github: 'rspec/rspec-expectations', branch: 'master' 
gem 'rspec-support', github: 'rspec/rspec-support', branch: 'master' 

扫码关注云+社区

领取腾讯云代金券