使用Rails和Rspec的“parallel_tests”gem和我的模型的测试运行正常,但我的控制器测试失败

时间:2017-01-11 17:51:26

标签: ruby-on-rails testing rspec

我正在尝试使用“parallel_tests”gem https://github.com/grosser/parallel_tests和我的Rspec测试。我的模型很好用。但是对于我的大多数控制器,它给了我错误。虽然Rspec仍然正常运行 - 没有错误。

测试示例:

require 'rails_helper'

describe Dashboard::GaugesController, :type => :controller do
  let!(:team) { create(:team) }
  let!(:user) { create(:user, selected_team: team, :slackid => 'SLACKID1') }
  let!(:team_user_admin) { create(:team_user, team: team, user: user, role: :admin) }

  describe 'with auth user' do
    before { sign_in user }
    describe 'GET /' do
      specify 'open gauges page' do
        get :index
        expect(response).to have_http_status(:ok)
        expect(response).to render_template(:index)
      end
    end
  end
end

使用并行gem运行rspec时出错:

rake parallel:spec[^spec/controllers/dashboard/gauges_controllers_spec.rb]                                                                                                              [ruby-2.2.3@wyzyr]
Using recorded test runtime
1 processes for 1 specs, ~ 1 specs per process
F

Failures:

  1) Dashboard::GaugesController with auth user GET / open gauges page
     Failure/Error: expect(response).to have_http_status(:ok)
       expected the response to have status code :ok (200) but it was :found (302)
     # ./spec/controllers/dashboard/gauges_controllers_spec.rb:13:in `block (4 levels) in <top (required)>'

Finished in 0.46955 seconds (files took 5.43 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/controllers/dashboard/gauges_controllers_spec.rb:11 # Dashboard::GaugesController with auth user GET / open gauges page

Rspec结果:

rspec ./spec/controllers/dashboard/gauges_controllers_spec.rb                                                                                                                           [ruby-2.2.3@wyzyr]
.

Finished in 0.53304 seconds (files took 5.25 seconds to load)
1 example, 0 failures

任何建议在哪里挖掘将非常感谢!谢谢!

1 个答案:

答案 0 :(得分:-1)

parallel_tests gem的创始人帮助我们解决了这个问题。 https://github.com/grosser/parallel_tests/issues/548

parallel_rspec spec正常运行。

  嗯,所以也许是因为耙子启动环境并设置了一些ENV变量?   ...现在关闭,但如果你找出未来用户遇到麻烦的原因,请报告回来:))

如果您遇到类似的问题,请点击@grosser并发现更多内容。