spec/ratis/next_bus_spec.rb in ratis-3.4.3 vs spec/ratis/next_bus_spec.rb in ratis-3.5.0

- old
+ new

@@ -1,26 +1,16 @@ require 'spec_helper' describe Ratis::NextBus do - before do - Ratis.reset - Ratis.configure do |config| - config.endpoint = 'http://soap.valleymetro.org/cgi-bin-soap-web-262/soap.cgi' - config.namespace = 'PX_WEB' - end + let(:empty_body) { {:nextbus_response => {:atstop => {:service => []}}} } + let(:time) { Chronic.parse('next monday at 6am') } - @time = Chronic.parse('next monday at 6am') - end - - let(:empty_body){ {:nextbus_response => {:atstop => {:service => []}}} } - describe "Developer can find a late bus to a stop" do it "will give developer happiness :-)" do pending - @conditions = {:app_id => 'ratis-specs', # a short string that can be used to separate requests from different applications or different modules with - :type => 'N', - :datetime => Chronic.parse('now') } + @conditions = {:type => 'N', + :datetime => Chronic.parse('now') } require 'pp' 10000.upto(10100).each do |id| puts id response = Ratis::NextBus.where(@conditions.dup.merge(:stop_id => id)) rescue next @@ -51,19 +41,18 @@ end describe 'time formatting' do it 'should make requests with 24 hour time format' do @stop_id = 10050 - @time = Chronic.parse('tomorrow at 3pm') + time = Chronic.parse('tomorrow at 3pm') @conditions = {:stop_id => @stop_id, - :app_id => 'ratis-specs', # a short string that can be used to separate requests from different applications or different modules with :type => 'N', - :datetime => @time } + :datetime => time } Ratis::Request.should_receive(:get) do |action, options| action.should eq('Nextbus') - options["Time"].should eq(@time.strftime("%H%M")) + options["Time"].should eq(time.strftime("%H%M")) end.and_return(double('response', :success? => false, :body => empty_body)) # false only to stop further running Ratis::NextBus.where(@conditions.dup) end @@ -71,13 +60,12 @@ describe 'single service return' do before do @stop_id = 10050 @conditions = {:stop_id => @stop_id, - :app_id => 'ratis-specs', # a short string that can be used to separate requests from different applications or different modules with :type => 'N', - :datetime => @time } + :datetime => time } end it 'returns the next bus times' do # raises exception when no runs available: @@ -95,13 +83,12 @@ it 'requests the correct SOAP action' do Ratis::Request.should_receive(:get) do |action, options| action.should eq('Nextbus') options["Stopid"].should eq(@stop_id) - options["Appid"].should eq('ratis-specs') - options["Date"].should eq(@time.strftime("%m/%d/%Y")) - options["Time"].should eq(@time.strftime("%H%M")) + options["Date"].should eq(time.strftime("%m/%d/%Y")) + options["Time"].should eq(time.strftime("%H%M")) options["Type"].should eq('N') end.and_return(double('response', :success? => false, :body => empty_body)) # false only to stop further running Ratis::NextBus.where(@conditions.dup) @@ -111,11 +98,11 @@ response = Ratis::NextBus.where(@conditions.dup) service = response.services.first expect(response).to be_a(Ratis::NextBus) expect(response.services).to be_a(Array) - expect(service.status).to eq('D') + expect(service.status).to eq('N') expect(service.sign).to eq('0 CENTRAL North to Dunlap/3rd St.') expect(service.routetype).to eq('B') expect(service.times).to eq("05:49 AM, 06:09 AM, 06:29 AM, 06:49 AM") expect(service.direction).to eq('N') expect(service.servicetype).to eq('W') @@ -145,13 +132,12 @@ it "should return an empty array if the api request isn't successful" do Ratis::Request.should_receive(:get) do |action, options| action.should eq('Nextbus') options["Stopid"].should eq(@stop_id) - options["Appid"].should eq('ratis-specs') - options["Date"].should eq(@time.strftime("%m/%d/%Y")) - options["Time"].should eq(@time.strftime("%H%M")) + options["Date"].should eq(time.strftime("%m/%d/%Y")) + options["Time"].should eq(time.strftime("%H%M")) options["Type"].should eq('N') end.and_return(double('response', :success? => false, :body => empty_body)) # false only to stop further running expect(Ratis::NextBus.where(@conditions.dup).services).to be_empty @@ -161,11 +147,10 @@ describe 'multiple services returned' do before do @stop_id = 15894 @time = Chronic.parse('next monday at 3pm') @conditions = {:stop_id => @stop_id, - :app_id => 'ratis-specs', # a short string that can be used to separate requests from different applications or different modules with :type => 'N', :datetime => @time } end it 'returns the next 4 bus times' do @@ -184,11 +169,10 @@ it 'requests the correct SOAP action' do Ratis::Request.should_receive(:get) do |action, options| action.should eq('Nextbus') options["Stopid"].should eq(@stop_id) - options["Appid"].should eq('ratis-specs') options["Date"].should eq(@time.strftime("%m/%d/%Y")) options["Time"].should eq(@time.strftime("%H%M")) options["Type"].should eq('N') end.and_return(double('response', :success? => false, :body => empty_body)) # false only to stop further running @@ -246,17 +230,16 @@ }.should raise_error(ArgumentError, 'You must provide a stop ID') end it "should return an empty array if the api request isn't successful" do Ratis::Request.should_receive('get') do |action, options| - action.should eq('Nextbus') - options["Time"].should eq(@time.strftime("%H%M") ) - options["Type"].should eq("N") - options["Stopid"].should eq(@stop_id) - options["Date"].should eq(@time.strftime("%m/%d/%Y") ) - options["Appid"].should eq("ratis-specs") + action.should eq('Nextbus') + options["Time"].should eq(@time.strftime("%H%M") ) + options["Type"].should eq("N") + options["Stopid"].should eq(@stop_id) + options["Date"].should eq(time.strftime("%m/%d/%Y") ) - end.and_return(double('response', :success? => false, :body => empty_body)) + end.and_return(double('response', :success? => false, :body => empty_body)) expect(Ratis::NextBus.where(@conditions.dup).services).to be_empty end end end