rapid7 / ruby_smb

A native Ruby implementation of the SMB Protocol Family
Other
80 stars 80 forks source link

Field 'stub' shadows an existing method in RubySMB::Dcerpc::Request while unit testing #261

Open ls5302 opened 5 months ago

ls5302 commented 5 months ago

When I try to unit test my code, a simple SMB client, I get a SyntaxError error with the message field 'stub' shadows an existing method in RubySMB::Dcerpc::Request.

This only happens when I'm running the RSPEC tests, and my code executes without errors. The issue seem to occur because RSPEC has been configured by calling mock_with :rspec, and the BasicObject has a stub function defined. If the mock_with method is not called the require 'ruby_smb' is successful.

If I require 'ruby_smb' before the RSpec.configure block in the spec_helper.rb - like you have in your tests - all is well too.

Any suggestion as to how to run the unit tests without pre-requiring the GEM? Can the check be changed to @the_class.method_defined?(name, false) to ignore inherited methods?

Further problem, name_is_reserved? is also picking up stub as a reserved work because it's part of Hash.