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

时间:2019-04-07 11:28:47

标签: ruby-on-rails rspec haml

我用rails 6和haml-rails和rspec开始了一个简单的项目,我的基本测试在基本的get上失败了:指向一个简单的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'

任何我可能会尝试的建议,或者是否有任何简单的方法可以从rails-haml回滚到erb?

1 个答案:

答案 0 :(得分:1)

我更新了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'