开始测试后出现Rspec错误

时间:2015-08-18 21:01:51

标签: ruby-on-rails ruby rspec

我尝试开始我的rspec测试,之后

RAILS_ENV=test bundle exec rspec

我得到了:

    /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:348:in `find_and_eval_shared': Could not find shared examples "template rend
ering action" (ArgumentError)
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:309:in `block (2 levels) in define_nested_shared_group_method'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:363:in `module_exec'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:363:in `subclass'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:254:in `block in define_example_group_method'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:308:in `block in define_nested_shared_group_method'
        from /home/nitrous/poznan-workshops-2015/spec/controllers/reports_controller_spec.rb:11:in `block (2 levels) in <top (required)>'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:363:in `module_exec'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:363:in `subclass'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:254:in `block in define_example_group_method'
        from /home/nitrous/poznan-workshops-2015/spec/controllers/reports_controller_spec.rb:8:in `block in <top (required)>'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:363:in `module_exec'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:363:in `subclass'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:254:in `block in define_example_group_method'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/dsl.rb:43:in `block in expose_example_group_alias'
        from /home/nitrous/poznan-workshops-2015/spec/controllers/reports_controller_spec.rb:3:in `<top (required)>'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/configuration.rb:1327:in `load'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/configuration.rb:1327:in `block in load_spec_files'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/configuration.rb:1325:in `each'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/configuration.rb:1325:in `load_spec_files'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/runner.rb:102:in `setup'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/runner.rb:88:in `run'
        from /home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/runner.rb:73:in `run'

我用谷歌搜索但没有找到解决方案。我注意到仅在模型上的rspec工作正常,但是当我想在控制器上启动时,我得到了同样的错误。 我需要的所有宝石都已正确安装。

1 个答案:

答案 0 :(得分:1)

没有ENV这是同一个故事。 我的reports_controller_spec.rb:

require 'rails_helper'

RSpec.describe ReportsController do
  let(:user) { create :user }

  before { sign_in user }

  describe 'GET #subjects' do
    subject { get :subjects }

    it_behaves_like 'template rendering action', :subjects
  end
end

我是规范测试的新手,我没有看到错误。那是reports_controller.rb。 Mayby会很有帮助。

class ReportsController < ApplicationController
  expose(:subject_items) { SubjectItem.includes(:teacher, :students) }
end