Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

improve error reporting of #see_actor_attrs test helper

  • Loading branch information...
commit c2cb7aca8a411c51a596679db241f398a3c41c4f 1 parent 1f42e30
@shawn42 authored
View
9 lib/gamebox/core/actor.rb
@@ -76,24 +76,19 @@ def controller
end
def to_s
- attrs = []
- attributes.keys.sort.each do |name|
- attrs << "#{name}: #{printable_value(attributes[name])}"
- end
"""
#{actor_type}:#{self.object_id}
Behaviors:
#{@behaviors.keys.sort}
Attributes:
- #{attrs.join("\n")}
- """
+ #{attributes.map{|name, val| "#{name}: #{printable_value(val)}"}.join("\n")} """
end
alias pretty_inspect to_s
private
def printable_value(value)
case value
- when String, Float, Fixnum, TrueClass, FalseClass, Vector2
+ when String, Float, Fixnum, TrueClass, FalseClass, Vector2, Symbol
value
when Array
value.map do |pv|
View
16 lib/gamebox/spec/helper.rb
@@ -483,6 +483,14 @@ def self.included(base)
actor.send(key).should == val
end
end
+
+ failure_message_for_should do |actual|
+ "#{actual} was not #{expected}"
+ end
+
+ failure_message_for_should_not do |actual|
+ "#{actual} was #{expected}"
+ end
end
RSpec::Matchers.define :have_no_attrs do |expected_attributes|
@@ -491,6 +499,14 @@ def self.included(base)
actor.has_attribute?(name).should be_false
end
end
+
+ failure_message_for_should do |actual|
+ "#{actual} was not #{expected}"
+ end
+
+ failure_message_for_should_not do |actual|
+ "#{actual} was #{expected}"
+ end
end
end
end
View
17 spec/core/actor_spec.rb
@@ -155,6 +155,23 @@
subject.remove
end
end
+
+ describe "#to_s" do
+ it 'prints meta data about the actor' do
+ subject.to_s.should include(subject.object_id.to_s)
+ end
+
+ it 'prints the attributes' do
+ subject.has_attribute :foo, :bar
+ subject.to_s.should include('foo')
+ subject.to_s.should include('bar')
+ end
+
+ it 'prints the behaviors' do
+ subject.add_behavior :foo, :bar
+ subject.to_s.should include('foo')
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.