Skip to content

Fix failing inspect call in case of failing spec

Patrick Derichs requested to merge fix-base-service-inspect-pd into master

What does this MR do?

Occurred in !31451 (merged).

Fixes output of spec failures like https://gitlab.com/gitlab-org/gitlab/-/jobs/549000059:

 Failures:
   1) MergeRequests::UpdateService execute valid params executes hooks with update action
      Failure/Error: "#<#{self.class} #{merge_request.to_reference(full: true)}>"
      NameError:
        undefined local variable or method `merge_request' for #<MergeRequests::UpdateService:0x0000560798ebc990>
        Did you mean?  merge_requests_for
      # ./app/services/merge_requests/base_service.rb:42:in `inspect'
      # ./vendor/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/error_generator.rb:230:in `intro'
      # ./vendor/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/error_generator.rb:72:in `default_error_message'
      # ./vendor/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/error_generator.rb:271:in `error_message'
      # ./vendor/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/error_generator.rb:55:in `raise_unexpected_message_args_error'
      # ./vendor/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/message_expectation.rb:506:in `raise_unexpected_message_args_error'
      # ./vendor/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/proxy.rb:122:in `block in check_for_unexpected_arguments'
      # ./vendor/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/proxy.rb:111:in `synchronize'
      # ./vendor/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/proxy.rb:111:in `check_for_unexpected_arguments'
      # ./vendor/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/matchers/have_received.rb:119:in `notify_failure_message'
      # ./vendor/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/matchers/have_received.rb:114:in `block in capture_failure_message'
      # ./vendor/ruby/2.6.0/gems/rspec-support-3.9.2/lib/rspec/support.rb:113:in `with_failure_notifier'
      # ./vendor/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/matchers/have_received.rb:113:in `capture_failure_message'
      # ./vendor/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/matchers/have_received.rb:41:in `failure_message'
      # ./vendor/ruby/2.6.0/gems/rspec-expectations-3.9.1/lib/rspec/expectations/handler.rb:35:in `handle_failure'
      # ./vendor/ruby/2.6.0/gems/rspec-expectations-3.9.1/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'
      # ./vendor/ruby/2.6.0/gems/rspec-expectations-3.9.1/lib/rspec/expectations/handler.rb:27:in `with_matcher'
      # ./vendor/ruby/2.6.0/gems/rspec-expectations-3.9.1/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
      # ./vendor/ruby/2.6.0/gems/rspec-expectations-3.9.1/lib/rspec/expectations/expectation_target.rb:65:in `to'
      # ./spec/services/merge_requests/update_service_spec.rb:87:in `block (4 levels) in <top (required)>'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:257:in `instance_exec'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:257:in `block in run'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:503:in `block in with_around_and_singleton_context_hooks'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:460:in `block in with_around_example_hooks'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/hooks.rb:472:in `block in run'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/hooks.rb:612:in `block in run_around_example_hooks_for'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:345:in `call'
      # ./vendor/ruby/2.6.0/gems/rspec-rails-4.0.0/lib/rspec/rails/adapters.rb:75:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:450:in `instance_exec'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:450:in `instance_exec'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/hooks.rb:381:in `execute_with'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/hooks.rb:614:in `block (2 levels) in run_around_example_hooks_for'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:345:in `call'
      # ./spec/spec_helper.rb:306:in `block (3 levels) in <top (required)>'
      # ./vendor/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/testing.rb:55:in `server_middleware'
      # ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
      # ./spec/spec_helper.rb:297:in `block (2 levels) in <top (required)>'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:450:in `instance_exec'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:450:in `instance_exec'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/hooks.rb:381:in `execute_with'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/hooks.rb:614:in `block (2 levels) in run_around_example_hooks_for'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:345:in `call'
      # ./spec/spec_helper.rb:293:in `block (3 levels) in <top (required)>'
      # ./vendor/ruby/2.6.0/gems/gitlab-labkit-0.12.0/lib/labkit/context.rb:32:in `with_context'
      # ./spec/spec_helper.rb:293:in `block (2 levels) in <top (required)>'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:450:in `instance_exec'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:450:in `instance_exec'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/hooks.rb:381:in `execute_with'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/hooks.rb:614:in `block (2 levels) in run_around_example_hooks_for'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:345:in `call'
      # ./vendor/ruby/2.6.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:123:in `block in run'
      # ./vendor/ruby/2.6.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:110:in `loop'
      # ./vendor/ruby/2.6.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:110:in `run'
      # ./vendor/ruby/2.6.0/gems/rspec-retry-0.6.1/lib/rspec_ext/rspec_ext.rb:12:in `run_with_retry'
      # ./vendor/ruby/2.6.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:37:in `block (2 levels) in setup'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:450:in `instance_exec'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:450:in `instance_exec'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/hooks.rb:381:in `execute_with'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/hooks.rb:614:in `block (2 levels) in run_around_example_hooks_for'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:345:in `call'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/hooks.rb:615:in `run_around_example_hooks_for'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/hooks.rb:472:in `run'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:460:in `with_around_example_hooks'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:503:in `with_around_and_singleton_context_hooks'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example.rb:254:in `run'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example_group.rb:633:in `block in run_examples'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example_group.rb:629:in `map'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example_group.rb:629:in `run_examples'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example_group.rb:595:in `run'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example_group.rb:596:in `block in run'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example_group.rb:596:in `map'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example_group.rb:596:in `run'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example_group.rb:596:in `block in run'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example_group.rb:596:in `map'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/example_group.rb:596:in `run'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/runner.rb:121:in `block (3 levels) in run_specs'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/runner.rb:121:in `map'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/runner.rb:121:in `block (2 levels) in run_specs'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/configuration.rb:2031:in `with_suite_hooks'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/runner.rb:116:in `block in run_specs'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/reporter.rb:74:in `report'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/runner.rb:115:in `run_specs'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/runner.rb:89:in `run'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/runner.rb:71:in `run'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/lib/rspec/core/runner.rb:45:in `invoke'
      # ./vendor/ruby/2.6.0/gems/rspec-core-3.9.1/exe/rspec:4:in `<top (required)>'
      # ./vendor/ruby/2.6.0/bin/rspec:23:in `load'
      # ./vendor/ruby/2.6.0/bin/rspec:23:in `<top (required)>'
      # /usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:74:in `load'
      # /usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:74:in `kernel_load'
      # /usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:28:in `run'
      # /usr/local/lib/ruby/2.6.0/bundler/cli.rb:463:in `exec'
      # /usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
      # /usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
      # /usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
      # /usr/local/lib/ruby/2.6.0/bundler/cli.rb:27:in `dispatch'
      # /usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
      # /usr/local/lib/ruby/2.6.0/bundler/cli.rb:18:in `start'
      # /usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:30:in `block in <top (required)>'
      # /usr/local/lib/ruby/2.6.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
      # /usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:22:in `<top (required)>'
      # /usr/local/bin/bundle:23:in `load'
      # /usr/local/bin/bundle:23:in `<main>'
 Finished in 10 minutes 50 seconds (files took 39.84 seconds to load)
 1780 examples, 1 failure, 7 pending
 Failed examples:
 rspec ./spec/services/merge_requests/update_service_spec.rb:86 # MergeRequests::UpdateService execute valid params executes hooks with update action

with this fix:

#<MergeRequests::UpdateService received :execute_hooks with unexpected arguments
  expected: (#<MergeRequest id:2 group2/project2!1>, "update", {:old_associations=>{:assignees=>[#<User id:11 @user11>], :description=>"FYI @user10", :labels=>[], :mentioned_users=>[#<User id:10 @user10>], :missing_value=>0, :total_time_spent=>0}})
       got: (#<MergeRequest id:2 group2/project2!1>, "update", {:old_associations=>{:assignees=>[#<User id:11 @user11>], :description=>"FYI @user10", :labels=>[], :mentioned_users=>[#<User id:10 @user10>], :total_time_spent=>0}})
Diff:
@@ -5,6 +5,5 @@
     :description=>"FYI @user10",
     :labels=>[],
     :mentioned_users=>[#<User id:10 @user10>],
-    :missing_value=>0,
     :total_time_spent=>0}}]


  0) MergeRequests::UpdateService execute valid params executes hooks with update action
     Failure/Error:
       expect(service).to have_received(:execute_hooks)
         .with(
           @merge_request,
           'update',
           old_associations: {
             labels: [],
             mentioned_users: [user2],
             assignees: [user3],
             total_time_spent: 0,
             missing_value: 0,

       #<MergeRequests::UpdateService received :execute_hooks with unexpected arguments
         expected: (#<MergeRequest id:2 group2/project2!1>, "update", {:old_associations=>{:assignees=>[#<User id:11 @user11>], :description=>"FYI @user10", :labels=>[], :mentioned_users=>[#<User id:10 @user10>], :missing_value=>0, :total_time_spent=>0}})
              got: (#<MergeRequest id:2 group2/project2!1>, "update", {:old_associations=>{:assignees=>[#<User id:11 @user11>], :description=>"FYI @user10", :labels=>[], :mentioned_users=>[#<User id:10 @user10>], :total_time_spent=>0}})
       Diff:
       @@ -5,6 +5,5 @@
            :description=>"FYI @user10",
            :labels=>[],
            :mentioned_users=>[#<User id:10 @user10>],
       -    :missing_value=>0,
            :total_time_spent=>0}}]
     # ./spec/services/merge_requests/update_service_spec.rb:87:in `block (4 levels) in <main>'
     # ./spec/spec_helper.rb:306:in `block (3 levels) in <main>'
     # ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
     # ./spec/spec_helper.rb:297:in `block (2 levels) in <main>'
     # ./spec/spec_helper.rb:293:in `block (3 levels) in <main>'
     # ./spec/spec_helper.rb:293:in `block (2 levels) in <main>'
     # -e:1:in `<main>'

Used patch for local test:

diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb
index 8c1800c495f..cadfbd0fe95 100644
--- a/spec/services/merge_requests/update_service_spec.rb
+++ b/spec/services/merge_requests/update_service_spec.rb
@@ -93,6 +93,7 @@ describe MergeRequests::UpdateService, :mailer do
               mentioned_users: [user2],
               assignees: [user3],
               total_time_spent: 0,
+              missing_value: 0,
               description: "FYI #{user2.to_reference}"
             }
           )

MergeRequests::UpdateService does not seem to have any merge_request method:

[22] pry(main)> i = MergeRequests::UpdateService.new(u)
=> #<MergeRequests::UpdateService
[23] pry(main)> i.methods(true).select { |m| m.to_s.include?("merge_request") }
=> [:pipeline_merge_requests, :merge_request_metrics_service, :can_use_merge_request_ref?, :merge_requests_for]
[24] pry(main)> i.private_methods(true).select { |m| m.to_s.include?("merge_request") }
=> [:blocking_merge_requests_params, :blocking_merge_requests_params=]
[25] pry(main)> i.public_methods(true).select { |m| m.to_s.include?("merge_request") }
=> [:pipeline_merge_requests, :merge_request_metrics_service, :can_use_merge_request_ref?, :merge_requests_for]

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by 🤖 GitLab Bot 🤖

Merge request reports

Loading