Created
August 7, 2015 18:51
-
-
Save tylerhunt/3decf5a32873625110c1 to your computer and use it in GitHub Desktop.
RSpec shared context to allow testing of Active Job objects with GlobalID-compatible doubles.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.shared_context 'Global ID', :global_id do | |
def global_id_instance_double(doubled_class, stubs={}) | |
instance_double(doubled_class, stubs) | |
.extend(GlobalID::Identification) | |
.tap { |double| | |
unless double.respond_to?(:id) | |
allow(double).to receive(:id).and_return(double.object_id) | |
end | |
} | |
end | |
before do | |
allow(GlobalID).to receive(:app).and_return('example') unless GlobalID.app | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the Gist ! Works perfect to make those ActiveJob jobs works with RSpec doubles.
Saved in
spec/support/global_id_context.rb
, I added to that file (following https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-context)And call it from other tests with (using RSpec 3.5)