Skip to content

Instantly share code, notes, and snippets.

@siassaj
Created October 23, 2021 02:19
Show Gist options
  • Save siassaj/ef72b4433db8e245bf9f0dde19a82896 to your computer and use it in GitHub Desktop.
Save siassaj/ef72b4433db8e245bf9f0dde19a82896 to your computer and use it in GitHub Desktop.
require_relative "./my_resource_spec/shared.rb"
RSpec.describe MyResource do
describe "#a_method" do
include_context "with shared foo and bar", lambda {
it "is great" do
expect(my_resource.a_method).to eq('is great')
end
}
end
end
###
### Result
# MyResource
# #a_method
# with shared foo and bar
# is great
RSpec.shared_context "with shared foo and bar" do |block|
subject(:my_resource) { create(:my_resource) }
let(:foo) { ... }
let(:bar) { ... }
before { ... }
context "with shared foo and bar", &block
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment