test/surrounded_test.rb in surrounded-0.7.3 vs test/surrounded_test.rb in surrounded-0.8.0
- old
+ new
@@ -17,57 +17,48 @@
let(:context){
TestContext.new(jim, guille)
}
- before do
- jim.store_context(context)
- guille.store_context(context)
- end
-
it "has access to objects in the context" do
- assert_equal jim.other_user, guille
+ assert context.access_other_object
end
- it "responds to messages for roles on the context" do
- assert jim.respond_to?(:other_user)
-
- jim.remove_context
-
- refute jim.respond_to?(:other_user)
- end
-
it "prevents access to context objects for external objects" do
assert_raises(NoMethodError){
external_user.user
}
end
end
+class UnsurroundedObject
+ attr_accessor :name
+end
+
describe "Surrounded", "added to an existing object" do
it "allows the object to store its context" do
- object = Object.new
+ thing = UnsurroundedObject.new
+ thing.name = 'Jim'
+
assert_raises(NoMethodError){
- object.store_context(self)
+ thing.send(:store_context)
}
- object.extend(Surrounded)
- assert object.store_context(self)
- assert object.remove_context
+ thing.extend(Surrounded)
+
+ other = User.new('Guille')
+
+ context = TestContext.new(thing, other)
+ assert context.access_other_object
end
end
module SpecialSurrounding
include Surrounded
end
describe "Surrounded", "added to an object through another module" do
it "allows the object to store its context" do
object = Array.new
- assert_raises(NoMethodError){
- object.store_context(self)
- }
object.extend(SpecialSurrounding)
- assert object.store_context(self)
- assert object.remove_context
- assert object.send(:context)
+ assert object.respond_to?(:context, true)
end
end
\ No newline at end of file