From 082ae650fc22e6a16dcf1bb740de03f24541c5ec Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer Date: Mon, 9 Oct 2017 12:53:18 +0200 Subject: [PATCH] specs --- spec/shared_examples/wp_item_infos.rb | 37 +++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/spec/shared_examples/wp_item_infos.rb b/spec/shared_examples/wp_item_infos.rb index 1e1d2fb2..dd83ca89 100644 --- a/spec/shared_examples/wp_item_infos.rb +++ b/spec/shared_examples/wp_item_infos.rb @@ -48,25 +48,42 @@ shared_examples 'WpItem::Infos' do end describe '#changelog_url' do - it 'returns the correct url' do - expect(subject.changelog_url).to eq changelog_url + after { expect(subject.changelog_url).to eql @expected } + + it 'returns nil' do + stub_request(:get, /.*/).to_return(status: 404) + @expected = nil + end + + context 'when the file exists' do + %w{changelog.txt CHANGELOG.md}.each do |changelog| + it 'returns the correct url' do + url = uri.merge(changelog).to_s + @expected = url + + stub_request(:get, %r{^(?!#{url})}).to_return(status: 404) + stub_request(:get, url).to_return(status: 200) + end + end end end describe '#has_changelog?' do - after :each do - stub_request(:get, subject.changelog_url).to_return(status: @status) + after do + allow(subject).to receive_messages(changelog_url: @stub) expect(subject.has_changelog?).to eql @expected end - it 'returns true on a 200' do - @status = 200 - @expected = true + context 'when changelog_url is nil' + it 'returns false' do + @stub = nil + @expected = false end - it 'returns false otherwise' do - @status = 404 - @expected = false + context 'when changelog_url is not nil' + it 'returns true' do + @stub = uri.merge('changelog.txt').to_s + @expected = true end end