spec/data/location_spec.rb in barometer-0.8.0 vs spec/data/location_spec.rb in barometer-0.9.0
- old
+ new
@@ -1,70 +1,75 @@
-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+require_relative '../spec_helper'
-describe "Location" do
-
- describe "when initialized" do
-
- before(:each) do
- @location = Data::Location.new
+module Barometer::Data
+ describe Location do
+ describe '#coordinates' do
+ it 'joins longitude and latitude' do
+ location = Location.new(
+ longitude: '99.99',
+ latitude: '88.88'
+ )
+ expect( location.coordinates ).to eq '88.88,99.99'
+ end
end
- it "responds to id" do
- @location.id.should be_nil
- end
+ describe '#to_s' do
+ it 'defaults to an empty string' do
+ location = Location.new
+ expect( location.to_s ).to be_empty
+ end
- it "responds to name" do
- @location.name.should be_nil
- end
+ it 'returns only the name' do
+ location = Location.new(name: 'name')
+ expect( location.to_s ).to eq 'name'
+ end
- it "responds to city" do
- @location.city.should be_nil
- end
+ it 'returns name + city' do
+ location = Location.new(
+ name: 'name',
+ city: 'city'
+ )
+ expect( location.to_s ).to eq 'name, city'
+ end
- it "responds to state_name" do
- @location.state_name.should be_nil
- end
+ it 'returns name + city + country_code' do
+ location = Location.new(
+ name: 'name',
+ city: 'city',
+ country_code: 'country_code'
+ )
+ expect( location.to_s ).to eq 'name, city, country_code'
+ end
- it "responds to state_code" do
- @location.state_code.should be_nil
- end
+ it 'returns name + city + country' do
+ location = Location.new(
+ name: 'name',
+ city: 'city',
+ country_code: 'country_code',
+ country: 'country'
+ )
+ expect( location.to_s ).to eq 'name, city, country'
+ end
- it "responds to country" do
- @location.country.should be_nil
- end
+ it 'returns name + city + state_code + country' do
+ location = Location.new(
+ name: 'name',
+ city: 'city',
+ country: 'country',
+ state_code: 'state_code'
+ )
+ expect( location.to_s ).to eq 'name, city, state_code, country'
+ end
- it "responds to country_code" do
- @location.country_code.should be_nil
+ it 'returns name + city + state_name + country' do
+ location = Location.new(
+ name: 'name',
+ city: 'city',
+ country: 'country',
+ state_code: 'state_code',
+ state_name: 'state_name'
+ )
+ expect( location.to_s ).to eq 'name, city, state_name, country'
+ end
end
-
- it "responds to zip_code" do
- @location.zip_code.should be_nil
- end
-
- it "responds to latitude" do
- @location.latitude.should be_nil
- end
-
- it "responds to longitude" do
- @location.longitude.should be_nil
- end
-
- it "responds to coordinates" do
- @location.longitude = "99.99"
- @location.latitude = "88.88"
- @location.coordinates.should == [@location.latitude, @location.longitude].join(',')
- end
-
- it "should print a string" do
- @location = Data::Location.new
- @location.to_s.should == ""
- @location.name = "name"
- @location.to_s.should == "name"
- @location.city = "city"
- @location.to_s.should == "name, city"
- @location.country_code = "code"
- @location.to_s.should == "name, city, code"
- end
-
end
-
end