Permalink
Browse files

Result equality

  • Loading branch information...
1 parent 27dfad0 commit 02a7413daaeeb9380ae7aef0211f8074c45a2fe9 @sam-wan sam-wan committed Apr 16, 2008
Showing with 65 additions and 1 deletion.
  1. +3 −1 lib/itunes_link_maker.rb
  2. +16 −0 lib/result.rb
  3. +46 −0 spec/result_spec.rb
View
@@ -1,6 +1,8 @@
require 'open-uri'
require 'cgi'
+require File.join(File.dirname(__FILE__), 'result')
+
class ItunesLinkMaker
MEDIA = [ 'all', 'music', 'movie', 'shortFilm', 'tvShow',
'musicVideo', 'audiobook', 'podcast', 'iTunesU' ]
@@ -18,7 +20,7 @@ def self.search(query, media='music', country='US')
private
def self.parse_html(html)
- []
+ [Result.new]
end
def self.get_html(query, media, country)
View
@@ -0,0 +1,16 @@
+class ItunesLinkMaker
+ class Result
+ attr_reader :name, :type
+
+ def initialize(name, type, display_url)
+ @name = name
+ @type = type
+ @display_url = display_url
+ end
+
+ def ==(result)
+ vars = [ '@name', '@type', '@display_url' ]
+ vars.all? { |v| instance_variable_get(v) == result.instance_variable_get(v) }
+ end
+ end
+end
View
@@ -0,0 +1,46 @@
+require File.dirname(__FILE__) + '/../lib/result.rb'
+
+describe ItunesLinkMaker::Result do
+ def create_result(options={})
+ options = {
+ :name => 'Such Great Heights',
+ :type => :name,
+ :display_url => '/WebObjects/MZStoreServices.woa/wa/itmsSearchDisplayUrl?desc=The+Postal+Service+-+Give+Up+-+Such+Great+Heights&WOURLEncoding=ISO8859_1&lang=1&url=http%3A%2F%2Fphobos.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbum%3Fi%3D2522315%26id%3D2522333%26s%3D143441'
+ }.merge(options)
+
+ ItunesLinkMaker::Result.new(options[:name], options[:type], options[:display_url])
+ end
+
+ it "should be instantiable with name, type and display url" do
+ create_result
+ end
+
+ it "should set the name and type instance variables" do
+ r = create_result
+ r.name.should == 'Such Great Heights'
+ r.type.should == :name
+ end
+
+ it "should be equal to a result with identical name, type and url" do
+ r1, r2 = create_result, create_result
+ r1.should == r2
+ end
+
+ it "should not be equal to a result with a different name" do
+ r1 = create_result
+ r2 = create_result(:name => 'Different')
+ r1.should_not == r2
+ end
+
+ it "should not be equal to a result with a different type" do
+ r1 = create_result
+ r2 = create_result(:type => 'Different')
+ r1.should_not == r2
+ end
+
+ it "should not be equal to a result with a different display url" do
+ r1 = create_result
+ r2 = create_result(:display_url => 'Different')
+ r1.should_not == r2
+ end
+end

0 comments on commit 02a7413

Please sign in to comment.