spec/lib/duffel_spec.rb in duffel-0.0.1 vs spec/lib/duffel_spec.rb in duffel-0.0.2
- old
+ new
@@ -1,8 +1,10 @@
require 'duffel'
describe Duffel do
+ subject { Duffel }
+
it 'should not raise an error' do
expect { subject }.to_not raise_error
end
describe '.not_an_existing_method' do
@@ -16,25 +18,83 @@
expect(
subject.another_non_existing_method(:fallback => 'blah')
).to eq 'blah'
end
+ it 'should be idempotent' do
+ expect(
+ subject.another_non_existing_method(:fallback => 'blah')
+ ).to eq 'blah'
+ expect(
+ subject.another_non_existing_method(:fallback => 'blah')
+ ).to eq 'blah'
+ end
+
+ it 'should allow a different fallback the next time it is called' do
+ expect(
+ subject.another_non_existing_method(:fallback => 'foo')
+ ).to eq 'foo'
+ end
+
+ it 'should allow nothing to be passed and to raise a key error' do
+ expect{
+ subject.another_non_existing_method
+ }.to raise_error KeyError
+ end
+
context 'fallback is nil' do
it 'should return nil' do
expect(
subject.yet_another_non_existing_method(:fallback => nil)
).to eq nil
end
+
+ it 'should be idempotent' do
+ expect(
+ subject.yet_another_non_existing_method(:fallback => nil)
+ ).to eq nil
+ expect(
+ subject.yet_another_non_existing_method(:fallback => nil)
+ ).to eq nil
+ end
+
+ it 'should allow a different fallback the next time it is called' do
+ expect(
+ subject.yet_another_non_existing_method(:fallback => 'bar')
+ ).to eq 'bar'
+ end
+
+ it 'should allow nothing to be passed and to raise a key error' do
+ expect{
+ subject.yet_another_non_existing_method
+ }.to raise_error KeyError
+ end
end
end
end
context 'with a matching environment variable' do
- before { expect(ENV).to receive(:fetch).with('AN_EXISTING_METHOD').and_return(response) }
+ before do
+ allow(ENV).to(
+ receive(:fetch).
+ with('AN_EXISTING_METHOD').
+ and_return(response)
+ )
+ end
+
let(:response) { 'response' }
it 'should return the env variable' do
expect(subject.an_existing_method).to eq response
+ end
+
+ it 'should be idempotent' do
+ expect(subject.an_existing_method).to eq response
+ expect(subject.an_existing_method).to eq response
+ end
+
+ it 'should not return the fallback when the env variable exists' do
+ expect(subject.an_existing_method(fallback: 'foo')).to eq response
end
end
end
end