ceedling 0.27.0 → 0.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/assets/project_as_gem.yml +6 -0
- data/assets/project_with_guts.yml +6 -0
- data/assets/project_with_guts_gcov.yml +88 -0
- data/assets/test_example_file_boom.c +13 -0
- data/assets/test_example_file_success.c +14 -0
- data/bin/ceedling +57 -113
- data/ceedling.gemspec +1 -1
- data/config/test_environment.rb +0 -1
- data/examples/blinky/project.yml +1 -1
- data/examples/temp_sensor/project.yml +7 -1
- data/examples/temp_sensor/rakefile.rb +3 -1
- data/lib/ceedling/build_invoker_utils.rb +14 -2
- data/lib/ceedling/configurator.rb +3 -1
- data/lib/ceedling/configurator_builder.rb +6 -4
- data/lib/ceedling/configurator_setup.rb +5 -1
- data/lib/ceedling/defaults.rb +5 -2
- data/lib/ceedling/dependinator.rb +1 -1
- data/lib/ceedling/file_path_utils.rb +1 -2
- data/lib/ceedling/generator_test_results.rb +3 -2
- data/lib/ceedling/generator_test_results_sanity_checker.rb +4 -3
- data/lib/ceedling/project_file_loader.rb +26 -9
- data/lib/ceedling/rakefile.rb +9 -2
- data/lib/ceedling/release_invoker.rb +1 -1
- data/lib/ceedling/reportinator.rb +18 -1
- data/lib/ceedling/system_utils.rb +6 -1
- data/lib/ceedling/system_wrapper.rb +2 -1
- data/lib/ceedling/target_loader.rb +2 -2
- data/lib/ceedling/tasks_filesystem.rake +8 -2
- data/lib/ceedling/tool_executor_helper.rb +71 -22
- data/lib/ceedling/version.rb +1 -1
- data/license.txt +1 -1
- data/out.fail +21 -0
- data/plugins/command_hooks/lib/command_hooks.rb +2 -1
- data/plugins/gcov/config/defaults.yml +22 -0
- data/plugins/gcov/gcov.rake +79 -65
- data/plugins/gcov/lib/gcov.rb +25 -38
- data/plugins/gcov/lib/gcov_constants.rb +16 -0
- data/spec/build_invoker_utils_spec.rb +54 -0
- data/spec/file_finder_helper_spec.rb +53 -0
- data/spec/gcov/gcov_deployment_spec.rb +70 -0
- data/spec/gcov/gcov_test_cases_spec.rb +91 -0
- data/spec/generator_test_results_sanity_checker_spec.rb +88 -0
- data/spec/generator_test_results_spec.rb +102 -0
- data/spec/reportinator_spec.rb +19 -0
- data/spec/spec_system_helper.rb +67 -5
- data/spec/support/other_target.yml +0 -0
- data/spec/support/target.yml +0 -0
- data/spec/support/test_example.fail +21 -0
- data/spec/support/test_example.pass +21 -0
- data/spec/support/test_example_empty.pass +13 -0
- data/spec/support/test_example_ignore.pass +21 -0
- data/spec/support/test_example_mangled.pass +19 -0
- data/spec/system/deployment_spec.rb +25 -5
- data/spec/system_utils_spec.rb +56 -0
- data/spec/target_loader_spec.rb +30 -0
- data/spec/tool_executor_helper_spec.rb +310 -0
- data/vendor/cmock/scripts/create_makefile.rb +35 -12
- data/vendor/unity/src/unity_internals.h +3 -3
- metadata +62 -27
- data/assets/rakefile_as_gem.rb +0 -3
- data/assets/rakefile_with_guts.rb +0 -6
- data/vendor/constructor/History.rdoc +0 -19
- data/vendor/constructor/README.rdoc +0 -72
- data/vendor/constructor/Rakefile +0 -33
- data/vendor/constructor/homepage/Notes.txt +0 -27
- data/vendor/constructor/homepage/Rakefile +0 -15
- data/vendor/constructor/homepage/index.erb +0 -27
- data/vendor/constructor/homepage/index.html +0 -36
- data/vendor/constructor/homepage/page_header.graffle +0 -0
- data/vendor/constructor/homepage/page_header.html +0 -9
- data/vendor/constructor/homepage/page_header.png +0 -0
- data/vendor/constructor/homepage/sample_code.png +0 -0
- data/vendor/constructor/homepage/sample_code.rb +0 -12
- data/vendor/constructor/lib/constructor.rb +0 -127
- data/vendor/constructor/lib/constructor_struct.rb +0 -33
- data/vendor/constructor/specs/constructor_spec.rb +0 -407
- data/vendor/constructor/specs/constructor_struct_spec.rb +0 -84
@@ -1,15 +0,0 @@
|
|
1
|
-
desc "Rewrite index.html using index.erb and publisher_homepage.html"
|
2
|
-
task :index do
|
3
|
-
require 'erb'
|
4
|
-
@title = "Constructor - atomicobject.rb"
|
5
|
-
@plugin_install = "$ script/plugin install svn://rubyforge.org/var/svn/atomicobjectrb/tags/constructor"
|
6
|
-
@header_html = File.read("page_header.html")
|
7
|
-
html = ERB.new(File.read("index.erb")).result(binding)
|
8
|
-
fname = "index.html"
|
9
|
-
File.open(fname,"w") do |f|
|
10
|
-
f.print html
|
11
|
-
end
|
12
|
-
puts "Wrote #{fname}"
|
13
|
-
end
|
14
|
-
|
15
|
-
task :default => :index
|
@@ -1,27 +0,0 @@
|
|
1
|
-
<html>
|
2
|
-
<head>
|
3
|
-
<title><%= @title %></title>
|
4
|
-
</head>
|
5
|
-
<style>
|
6
|
-
#rails_plugin_installation {
|
7
|
-
padding: 5px;
|
8
|
-
margin-bottom: 10px;
|
9
|
-
font: bold 10pt "Courier New", courier, serif
|
10
|
-
}
|
11
|
-
</style>
|
12
|
-
|
13
|
-
<body>
|
14
|
-
|
15
|
-
<div align="center">
|
16
|
-
|
17
|
-
<%= @header_html %>
|
18
|
-
|
19
|
-
<div id="rails_plugin_installation"><%= @plugin_install %></div>
|
20
|
-
|
21
|
-
<a href="rdoc/index.html"><img border=0 src="sample_code.png"></a>
|
22
|
-
</div>
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
</body>
|
27
|
-
</html>
|
@@ -1,36 +0,0 @@
|
|
1
|
-
<html>
|
2
|
-
<head>
|
3
|
-
<title>Constructor - atomicobject.rb</title>
|
4
|
-
</head>
|
5
|
-
<style>
|
6
|
-
#rails_plugin_installation {
|
7
|
-
padding: 5px;
|
8
|
-
margin-bottom: 10px;
|
9
|
-
font: bold 10pt "Courier New", courier, serif
|
10
|
-
}
|
11
|
-
</style>
|
12
|
-
|
13
|
-
<body>
|
14
|
-
|
15
|
-
<div align="center">
|
16
|
-
|
17
|
-
<map name="GraffleExport">
|
18
|
-
<area shape=rect coords="486,91,635,108" href="http://atomicobjectrb.rubyforge.org/">
|
19
|
-
<area shape=rect coords="485,120,635,187" href="rdoc/index.html">
|
20
|
-
<area shape=rect coords="310,120,463,187" href="http://rubyforge.org/frs/?group_id=4897&release_id=16546">
|
21
|
-
<area shape=rect coords="14,91,168,108" href="http://atomicobject.com">
|
22
|
-
<area shape=rect coords="572,16,627,71" href="http://atomicobjectrb.rubyforge.org/">
|
23
|
-
<area shape=rect coords="21,13,83,75" href="http://atomicobject.com">
|
24
|
-
</map>
|
25
|
-
<img border=0 src="page_header.png" usemap="#GraffleExport">
|
26
|
-
|
27
|
-
|
28
|
-
<div id="rails_plugin_installation">$ script/plugin install svn://rubyforge.org/var/svn/atomicobjectrb/tags/constructor</div>
|
29
|
-
|
30
|
-
<a href="rdoc/index.html"><img border=0 src="sample_code.png"></a>
|
31
|
-
</div>
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
</body>
|
36
|
-
</html>
|
Binary file
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<map name="GraffleExport">
|
2
|
-
<area shape=rect coords="486,91,635,108" href="http://atomicobjectrb.rubyforge.org/">
|
3
|
-
<area shape=rect coords="485,120,635,187" href="rdoc/index.html">
|
4
|
-
<area shape=rect coords="310,120,463,187" href="http://rubyforge.org/frs/?group_id=4897&release_id=16546">
|
5
|
-
<area shape=rect coords="14,91,168,108" href="http://atomicobject.com">
|
6
|
-
<area shape=rect coords="572,16,627,71" href="http://atomicobjectrb.rubyforge.org/">
|
7
|
-
<area shape=rect coords="21,13,83,75" href="http://atomicobject.com">
|
8
|
-
</map>
|
9
|
-
<img border=0 src="page_header.png" usemap="#GraffleExport">
|
Binary file
|
Binary file
|
@@ -1,127 +0,0 @@
|
|
1
|
-
CONSTRUCTOR_VERSION = '1.0.4' #:nodoc:#
|
2
|
-
|
3
|
-
class Class #:nodoc:#
|
4
|
-
def constructor(*attrs, &block)
|
5
|
-
call_block = ''
|
6
|
-
if block_given?
|
7
|
-
@constructor_block = block
|
8
|
-
call_block = 'self.instance_eval(&self.class.constructor_block)'
|
9
|
-
end
|
10
|
-
# Look for embedded options in the listing:
|
11
|
-
opts = attrs.find { |a| a.kind_of?(Hash) and attrs.delete(a) }
|
12
|
-
do_acc = opts.nil? ? false : opts[:accessors] == true
|
13
|
-
do_reader = opts.nil? ? false : opts[:readers] == true
|
14
|
-
require_args = opts.nil? ? true : opts[:strict] != false
|
15
|
-
super_args = opts.nil? ? nil : opts[:super]
|
16
|
-
|
17
|
-
# Incorporate superclass's constructor keys, if our superclass
|
18
|
-
if superclass.constructor_keys
|
19
|
-
similar_keys = superclass.constructor_keys & attrs
|
20
|
-
raise "Base class already has keys #{similar_keys.inspect}" unless similar_keys.empty?
|
21
|
-
attrs = [attrs,superclass.constructor_keys].flatten
|
22
|
-
end
|
23
|
-
# Generate ivar assigner code lines
|
24
|
-
assigns = ''
|
25
|
-
attrs.each do |k|
|
26
|
-
assigns += "@#{k.to_s} = args[:#{k.to_s}]\n"
|
27
|
-
end
|
28
|
-
|
29
|
-
# If accessors option is on, declare accessors for the attributes:
|
30
|
-
if do_acc
|
31
|
-
add_accessors = "attr_accessor " + attrs.reject {|x| superclass.constructor_keys.include?(x.to_sym)}.map {|x| ":#{x.to_s}"}.join(',')
|
32
|
-
#add_accessors = "attr_accessor " + attrs.map {|x| ":#{x.to_s}"}.join(',')
|
33
|
-
self.class_eval add_accessors
|
34
|
-
end
|
35
|
-
|
36
|
-
# If readers option is on, declare readers for the attributes:
|
37
|
-
if do_reader
|
38
|
-
self.class_eval "attr_reader " + attrs.reject {|x| superclass.constructor_keys.include?(x.to_sym)}.map {|x| ":#{x.to_s}"}.join(',')
|
39
|
-
end
|
40
|
-
|
41
|
-
# If user supplied super-constructor hints:
|
42
|
-
super_call = ''
|
43
|
-
if super_args
|
44
|
-
list = super_args.map do |a|
|
45
|
-
case a
|
46
|
-
when String
|
47
|
-
%|"#{a}"|
|
48
|
-
when Symbol
|
49
|
-
%|:#{a}|
|
50
|
-
end
|
51
|
-
end
|
52
|
-
super_call = %|super(#{list.join(',')})|
|
53
|
-
end
|
54
|
-
|
55
|
-
# If strict is on, define the constructor argument validator method,
|
56
|
-
# and setup the initializer to invoke the validator method.
|
57
|
-
# Otherwise, insert lax code into the initializer.
|
58
|
-
validation_code = "return if args.nil?"
|
59
|
-
if require_args
|
60
|
-
self.class_eval do
|
61
|
-
def _validate_constructor_args(args)
|
62
|
-
# First, make sure we've got args of some kind
|
63
|
-
unless args and args.keys and args.keys.size > 0
|
64
|
-
raise ConstructorArgumentError.new(self.class.constructor_keys)
|
65
|
-
end
|
66
|
-
# Scan for missing keys in the argument hash
|
67
|
-
a_keys = args.keys
|
68
|
-
missing = []
|
69
|
-
self.class.constructor_keys.each do |ck|
|
70
|
-
unless a_keys.member?(ck)
|
71
|
-
missing << ck
|
72
|
-
end
|
73
|
-
a_keys.delete(ck) # Delete inbound keys as we address them
|
74
|
-
end
|
75
|
-
if missing.size > 0 || a_keys.size > 0
|
76
|
-
raise ConstructorArgumentError.new(missing,a_keys)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
# Setup the code to insert into the initializer:
|
81
|
-
validation_code = "_validate_constructor_args args "
|
82
|
-
end
|
83
|
-
|
84
|
-
# Generate the initializer code
|
85
|
-
self.class_eval %{
|
86
|
-
def initialize(args=nil)
|
87
|
-
#{super_call}
|
88
|
-
#{validation_code}
|
89
|
-
#{assigns}
|
90
|
-
setup if respond_to?(:setup)
|
91
|
-
#{call_block}
|
92
|
-
end
|
93
|
-
}
|
94
|
-
|
95
|
-
# Remember our constructor keys
|
96
|
-
@_ctor_keys = attrs
|
97
|
-
end
|
98
|
-
|
99
|
-
# Access the constructor keys for this class
|
100
|
-
def constructor_keys; @_ctor_keys ||=[]; end
|
101
|
-
|
102
|
-
def constructor_block #:nodoc:#
|
103
|
-
@constructor_block
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
# Fancy validation exception, based on missing and extraneous keys.
|
109
|
-
class ConstructorArgumentError < RuntimeError #:nodoc:#
|
110
|
-
def initialize(missing,rejected=[])
|
111
|
-
err_msg = ''
|
112
|
-
if missing.size > 0
|
113
|
-
err_msg = "Missing constructor args [#{missing.join(',')}]"
|
114
|
-
end
|
115
|
-
if rejected.size > 0
|
116
|
-
# Some inbound keys were not addressed earlier; this means they're unwanted
|
117
|
-
if err_msg
|
118
|
-
err_msg << "; " # Appending to earlier message about missing items
|
119
|
-
else
|
120
|
-
err_msg = ''
|
121
|
-
end
|
122
|
-
# Enumerate the rejected key names
|
123
|
-
err_msg << "Rejected constructor args [#{rejected.join(',')}]"
|
124
|
-
end
|
125
|
-
super err_msg
|
126
|
-
end
|
127
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
class ConstructorStruct
|
2
|
-
def self.new(*accessors, &block)
|
3
|
-
defaults = {:accessors => true, :strict => false}
|
4
|
-
|
5
|
-
accessor_names = accessors.dup
|
6
|
-
if accessors.last.is_a? Hash
|
7
|
-
accessor_names.pop
|
8
|
-
user_opts = accessors.last
|
9
|
-
user_opts.delete(:accessors)
|
10
|
-
defaults.each do |k,v|
|
11
|
-
user_opts[k] ||= v
|
12
|
-
end
|
13
|
-
else
|
14
|
-
accessors << defaults
|
15
|
-
end
|
16
|
-
|
17
|
-
Class.new do
|
18
|
-
constructor *accessors
|
19
|
-
|
20
|
-
class_eval(&block) if block
|
21
|
-
|
22
|
-
comparator_code = accessor_names.map { |fname| "self.#{fname} == o.#{fname}" }.join(" && ")
|
23
|
-
eval %|
|
24
|
-
def ==(o)
|
25
|
-
(self.class == o.class) && #{comparator_code}
|
26
|
-
end
|
27
|
-
def eql?(o)
|
28
|
-
(self.class == o.class) && #{comparator_code}
|
29
|
-
end
|
30
|
-
|
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,407 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../lib/constructor')
|
2
|
-
|
3
|
-
describe 'standard constructor usage' do
|
4
|
-
it 'allows for object construction using a hash of named arguments' do
|
5
|
-
fuh = TestingClass.new(
|
6
|
-
:foo => 'my foo',
|
7
|
-
:bar => 'my bar',
|
8
|
-
:qux => 'my qux',
|
9
|
-
:why => 'lucky'
|
10
|
-
)
|
11
|
-
|
12
|
-
fuh.foo.should eql('my foo')
|
13
|
-
fuh.bar.should eql('my bar')
|
14
|
-
fuh.qux.should eql('my qux')
|
15
|
-
fuh.why.should eql('lucky')
|
16
|
-
fuh.to_pretty_pretty.should eql('my foo my bar')
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'calls setup method if defined' do
|
20
|
-
ralph = Llamma.new :hair => 'red'
|
21
|
-
ralph.hungry.should be_true
|
22
|
-
ralph.hair.should eql('red')
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "constructor's accessor option" do
|
27
|
-
it 'provides accessors for constructor arguments when accessor option is true' do
|
28
|
-
fuh = TestingAutoAccessors.new(
|
29
|
-
:foo => 'my foo',
|
30
|
-
:bar => 'my bar',
|
31
|
-
:qux => 'my qux',
|
32
|
-
:why => 'lucky'
|
33
|
-
)
|
34
|
-
fuh.foo.should eql('my foo')
|
35
|
-
fuh.bar.should eql('my bar')
|
36
|
-
fuh.qux.should eql('my qux')
|
37
|
-
fuh.why.should eql('lucky')
|
38
|
-
fuh.to_pretty_pretty.should eql('my foo my bar')
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'does not provide accessors for constructor arguments when accessor option is false' do
|
42
|
-
fuh = TestingBlockedAccessors.new :foo => 'my foo', :bar => 'my bar'
|
43
|
-
lambda {fuh.foo}.should raise_error(NoMethodError)
|
44
|
-
lambda {fuh.bar}.should raise_error(NoMethodError)
|
45
|
-
fuh.to_pretty_pretty.should eql('my foo my bar')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "constructor's reader option" do
|
50
|
-
it 'provides readers for constructor arguments when reader option is true' do
|
51
|
-
fuh = TestingAutoReaders.new(
|
52
|
-
:foo => 'my foo',
|
53
|
-
:why => 'lucky'
|
54
|
-
)
|
55
|
-
fuh.foo.should eql('my foo')
|
56
|
-
fuh.why.should eql('lucky')
|
57
|
-
fuh.to_pretty_pretty.should eql('my foo lucky')
|
58
|
-
|
59
|
-
lambda {fuh.why = 'no way'}.should raise_error(NoMethodError)
|
60
|
-
lambda {fuh.foo = 'uh uh'}.should raise_error(NoMethodError)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'does not provide reader for constructor arguments when reader option is false' do
|
64
|
-
fuh = TestingBlockedReaders.new :foo => 'my foo', :why => 'my why'
|
65
|
-
lambda {fuh.foo}.should raise_error(NoMethodError)
|
66
|
-
lambda {fuh.bar}.should raise_error(NoMethodError)
|
67
|
-
fuh.to_pretty_pretty.should eql('my foo my why')
|
68
|
-
|
69
|
-
lambda {fuh.why = 'no way'}.should raise_error(NoMethodError)
|
70
|
-
lambda {fuh.foo = 'uh uh'}.should raise_error(NoMethodError)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe 'using constructor with inheritance' do
|
75
|
-
it 'allows for inheritance of constructor arguments using a non-constructor defined subclass' do
|
76
|
-
fuh = SubclassOfTestingClass.new :foo => 'whu?'
|
77
|
-
fuh.foo.should eql('whu?')
|
78
|
-
fuh.bar.should be_nil
|
79
|
-
fuh.qux.should be_nil
|
80
|
-
fuh.why.should be_nil
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'allows for standard construction of a non-constructor subclass of a non-strict constuctor superclass' do
|
84
|
-
fuh = SubclassOfTestingClass2.new
|
85
|
-
fuh.foo.should be_nil
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'runs initialize method of a sublcass' do
|
89
|
-
fuh = SubclassOfTestingClass3.new
|
90
|
-
fuh.my_new_var.should eql('something')
|
91
|
-
fuh.foo.should be_nil
|
92
|
-
fuh.bar.should be_nil
|
93
|
-
fuh.qux.should be_nil
|
94
|
-
fuh.why.should be_nil
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'passes named constructor args to superclass when subclass calls super' do
|
98
|
-
fuh = SubclassOfTestingClass3.new :foo => 12
|
99
|
-
fuh.my_new_var.should eql('something')
|
100
|
-
fuh.foo.should eql(12)
|
101
|
-
fuh.bar.should be_nil
|
102
|
-
fuh.qux.should be_nil
|
103
|
-
fuh.why.should be_nil
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'allows for inheritance of constructor arguments using a constructor defined subclass' do
|
107
|
-
s = Sonny.new :car => 'Nissan', :saw => 'Dewalt', :computer => 'Dell'
|
108
|
-
s.computer.should eql('Dell')
|
109
|
-
s.saw.should eql('Dewalt')
|
110
|
-
s.car.should eql('Nissan')
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'calls the setup method on superclass if subclass does not define a setup method' do
|
114
|
-
baby = Baby.new :cuteness => 'little', :age => 1
|
115
|
-
baby.fat.should eql('much')
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'calls parent class setup when super is called from subclass setup' do
|
119
|
-
m = Mama.new :age => 55
|
120
|
-
m.age.should eql(55)
|
121
|
-
m.fat.should eql('much')
|
122
|
-
|
123
|
-
s = Sissy.new :age => 19, :beauty => 'medium', :fat => 'yeah'
|
124
|
-
s.age.should eql(19)
|
125
|
-
s.beauty.should eql('medium')
|
126
|
-
s.fat.should eql('much')
|
127
|
-
s.friends.should eql('many')
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'passes arguments given in the super option to the initializer of a non-constructor defined superclass' do
|
131
|
-
tsc = TestingSuperConstructor.new(:far => 'oo', :away => 'kk')
|
132
|
-
tsc.far.should eql('oo')
|
133
|
-
tsc.away.should eql('kk')
|
134
|
-
tsc.a.should eql("once")
|
135
|
-
tsc.b.should eql(:twice)
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'calls non-constructor defined superclass constructor when the super option is an empty array' do
|
139
|
-
tsc = TestingSuperConstructor2.new(:some => 'thing')
|
140
|
-
tsc.some.should eql('thing')
|
141
|
-
tsc.c.should eql('what a')
|
142
|
-
tsc.d.should eql('day for')
|
143
|
-
end
|
144
|
-
|
145
|
-
it "raises an error if subclass tries to build a constructor with the keys as its parents" do
|
146
|
-
class1 = constructor_class(Object, :star, :wars)
|
147
|
-
class2 = constructor_class(class1, :space, :balls)
|
148
|
-
lambda { constructor_class(class2, :star, :space, :chewy) }.should raise_error("Base class already has keys [:space, :star]")
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'does not create accessors for superclass constructor arguments' do
|
152
|
-
tas = TestingAccessorSubclass.new(:far => 'thing')
|
153
|
-
tas.respond_to?(:cuteness).should be_false
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'does not create a reader for superclass constructor arguments' do
|
157
|
-
t1 = TestingReaderSubclass.new(:foo => 'thing')
|
158
|
-
t1.respond_to?(:foo).should be_false
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
describe 'stict mode usage' do
|
163
|
-
it 'allows omission of arguments when strict is off' do
|
164
|
-
fuh = TestingClass.new :foo => 'my foo'
|
165
|
-
|
166
|
-
fuh.foo.should eql('my foo')
|
167
|
-
fuh.bar.should be_nil
|
168
|
-
fuh.qux.should be_nil
|
169
|
-
fuh.why.should be_nil
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'allows no arguments to a constructor when strict is off' do
|
173
|
-
fuh = TestingClass.new
|
174
|
-
fuh.foo.should be_nil
|
175
|
-
fuh.bar.should be_nil
|
176
|
-
fuh.qux.should be_nil
|
177
|
-
fuh.why.should be_nil
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'does not interfere with normal object construction' do
|
181
|
-
require 'rexml/document'
|
182
|
-
d = REXML::Document.new '<base/>'
|
183
|
-
d.should_not be_nil
|
184
|
-
d.root.name.should eql('base')
|
185
|
-
end
|
186
|
-
|
187
|
-
def see_strict_args_in_effect_for(clazz)
|
188
|
-
fuh = clazz.new :foo => 'my foo', :bar => 'my bar'
|
189
|
-
fuh.to_pretty_pretty.should eql('my foo my bar')
|
190
|
-
|
191
|
-
# Omit foo
|
192
|
-
lambda {
|
193
|
-
TestingStrictArgsDefault.new :bar => 'ok,yeah'
|
194
|
-
}.should raise_error(ConstructorArgumentError, /foo/)
|
195
|
-
|
196
|
-
# Omit bar
|
197
|
-
lambda {
|
198
|
-
TestingStrictArgsDefault.new :foo => 'ok,yeah'
|
199
|
-
}.should raise_error(ConstructorArgumentError, /bar/)
|
200
|
-
end
|
201
|
-
|
202
|
-
it 'defaults to strict argument enforcement' do
|
203
|
-
see_strict_args_in_effect_for TestingStrictArgsDefault
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'enforces strict arguments when strict option is true' do
|
207
|
-
see_strict_args_in_effect_for TestingStrictArgs
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'does not allow empty constructor arguments when strict option is true' do
|
211
|
-
lambda {TestingStrictArgs.new {}}.should raise_error(ConstructorArgumentError,/foo,bar/)
|
212
|
-
lambda {TestingStrictArgs.new}.should raise_error(ConstructorArgumentError,/foo,bar/)
|
213
|
-
lambda {TestingStrictArgs.new nil}.should raise_error(ConstructorArgumentError,/foo,bar/)
|
214
|
-
end
|
215
|
-
|
216
|
-
it 'does not allow extraneous arguments when strict option is true' do
|
217
|
-
[ /thing/, /other/ ].each do |rejected_arg|
|
218
|
-
lambda {
|
219
|
-
TestingStrictArgs.new(:foo => 1, :bar => 2, :other => 3, :thing => 4)
|
220
|
-
}.should raise_error(ConstructorArgumentError, rejected_arg)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
it 'allows for setting accessors option while in strict mode' do
|
225
|
-
t2 = TestingStrictArgs2.new :foo => 1, :bar => 2
|
226
|
-
|
227
|
-
# See that accessors work
|
228
|
-
t2.foo.should eql(1)
|
229
|
-
t2.bar.should eql(2)
|
230
|
-
|
231
|
-
# See that strictness still applies
|
232
|
-
lambda {TestingStrictArgs2.new :no => 'good'}.should raise_error(ConstructorArgumentError)
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
describe 'catching ConstructorArgumentError' do
|
237
|
-
it 'allows for generic rescuing of constructor argument errors' do
|
238
|
-
begin
|
239
|
-
TestingStrictArgs.new :broken => 'yoobetcha'
|
240
|
-
rescue => bad_news
|
241
|
-
bad_news.should be_kind_of(ConstructorArgumentError)
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
describe 'block yielding' do
|
247
|
-
it 'executes a specified block after instantiating' do
|
248
|
-
TestingBlockYield.new(:a => false).a.should == true
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
def constructor_class(base, *keys)
|
253
|
-
Class.new(base) do
|
254
|
-
constructor *keys
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
class TestingClass
|
259
|
-
attr_accessor :foo, :bar, :why, :qux
|
260
|
-
constructor :foo, :bar, :why, :qux, :strict => false
|
261
|
-
|
262
|
-
def to_pretty_pretty
|
263
|
-
"#{@foo} #{@bar}"
|
264
|
-
end
|
265
|
-
|
266
|
-
end
|
267
|
-
|
268
|
-
class Mama
|
269
|
-
attr_accessor :fat, :age
|
270
|
-
constructor :age, :strict => false
|
271
|
-
def setup
|
272
|
-
@fat = "much"
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
class Baby < Mama
|
277
|
-
constructor :cuteness
|
278
|
-
end
|
279
|
-
|
280
|
-
class Sissy < Mama
|
281
|
-
attr_accessor :friends, :beauty
|
282
|
-
constructor :beauty, :strict => false
|
283
|
-
def setup
|
284
|
-
super #IMPORTANT!
|
285
|
-
@friends = "many"
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
class TestingStrictArgsDefault
|
290
|
-
constructor :foo, :bar
|
291
|
-
def to_pretty_pretty
|
292
|
-
"#{@foo} #{@bar}"
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
class TestingStrictArgs
|
297
|
-
constructor :foo, :bar, :strict => true
|
298
|
-
def to_pretty_pretty
|
299
|
-
"#{@foo} #{@bar}"
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
class TestingStrictArgs2
|
304
|
-
constructor :foo, :bar, :accessors => true
|
305
|
-
end
|
306
|
-
|
307
|
-
class SubclassOfTestingClass < TestingClass
|
308
|
-
end
|
309
|
-
|
310
|
-
class SubclassOfTestingClass2 < TestingClass
|
311
|
-
def initialize; end
|
312
|
-
end
|
313
|
-
|
314
|
-
class SubclassOfTestingClass3 < TestingClass
|
315
|
-
attr_reader :my_new_var
|
316
|
-
def initialize(hash = nil)
|
317
|
-
super
|
318
|
-
@my_new_var = "something"
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
class TestingAutoAccessors
|
323
|
-
constructor :foo, :bar, :why, :qux, :accessors => true, :strict => false
|
324
|
-
def to_pretty_pretty
|
325
|
-
"#{@foo} #{@bar}"
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
class TestingAutoReaders
|
330
|
-
constructor :foo, :why, :readers => true, :strict => false
|
331
|
-
def to_pretty_pretty
|
332
|
-
"#{@foo} #{@why}"
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
class TestingReaderSuperclass
|
337
|
-
constructor :foo
|
338
|
-
end
|
339
|
-
|
340
|
-
class TestingReaderSubclass < TestingReaderSuperclass
|
341
|
-
constructor :bar, :readers => true, :strict => false
|
342
|
-
end
|
343
|
-
|
344
|
-
class TestingSuperConstructorBase
|
345
|
-
attr_reader :a, :b
|
346
|
-
def initialize(a,b)
|
347
|
-
@a = a
|
348
|
-
@b = b
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
class TestingSuperConstructor < TestingSuperConstructorBase
|
353
|
-
constructor :far, :away, :accessors => true, :super => ["once", :twice], :strict => false
|
354
|
-
end
|
355
|
-
|
356
|
-
class TestingSuperConstructorBase2
|
357
|
-
attr_reader :c, :d
|
358
|
-
def initialize
|
359
|
-
@c = 'what a'
|
360
|
-
@d = 'day for'
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
class TestingSuperConstructor2 < TestingSuperConstructorBase2
|
365
|
-
constructor :some, :accessors => true, :super => [], :strict => false
|
366
|
-
end
|
367
|
-
|
368
|
-
class TestingAccessorSubclass < Baby
|
369
|
-
constructor :foo, :accessors => true, :strict => false
|
370
|
-
end
|
371
|
-
|
372
|
-
class TestingBlockedAccessors
|
373
|
-
constructor :foo, :bar, :accessors => false
|
374
|
-
def to_pretty_pretty
|
375
|
-
"#{@foo} #{@bar}"
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
class TestingBlockedReaders
|
380
|
-
constructor :foo, :why, :readers => false
|
381
|
-
def to_pretty_pretty
|
382
|
-
"#{@foo} #{@why}"
|
383
|
-
end
|
384
|
-
end
|
385
|
-
|
386
|
-
class Papa
|
387
|
-
constructor :car, :saw
|
388
|
-
end
|
389
|
-
|
390
|
-
class Sonny < Papa
|
391
|
-
attr_accessor :car, :saw, :computer
|
392
|
-
constructor :computer
|
393
|
-
end
|
394
|
-
|
395
|
-
class Llamma
|
396
|
-
attr_accessor :hungry, :hair
|
397
|
-
constructor :hair
|
398
|
-
def setup
|
399
|
-
@hungry = true
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
class TestingBlockYield
|
404
|
-
constructor :a, :accessors => true do
|
405
|
-
@a = true
|
406
|
-
end
|
407
|
-
end
|