diff options
author | Kazushige Tominaga <kazu9su@gmail.com> | 2018-02-09 08:12:35 +0900 |
---|---|---|
committer | Yamagishi Kazutoshi <ykzts@desire.sh> | 2018-02-09 08:12:35 +0900 |
commit | 1167c6dbf8d5b8411d9924350b2b9735da6d9d26 (patch) | |
tree | 6b4120e05515c6d16cc5e719a62cdd915e85f6c6 /spec/services | |
parent | 298c81c00f951241f026b0b3f711ead405b78fbe (diff) |
Perform request spec (#6446)
* Added #link_header spec * Added #perform_request spec
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/fetch_atom_service_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/services/fetch_atom_service_spec.rb b/spec/services/fetch_atom_service_spec.rb index fcba55e8d..d7f162b85 100644 --- a/spec/services/fetch_atom_service_spec.rb +++ b/spec/services/fetch_atom_service_spec.rb @@ -21,4 +21,43 @@ RSpec.describe FetchAtomService do it { expect(target.send(:link_header).links[0].href).to eq 'http://example.com/foo' } end end + + describe '#perform_request' do + let(:url) { 'http://example.com' } + context 'Check method result' do + before do + WebMock.stub_request(:get, url).to_return(status: 200, body: '', headers: {}) + @target = FetchAtomService.new + @target.instance_variable_set('@url', url) + end + + it 'HTTP::Response instance is returned and set to @response' do + expect(@target.send(:perform_request).status.to_s).to eq '200 OK' + expect(@target.instance_variable_get('@response')).to be_instance_of HTTP::Response + end + end + + context 'check passed parameters to Request' do + before do + @target = FetchAtomService.new + @target.instance_variable_set('@url', url) + @target.instance_variable_set('@unsupported_activity', unsupported_activity) + allow(Request).to receive(:new).with(:get, url) + expect(Request).to receive_message_chain(:new, :add_headers).with('Accept' => accept) + allow(Request).to receive_message_chain(:new, :add_headers, :perform).with(no_args) + end + + context '@unsupported_activity is true' do + let(:unsupported_activity) { true } + let(:accept) { 'text/html' } + it { @target.send(:perform_request) } + end + + context '@unsupported_activity is false' do + let(:unsupported_activity) { false } + let(:accept) { 'application/activity+json, application/ld+json, application/atom+xml, text/html' } + it { @target.send(:perform_request) } + end + end + end end |