【问题标题】:rspec doesn't run first test caserspec 不运行第一个测试用例
【发布时间】:2016-12-21 10:08:28
【问题描述】:

#update 块没有运行。为什么?如何更改它以运行所有这些。 #anything 工作正常。

describe UsersController, type: :controller do
  login_admin

  describe '#update' do
    def user_update_params(roles:)
      {
        role_ids: roles.map(&:id),
        name: 'new'
      }
    end

    shared_examples_for 'update user' do
      it 'change the user' do
        expect do
          put :update, id: user.id, user: user_params
        end.to change { user.reload.name }
      end
    end
  end

  describe '#anything' do
    it 'is ok' do
      #runs ok
    end
  end
end

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 rspec rspec-rails


    【解决方案1】:

    这是一个共享示例,而不是真正的测试。它应该包含在其他测试组中。像这样:

      describe '#whatever' do
        it_behaves_like 'update user'
    
        it 'runs shared example' do
        end
      end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-21
      • 2015-05-12
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多