Permalink
Browse files

dealing with puts-issues

  • Loading branch information...
mugwump committed Mar 13, 2013
1 parent d9c14d5 commit c8df3157d90e774d814b53d5fad8ed0fb4d82b17
Showing with 27 additions and 4 deletions.
  1. +2 −2 lib/freebase_rb/api.rb
  2. +15 −1 lib/freebase_rb/topic.rb
  3. +10 −1 spec/api_spec.rb
View
@@ -72,8 +72,8 @@ def self.get_result(url, params={})
end
def self.get_uncached_result(url)
- log "querying freebase with: #{url}"
-
+ puts "querying freebase with: #{url}"
+
response = HTTParty.get(url)
if response.code == 200
return JSON.parse(response.body)
View
@@ -31,7 +31,6 @@ def raw_data
end
def get_property(property_name)
-
property = property_name.to_s
return nil if @raw_data.blank?
@@ -56,10 +55,25 @@ def [](key)
get_property(key)
end
+ def to_s
+ "#{id}: #{description}"
+ end
+
+ def inspect
+ "#{id}: #{description}"
+ end
+
+ # implemented to get proper puts-support without running into issues with the method_missing-implementation
+ def to_ary
+ ["#{id}: #{description}", @raw_data]
+ end
+
private
def method_missing(method, *args)
get_property(method)
end
+
+
end
end
View
@@ -10,7 +10,7 @@
let (:api) { FreebaseRb::API}
-
+
describe ".get" do
it "returns a topic with the correct name" do
api.get("/en/the_beatles").name.should eql "The Beatles"
@@ -33,6 +33,7 @@
topic.description.length.should > 100
end
end
+
describe ".topic" do
@@ -54,4 +55,12 @@
end
+ describe "inspection should provide a meaningful result and don't throw errors" do
+ it "inspect works" do
+ topic = api.search("Elvis Presley").first
+ lambda { puts topic }.should_not raise_exception
+ end
+
+
+ end
end

0 comments on commit c8df315

Please sign in to comment.