Permalink
Browse files

Provide reasonable #inspect/#to_s for Interpol::Endpoint.

  • Loading branch information...
1 parent d9cda63 commit aa3bdcc7bd0f43c9fc2184c4a72f9187e7c02d6f @myronmarston myronmarston committed Dec 4, 2012
Showing with 12 additions and 1 deletion.
  1. +5 −0 lib/interpol/endpoint.rb
  2. +7 −1 spec/unit/interpol/endpoint_spec.rb
View
@@ -94,6 +94,11 @@ def route_matches?(path)
path =~ route_regex
end
+ def inspect
+ "#<#{self.class.name} #{method} #{route} (#{name})>"
+ end
+ alias to_s inspect
+
private
def available_versions_matching
@@ -29,11 +29,17 @@ def build_hash(hash = {})
end
end
-
it 'initializes the HTTP method' do
Endpoint.new(build_hash 'method' => 'PUT').method.should be(:put)
end
+ [:to_s, :inspect].each do |meth|
+ it "provides a human-readable ##{meth} output" do
+ endpoint = Endpoint.new(build_hash 'route' => '/foo')
+ endpoint.send(meth).should eq("#<Interpol::Endpoint get /foo (the-name)>")
+ end
+ end
+
%w[ name route definitions method ].each do |attr|
it "raises an error if not initialized with '#{attr}'" do
hash = build_hash.reject { |k, v| k == attr }

0 comments on commit aa3bdcc

Please sign in to comment.