-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minitest/GlobalExpectations
triggers google-cloud-storage unit test failures
#68
Comments
First of all, Thanks for your feedback! As far as I've investigated, I think Minitest warnings cannot be fixed with simple substitutions. it "raises when creating a bucket without authentication" do
+ p self.class.to_s #=> "Google::Cloud::Storage::Project::anonymous::mock_storage"
+ p self.respond_to?(:_) #=> true
+ p self.method(:_).owner #=> Minitest::Spec::DSL::InstanceMethods
stub = Object.new
def stub.insert_bucket *args
+ p self.class.to_s #=> "Object"
+ p self.respond_to?(:_) #=> false
args.first.must_be_nil # project
raise Google::Apis::AuthorizationError.new("unauthorized", status_code: 401)
end There are several possible approaches for the issue.
I think the former is realistic. diff --git a/google-cloud-storage/test/google/cloud/storage/project_anonymous_test.rb b/google-cloud-storage/test/google/cloud/storage/project_anonymous_test.rb
index 2767f361f..5fe3c3e35 100644
--- a/google-cloud-storage/test/google/cloud/storage/project_anonymous_test.rb
+++ b/google-cloud-storage/test/google/cloud/storage/project_anonymous_test.rb
@@ -20,7 +20,7 @@ describe Google::Cloud::Storage::Project, :anonymous, :mock_storage do
let(:anonymous_storage) { Google::Cloud::Storage.anonymous }
it "raises when creating a bucket without authentication" do
- stub = Object.new
+ stub = self
def stub.insert_bucket *args
_(args.first).must_be_nil # project
raise Google::Apis::AuthorizationError.new("unauthorized", status_code: 401)
@@ -31,7 +31,7 @@ describe Google::Cloud::Storage::Project, :anonymous, :mock_storage do
end
it "raises when listing buckets without authentication" do
- stub = Object.new
+ stub = self
def stub.list_buckets *args
_(args.first).must_be_nil # project
raise Google::Apis::AuthorizationError.new("unauthorized", status_code: 401) Either way, I think it's difficult to solve with RuboCop Minitest. Thank you. |
Thanks for the deep investigation. Agreed that these two failures should be addressed by google-cloud-storage gem or minitest. |
…/storage/project_anonymous_test.rb` Because object of `Object` class does not have `_` method defined It is owned by `Minitest::Spec::DSL::InstanceMethods`. Refer rubocop/rubocop-minitest#68 (comment) ``` % bundle exec ruby -w -Itest test/google/cloud/storage/project_anonymous_test.rb -n /test_0001_raises\|test_0002_raises/ ... snip ... FF Finished in 0.002656s, 753.0120 runs/s, 753.0120 assertions/s. 1) Failure: Google::Cloud::Storage::Project::anonymous::mock_storage#test_0002_raises when listing buckets without authentication [test/google/cloud/storage/project_anonymous_test.rb:41]: [Google::Cloud::UnauthenticatedError] exception expected, not Class: <NoMethodError> Message: <"undefined method `_' for #<Object:0x00007fae26010460>"> ---Backtrace--- test/google/cloud/storage/project_anonymous_test.rb:36:in `list_buckets' /Users/yahonda/src/github.com/googleapis/google-cloud-ruby/google-cloud-storage/lib/google/cloud/storage/service.rb:76:in `block in list_buckets' /Users/yahonda/src/github.com/googleapis/google-cloud-ruby/google-cloud-storage/lib/google/cloud/storage/service.rb:631:in `execute' /Users/yahonda/src/github.com/googleapis/google-cloud-ruby/google-cloud-storage/lib/google/cloud/storage/service.rb:75:in `list_buckets' /Users/yahonda/src/github.com/googleapis/google-cloud-ruby/google-cloud-storage/lib/google/cloud/storage/project.rb:153:in `buckets' test/google/cloud/storage/project_anonymous_test.rb:41:in `block (3 levels) in <main>' --------------- 2) Failure: Google::Cloud::Storage::Project::anonymous::mock_storage#test_0001_raises when creating a bucket without authentication [test/google/cloud/storage/project_anonymous_test.rb:30]: [Google::Cloud::UnauthenticatedError] exception expected, not Class: <NoMethodError> Message: <"undefined method `_' for #<Object:0x00007fae658703c8>"> ---Backtrace--- test/google/cloud/storage/project_anonymous_test.rb:25:in `insert_bucket' /Users/yahonda/src/github.com/googleapis/google-cloud-ruby/google-cloud-storage/lib/google/cloud/storage/service.rb:98:in `block in insert_bucket' /Users/yahonda/src/github.com/googleapis/google-cloud-ruby/google-cloud-storage/lib/google/cloud/storage/service.rb:631:in `execute' /Users/yahonda/src/github.com/googleapis/google-cloud-ruby/google-cloud-storage/lib/google/cloud/storage/service.rb:97:in `insert_bucket' /Users/yahonda/src/github.com/googleapis/google-cloud-ruby/google-cloud-storage/lib/google/cloud/storage/project.rb:379:in `create_bucket' test/google/cloud/storage/project_anonymous_test.rb:30:in `block (3 levels) in <main>' --------------- 2 runs, 2 assertions, 2 failures, 0 errors, 0 skips % ``` 2 Revert false positives of `google-cloud-storage/test/google/cloud/storage/project_anonymous_test.rb ``` % bundle exec ruby -w -Itest test/google/cloud/storage/project_anonymous_test.rb -n /test_0006_downloads/ ... snip ... 1) Failure: Google::Cloud::Storage::Project::anonymous::mock_storage#test_0006_downloads a public file [test/google/cloud/storage/project_anonymous_test.rb:125]: Expected #<Tempfile:/var/folders/4d/1hfsdkkj2772brj5d70vtbm40000gn/T/google-cloud20200410-6349-nvppgj> to be a kind of File, not Tempfile. 1 runs, 1 assertions, 1 failures, 0 errors, 0 skips % ``` * Reverting auto-correct generates these warnings as expected. ``` DEPRECATED: global use of must_be_kind_of from /Users/yahonda/.rbenv/versions/2.6.6/lib/ruby/2.6.0/delegate.rb:83. Use _(obj).must_be_kind_of instead. This will fail in Minitest 6. ```
Follow up #65 (comment)
Expected behavior
Minitest/GlobalExpectations
auto-correction does not cause unit test failures.Actual behavior
Minitest/GlobalExpectations
auto-correct causes two google-cloud-storage unit test failures.Steps to reproduce the problem
RuboCop version
I understand this is not the latest version of RuboCop, which is restricted by https://github.com/googleapis/ruby-style/blob/master/google-style.gemspec#L31
The text was updated successfully, but these errors were encountered: