Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Self Shunt vs Fake Object in Ruby / RSpec
module Fubarizable
def fubarize
"foobar-#{fubarizable}-foobar"
end
end
class FakeFoobar
include Fubarizable
def fubarizable
"fake"
end
end
describe "Fubarizable" do
context "with fake object" do
it 'is fubarized' do
expect(FakeFoobar.new.fubarize).to eq 'foobar-fake-foobar'
end
end
context "with self shunt pattern" do
include Fubarizable
it 'is fubarized' do
expect(fubarize).to eq "foobar-self_shunt-foobar"
end
def fubarizable
'self_shunt'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.