Last active
July 6, 2020 08:51
-
-
Save krisleech/7c292bc1124a19715f401fc144f6982d to your computer and use it in GitHub Desktop.
RSpec gotcha
This file contains 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
require "bundler/inline" | |
gemfile(false) do | |
source "https://rubygems.org" | |
gem "rspec" | |
gem "pry-byebug" | |
end | |
require 'rspec/autorun' | |
RSpec.shared_context 'foo' do | |
let(:name) { 'ONE' } | |
it 'works' do | |
expect(name).to eq('ONE') | |
end | |
end | |
RSpec.shared_context 'bar' do | |
let(:name) { 'TWO' } | |
it 'works' do | |
expect(name).to eq('TWO') | |
end | |
end | |
RSpec.describe 'test' do | |
# FAILS | |
include_examples 'foo' # fails (name is "TWO") | |
include_examples 'bar' | |
# FAILS | |
include_context 'foo' # fails (name is "TWO") | |
include_context 'bar' | |
# WORKS | |
# it_behaves_like 'foo' # passes | |
# it_behaves_like 'bar' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment