Sha256: e10deb001c4eada89aae0c43fe9d0531d427e8da12fb3d406bd10c069b38c037

Contents?: true

Size: 1.42 KB

Versions: 5

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'
require 'omdb/network'

describe Omdb::Network do
  it "returns a instance of Omdb::Network" do
    network = Omdb::Network.new
    expect(network).to be_a(Omdb::Network)
  end

  describe "#call" do
    it "returns a hash when called" do
      expect(search_movie).to be_a(Hash)
    end

    context 'When called with {t: "Star Wars"} as params' do
      it 'returns value contains "Star Wars"' do
        expect(fetch_movie[:data]).to include(
          {"Title"=> "Star Wars"}
        )
      end
    end

    context 'When called with {s: "Star Wars"{ as params' do
      it 'returns value contains "Star Wars: The Clone Wars"' do
        expect(search_movie[:data]["Search"].last).to include (
          {"Title" => "The Star Wars Holiday Special"}
        )
      end
    end

    def search_movie
      omdb_return_data = File.read(File.join("spec", "fixtures", "movies_search.json"))
      stub_request(:any, "http://www.omdbapi.com").
        with({query: {"s" => "Star Wars"}}).
        to_return(:body => omdb_return_data, :code => 200 )
      Omdb::Network.new.call({s: "Star Wars"})
    end

    def fetch_movie
      omdb_return_data = File.read(File.join("spec", "fixtures", "star_wars.json"))
      stub_request(:any, "http://www.omdbapi.com").
        with({query: {"t" => "Star Wars"}}).
        to_return(:body => omdb_return_data, :code => 200 )
      Omdb::Network.new.call({t: "Star Wars"})
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
omdb-1.0.4 spec/lib/omdb/network_spec.rb
omdb-1.0.3 spec/lib/omdb/network_spec.rb
omdb-1.0.2 spec/lib/omdb/network_spec.rb
omdb-1.0.1 spec/lib/omdb/network_spec.rb
omdb-1.0.0 spec/lib/omdb/network_spec.rb