I have written a class and spec for testing my class. Can anyone determine whether or not this is a correct and good spec?
Class:
module Sitemap
=begin
Class Name: Cities
Function: This class is responsible for getting the data to create the sitemap
for each country according to cities.
=end
class City
attr_accessor :country_version, :directory, :country_host, :locale
def initialize(country_version, directory, country_host,locale)
@country_version = country_version
@directory = directory
@country_host = country_host
@locale = locale
end
def get_data
::City.find_each(:conditions => {:country_version_id => @country_version.id}) do |city|
I18n.locale=(@locale)
yield entry(city)
end
end
private
def entry(city)
{
:loc => ActionController::Integration::Session.new.url_for(:controller => 'cities', :action => 'show', :city_name => city.name, :host => @country_host.value),
:changefreq => 0.8,
:priority => 'monthly',
:lastmod => city.updated_at
}
end
end
end
Spec:
require File.join(File.dirname(__FILE__), "/../spec_helper" )
module Sitemap
describe City do
before :all do
@city = City.new :country_version, :directory, :country_host, :locale
end
describe "#new" do
it "takes four parameters and returns a City object" do
@city.should be_an_instance_of City
end
end
describe "#country_version" do
it "returns the correct country version" do
@city.country_version.should eql :country_version
end
end
describe "#directory" do
it "returns the correct filepath" do
@city.directory.should eql :directory
end
end
describe "#country_host" do
it "returns the correct country host" do
@city.country_host.should eql :country_host
end
end
describe "#locale" do
it "returns the correct locale for translation" do
@city.locale.should eql :locale
end
end
describe "#get_data" do
it "returns collections for xml entries" do
@city.get_data.should eql ::City
end
end
end
end