Skip to content

Instantly share code, notes, and snippets.

@vovimayhem
Last active January 3, 2022 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vovimayhem/eee54dd4d1b65c0a633955274eb11d48 to your computer and use it in GitHub Desktop.
Save vovimayhem/eee54dd4d1b65c0a633955274eb11d48 to your computer and use it in GitHub Desktop.
Spec mocks failing on ruby 3
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'rspec', github: 'rspec/rspec-metagem', ref: 'main'
gem 'rspec-core', github: 'rspec/rspec-core', ref: 'main'
gem 'rspec-expectations', github: 'rspec/rspec-expectations', ref: 'main'
gem 'rspec-mocks', github: 'rspec/rspec-mocks', ref: 'main'
gem 'rspec-support', github: 'rspec/rspec-support', ref: 'main'
# frozen_string_literal: true
module MyExample
def self.my_method(argument_one, keword_argument_one: nil)
return true
end
def self.my_failing_method
my_method(a: 1)
end
def self.my_working_method
my_method({a: 1})
end
end
RSpec.describe MyExample do
describe '.my_failing_method' do
it "doesn't call my_method with a hash" do
expect(described_class).not_to receive(:my_method).with({a: 1})
described_class.my_failing_method
end
it 'calls my_method with keywords' do
expect(described_class).to receive(:my_method).with(a: 1)
described_class.my_failing_method
end
end
describe '.my_working_method' do
it 'calls my_method with a hash' do
expect(described_class).to receive(:my_method).with({a: 1})
described_class.my_failing_method
end
it "doesn't call my_method with keywords" do
expect(described_class).not_to receive(:my_method).with(a: 1)
described_class.my_failing_method
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment