summaryrefslogtreecommitdiff
path: root/lib/rb/spec
diff options
context:
space:
mode:
authorBryan Duxbury <bryanduxbury@apache.org>2010-09-21 16:30:58 +0000
committerBryan Duxbury <bryanduxbury@apache.org>2010-09-21 16:30:58 +0000
commit6a1fb17a25ce7b52b7c5e396adf86ceb96606d64 (patch)
treedf7f8cca3980f6da2d22f6151a33c4c51b50b296 /lib/rb/spec
parent1237dcb099a068f83f31cc51df428f5c828d0511 (diff)
downloadthrift-6a1fb17a25ce7b52b7c5e396adf86ceb96606d64.tar.gz
THRIFT-909. rb: allow block argument to struct constructor
This patch allows the user to pass a block to generated structs' constructors. The block will receive and instance of the new object. Patch: Michael Stockton git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@999487 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'lib/rb/spec')
-rw-r--r--lib/rb/spec/struct_spec.rb23
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/rb/spec/struct_spec.rb b/lib/rb/spec/struct_spec.rb
index 59a401815..04f55ca6e 100644
--- a/lib/rb/spec/struct_spec.rb
+++ b/lib/rb/spec/struct_spec.rb
@@ -31,13 +31,22 @@ class ThriftStructSpec < Spec::ExampleGroup
end
it "should initialize all fields to defaults" do
- struct = Foo.new
- struct.simple.should == 53
- struct.words.should == "words"
- struct.hello.should == Hello.new(:greeting => 'hello, world!')
- struct.ints.should == [1, 2, 2, 3]
- struct.complex.should be_nil
- struct.shorts.should == Set.new([5, 17, 239])
+ validate_default_arguments(Foo.new)
+ end
+
+ it "should initialize all fields to defaults and accept a block argument" do
+ Foo.new do |f|
+ validate_default_arguments(f)
+ end
+ end
+
+ def validate_default_arguments(object)
+ object.simple.should == 53
+ object.words.should == "words"
+ object.hello.should == Hello.new(:greeting => 'hello, world!')
+ object.ints.should == [1, 2, 2, 3]
+ object.complex.should be_nil
+ object.shorts.should == Set.new([5, 17, 239])
end
it "should not share default values between instances" do