test/surrounded_context_test.rb in surrounded-0.9.6 vs test/surrounded_context_test.rb in surrounded-0.9.7
- old
+ new
@@ -104,11 +104,13 @@
end
class RoleAssignmentContext
extend Surrounded::Context
- initialize(:user, :other_user)
+ initialize(:user, :other_user) do
+ self.instance_variable_set(:@defined_by_initializer_block, 'yup')
+ end
def user_ancestors
user.singleton_class.ancestors
end
@@ -205,10 +207,14 @@
special = User.new('Special')
other = User.new('Other')
context = IgnoreExternalConstantsContext.new(user, special, other)
assert_equal User, context.check_special
end
+
+ it 'applies a provided block to the instance' do
+ assert_equal 'yup', context.instance_variable_get(:@defined_by_initializer_block)
+ end
end
class CollectionContext
extend Surrounded::Context
@@ -282,11 +288,13 @@
begin
class Keyworder
extend Surrounded::Context
- keyword_initialize :this, :that
+ keyword_initialize :this, :that do
+ self.instance_variable_set(:@defined_by_initializer_block, 'yes')
+ end
end
describe Surrounded::Context, 'keyword initializers' do
it 'works with keyword arguments' do
assert Keyworder.new(this: User.new('Jim'), that: User.new('Guille'))
@@ -295,9 +303,13 @@
it 'raises errors with missing keywords' do
err = assert_raises(ArgumentError){
Keyworder.new(this: User.new('Amy'))
}
assert_match(/missing keyword: that/, err.message)
+ end
+
+ it 'evaluates a given block' do
+ assert_equal 'yes', Keyworder.new(this: User.new('Jim'), that: User.new('Guille')).instance_variable_get(:@defined_by_initializer_block)
end
end
rescue SyntaxError
STDOUT.puts "No support for keywords"
end