test/surrounded_context_test.rb in surrounded-0.1.0 vs test/surrounded_context_test.rb in surrounded-0.2.0
- old
+ new
@@ -81,20 +81,19 @@
refute context.role?(:user){} # this test is the caller
end
end
require 'casting'
-CastingUser = Struct.new(:name)
-class CastingUser
+class CastingUser < User
include Casting::Client
delegate_missing_methods
end
class RoleAssignmentContext
extend Surrounded::Context
- setup(:user, :other_user)
+ initialize(:user, :other_user)
trigger :user_ancestors do
user.singleton_class.ancestors
end
@@ -116,11 +115,19 @@
module OtherUser
def a_method!; end
end
end
+describe Surrounded::Context, '.setup' do
+ it 'defines an initialize method accepting the same arguments' do
+ skip "not yet implemented. may not be possible"
+ assert_equal 2, RoleAssignmentContext.instance_method(:initialize).arity
+ end
+end
+
describe Surrounded::Context, 'assigning roles' do
+ include Surrounded
let(:user){ CastingUser.new("Jim") }
let(:other_user){ User.new("Guille") }
let(:context){ RoleAssignmentContext.new(user, other_user) }
it 'tries to use casting to add roles' do
@@ -134,20 +141,22 @@
it 'sets role players to respond to role methods' do
assert context.check_user_response
assert context.check_other_user_response
end
- it 'will not use classes as roles' do
+ it 'will use classes as roles' do
ClassRoleAssignmentContext = Class.new do
extend Surrounded::Context
- setup(:thing, :the_test)
+ initialize(:thing, :the_test)
trigger :check_user_response do
- the_test.refute thing.respond_to?(:method_from_class), 'did respond to :method_from_class'
+ the_test.assert_respond_to thing, :method_from_class
end
class Thing
+ include Surrounded
+ def initialize(obj); end
def method_from_class; end
end
end
\ No newline at end of file