Skip to content

Instantly share code, notes, and snippets.

@bilus
Created April 28, 2017 21:05
Show Gist options
  • Save bilus/18333f40adc34d40d62dc093d5a6a601 to your computer and use it in GitHub Desktop.
Save bilus/18333f40adc34d40d62dc093d5a6a601 to your computer and use it in GitHub Desktop.
class User; end
class Company; end
class Package
def initialize(owner:)
end
def cost(distance)
end
end
RSpec.shared_examples 'cheap package' do
it { is_expected.to be < 100 }
it { is_expected.to be > 50 }
end
RSpec.shared_examples 'expensive package' do
it { is_expected.to be >= 500 }
it { is_expected.to be < 1000 }
end
RSpec.describe Package do
let(:package) { described_class.new(owner: owner) }
describe '#cost' do
subject { package.cost(distance) }
context 'when owned by company' do
let(:owner) { Company.new }
context 'long range' do
let(:distance) { 10000 }
it_behaves_like 'expensive package'
end
context 'mid range' do
let(:distance) { 5000 }
it_behaves_like 'expensive package'
end
context 'short range' do
let(:distance) { 1000 }
it_behaves_like 'cheap package'
end
end
# .. different pricing for User ...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment