Permalink
Browse files

Version 0.0.2, full spec passing and basic functionality

  • Loading branch information...
1 parent e0ad992 commit abdea1d5d5661b9017f6e78eaaa81c9a53bf7f1d Bruno Bonamin committed Apr 27, 2012
@@ -40,7 +40,7 @@ class Bus
{:name => 'Linea de la Costa', :line_id => '65', :value => 'LC'},
{:name => 'Ronda del Centro', :line_id => '66', :value => 'RC'} ]
- attr_reader :name, :line_id, :value
+ attr_reader :name, :line_id, :value, :streets
def initialize bus_name
bus = BUS_LINES.select { |bus| bus[:name] == bus_name.to_s }.first
if bus.nil?
@@ -49,6 +49,10 @@ def initialize bus_name
@name = bus[:name]
@line_id = bus[:line_id]
@value = bus[:value]
+
+ agent = Mechanize.new
+ agent.get("http://www.etr.gov.ar/getData.php?accion=getCalle&idLinea=#{line_id}")
+ @streets = JSON(agent.page.content)
end
end
@@ -60,16 +64,17 @@ def self.list_all
buses
end
- def streets
- agent = Mechanize.new
- agent.get("http://www.etr.gov.ar/getData.php?accion=getCalle&idLinea=#{line_id}")
- JSON(agent.page.content)
- end
-
def intersections(street)
agent = Mechanize.new
agent.get("http://www.etr.gov.ar/getData.php?accion=getInterseccion&idLinea=#{line_id}&idCalle=#{street['id']}")
JSON(agent.page.content)
end
+
+ # private
+ # def get_streets
+ # agent = Mechanize.new
+ # agent.get("http://www.etr.gov.ar/getData.php?accion=getCalle&idLinea=#{line_id}")
+ # JSON(agent.page.content)
+ # end
end
end
@@ -1,3 +1,3 @@
module Colectivero
- VERSION = "0.0.1"
+ VERSION = "0.0.2"
end
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe 'Arrival' do
+ it 'should return a string when called with object parameters' do
+ bus = Colectivero::Bus.new('110')
+ street = bus.streets.first
+ intersection = bus.intersections(street).first
+ bus_stop = Colectivero::BusStop.new(bus, street, intersection)
+
+ arrival = Colectivero::Arrival.new bus, bus_stop
+ arrival.message.should_not match "Disculpe\\*"
+ end
+
+ it 'should return a string when called with a bus stop number' do
+ bus = Colectivero::Bus.new('110')
+ valid_bus_stop = 7969
+
+ arrival = Colectivero::Arrival.new bus, valid_bus_stop
+ arrival.message.should_not match "Disculpe\\*"
+ end
+
+ it 'should return a Disculpe message when called with an invalid bus stop' do
+ bus = Colectivero::Bus.new('110')
+ street = bus.streets.first
+ intersection = bus.intersections(street).first
+ bus_stop = Colectivero::BusStop.new(bus, street, intersection)
+
+ arrival = Colectivero::Arrival.new bus, 9191
+ arrival.message.should match("Disculpe(.*)")
+ end
+end
@@ -19,10 +19,24 @@
end
end
- context 'with a non valid name' do
- it 'should be nil' do
- @bus = Colectivero::Bus.new('xxx')
- @bus.should be_nil
+ context 'with an invalid name' do
+ it 'should be raise an error' do
+ expect { Colectivero::Bus.new('xxx') }.should raise_error
end
end
+
+ it 'should have many streets' do
+ @bus.streets.should_not be_empty
+ end
+
+ context 'with a street as parameter' do
+ it 'should have many intersections' do
+ street = @bus.streets.first
+ @bus.intersections(street).should_not be_empty
+ end
+ end
+
+ it 'should raise an error when calling intersections without params' do
+ expect { @bus.intersections }.should raise_error
+ end
end
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+describe 'BusStop' do
+ it 'should return a bus_stop number when called with the correct parameters' do
+ bus = Colectivero::Bus.new('110')
+ street = bus.streets.first
+ intersection = bus.intersections(street).first
+ bus_stop = Colectivero::BusStop.new(bus, street, intersection)
+
+ bus_stop.should_not be_nil
+ end
+
+ it 'should return an error when called with no parameters' do
+ expect { Colectivero::BusStop.new}.should raise_error
+ end
+end

0 comments on commit abdea1d

Please sign in to comment.