tengine_support 0.3.27 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Gemfile +3 -20
  2. data/lib/tengine/support/core_ext/enumerable/map_to_hash.rb +20 -0
  3. data/lib/tengine/support/mongoid.rb +59 -0
  4. data/lib/tengine/support/null_logger.rb +1 -1
  5. data/lib/tengine/support.rb +4 -3
  6. metadata +80 -76
  7. data/.document +0 -5
  8. data/.rspec +0 -1
  9. data/.travis.yml +0 -11
  10. data/NULL +0 -1
  11. data/Rakefile +0 -43
  12. data/VERSION +0 -1
  13. data/gemfiles/Gemfile.activesupport-3.0.10 +0 -24
  14. data/gemfiles/Gemfile.activesupport-3.1.1 +0 -24
  15. data/gemfiles/Gemfile.activesupport-3.2.3 +0 -24
  16. data/spec/spec_helper.rb +0 -15
  17. data/spec/support/app1.rb +0 -27
  18. data/spec/support/suite.rb +0 -182
  19. data/spec/tengine/support/config/amqp_spec.rb +0 -32
  20. data/spec/tengine/support/config/logger_spec.rb +0 -316
  21. data/spec/tengine/support/config/mongoid_spec.rb +0 -24
  22. data/spec/tengine/support/config_spec/dump_skelton_spec.rb +0 -171
  23. data/spec/tengine/support/config_spec/load_config_file_by_config_option_spec.rb +0 -94
  24. data/spec/tengine/support/config_spec/load_spec.rb +0 -239
  25. data/spec/tengine/support/config_spec/load_spec_01.yml.erb +0 -43
  26. data/spec/tengine/support/config_spec/load_spec_01_with_other_settings.yml.erb +0 -48
  27. data/spec/tengine/support/config_spec/load_spec_02.yml.erb +0 -52
  28. data/spec/tengine/support/config_spec/parse_spec.rb +0 -178
  29. data/spec/tengine/support/config_spec.rb +0 -217
  30. data/spec/tengine/support/core_ext/array/deep_dup_spec.rb +0 -69
  31. data/spec/tengine/support/core_ext/enumerable/deep_freeze_spec.rb +0 -16
  32. data/spec/tengine/support/core_ext/enumerable/each_next_tick_spec.rb +0 -29
  33. data/spec/tengine/support/core_ext/hash/compact_spec.rb +0 -28
  34. data/spec/tengine/support/core_ext/hash/deep_dup_spec.rb +0 -66
  35. data/spec/tengine/support/core_ext/hash/keys_spec.rb +0 -88
  36. data/spec/tengine/support/mongoid_spec.rb +0 -36
  37. data/spec/tengine/support/null_logger_spec.rb +0 -13
  38. data/spec/tengine/support/yaml_with_erb_spec/test1.yml.erb +0 -2
  39. data/spec/tengine/support/yaml_with_erb_spec/test2_with_erb.yml +0 -2
  40. data/spec/tengine/support/yaml_with_erb_spec/test3_without_erb.yml +0 -2
  41. data/spec/tengine/support/yaml_with_erb_spec/test4_with_invalid_erb.yml +0 -2
  42. data/spec/tengine/support/yaml_with_erb_spec.rb +0 -76
  43. data/tengine_support.gemspec +0 -125
@@ -1,178 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
3
-
4
- describe "config" do
5
- describe :parse! do
6
- context "setting1" do
7
- shared_examples_for "common_data" do
8
- it { subject.action.should == 'start'}
9
- it { subject.config.should == nil}
10
- it { subject.process.should be_a(App1::ProcessConfig) }
11
- # it { subject.process.daemon.should == nil}
12
- it { subject.process.pid_dir.should == nil}
13
- it { subject.db.should be_a(Tengine::Support::Config::Mongoid::Connection) }
14
- it { subject.db.host.should == "mongo1"}
15
- # it { subject.db.port.should == 27017}
16
- it { subject.db.username.should == 'goku'}
17
- it { subject.db.password.should == 'ideyoshenlong'}
18
- it { subject.db.database.should == "tengine_production"}
19
- it { subject.event_queue.connection.host.should == "localhost"}
20
- it { subject.event_queue.connection.port.should == 5672}
21
- it { subject.event_queue.exchange.name.should == "tengine_event_exchange"}
22
- it { subject.event_queue.exchange.type.should == 'direct'}
23
- it { subject.event_queue.exchange.durable.should == true}
24
- it { subject.event_queue.queue.name.should == "tengine_event_queue"}
25
- it { subject.event_queue.queue.durable.should == true}
26
- it { subject.log_common.output.should == "STDOUT"}
27
- it { subject.log_common.rotation.should == 3}
28
- it { subject.log_common.rotation_size.should == 1024 * 1024}
29
- it { subject.log_common.level.should == "debug"}
30
- # it { subject.application_log.output.should == "STDOUT"}
31
- it { subject.application_log.rotation.should == 3}
32
- it { subject.application_log.rotation_size.should == 1024 * 1024}
33
- it { subject.application_log.level.should == "debug"}
34
- # it { subject.process_stdout_log.output.should == "STDOUT"}
35
- it { subject.process_stdout_log.rotation.should == 3}
36
- it { subject.process_stdout_log.rotation_size.should == 1024 * 1024}
37
- it { subject.process_stdout_log.level.should == "info"}
38
- # it { subject.process_stderr_log.output.should == "STDOUT"}
39
- it { subject.process_stderr_log.rotation.should == 3}
40
- it { subject.process_stderr_log.rotation_size.should == 1024 * 1024}
41
- it { subject.process_stderr_log.level.should == "debug"}
42
- end
43
-
44
- shared_examples_for "data1" do
45
- it { subject.db.port.should == 27017}
46
- it { subject.process.daemon.should == nil}
47
- it { subject.application_log.output.should == "STDOUT"}
48
- it { subject.process_stdout_log.output.should == "STDOUT"}
49
- it { subject.process_stderr_log.output.should == "STDOUT"}
50
- end
51
-
52
- shared_examples_for "data2" do
53
- it { subject.db.port.should == 27020}
54
- it { subject.process.daemon.should == true}
55
- it { subject.application_log.output.should == "./log/application.log"}
56
- it { subject.process_stdout_log.output.should == "./log/suite_stdout.log"}
57
- it { subject.process_stderr_log.output.should == "./log/suite_stderr.log"}
58
- end
59
-
60
- context "use long option name" do
61
- before(:all) do
62
- @suite = build_suite1
63
- @suite.parse!(%w[--action=start --db-host=mongo1 --db-username=goku --db-password=ideyoshenlong --log-common-level=debug --process-stdout-log-level=info])
64
- end
65
- subject{ @suite }
66
- it_should_behave_like "common_data"
67
- it_should_behave_like "data1"
68
- end
69
-
70
- context "use short option name" do
71
- before(:all) do
72
- @suite = build_suite1
73
- @suite.parse!(%w[-k start -O mongo1 -U goku -S ideyoshenlong --log-common-level=debug --process-stdout-log-level=info])
74
- end
75
- subject{ @suite }
76
- it_should_behave_like "common_data"
77
- it_should_behave_like "data1"
78
- end
79
-
80
- context "field value specified" do
81
- context "long option name" do
82
- before(:all) do
83
- @suite = build_suite1
84
- @suite.parse!(%w[-k start -O mongo1 -U goku -S ideyoshenlong --log-common-level=debug --process-stdout-log-level=info] +
85
- %w[--process-daemon --db-port=27020])
86
- end
87
- subject{ @suite }
88
- it_should_behave_like "common_data"
89
- it_should_behave_like "data2"
90
- end
91
-
92
- context "short options name" do
93
- before(:all) do
94
- @suite = build_suite1
95
- @suite.parse!(%w[-k start -O mongo1 -U goku -S ideyoshenlong --log-common-level=debug --process-stdout-log-level=info] +
96
- %w[-D -P 27020])
97
- end
98
- subject{ @suite }
99
- it_should_behave_like "common_data"
100
- it_should_behave_like "data2"
101
- end
102
- end
103
-
104
- context "show help" do
105
- it do
106
- @suite = build_suite1
107
- STDOUT.should_receive(:puts).with(HELP_MESSAGE)
108
- expect{
109
- @suite.parse!(%w[--help])
110
- }.to raise_error(SystemExit)
111
- end
112
- end
113
-
114
- end
115
-
116
- end
117
-
118
- end
119
-
120
-
121
- HELP_MESSAGE = <<END_OF_HELP
122
- Usage: config_test [-k action] [-f path_to_config]
123
- [-H db_host] [-P db_port] [-U db_user] [-S db_pass] [-B db_database]
124
-
125
- -k, --action=VAL test|load|start|enable|stop|force-stop|status|activate default: "start"
126
- -f, --config=VAL path/to/config_file
127
-
128
- process:
129
- -D, --process-daemon process works on background.
130
- --process-pid-dir=VAL path/to/dir for PID created.
131
-
132
- db:
133
- -O, --db-host=VAL hostname to connect db. default: "localhost"
134
- -P, --db-port=VAL port to connect db. default: 27017
135
- -U, --db-username=VAL username to connect db.
136
- -S, --db-password=VAL password to connect db.
137
- --db-database=VAL database name to connect db. default: "tengine_production"
138
-
139
- log_common:
140
- --log-common-output=VAL file path or "STDOUT" / "STDERR" / "NULL". default: "STDOUT"
141
- --log-common-level=VAL Logging severity threshold. must be one of debug,info,warn,error,fatal default: "info"
142
- --log-common-progname=VAL program name to include in log messages.
143
- --log-common-datetime-format=VAL
144
- A string suitable for passing to strftime.
145
-
146
- application_log:
147
- --application-log-output=VAL file path or "STDOUT" / "STDERR" / "NULL". if daemon process then "./log/application.log" else "STDOUT" default: "STDOUT"
148
- --application-log-level=VAL Logging severity threshold. value of --log-common-level must be one of debug,info,warn,error,fatal default: "info"
149
- --application-log-progname=VAL
150
- program name to include in log messages.
151
- --application-log-datetime-format=VAL
152
- A string suitable for passing to strftime.
153
-
154
- process_stdout_log:
155
- --process-stdout-log-output=VAL
156
- file path or "STDOUT" / "STDERR" / "NULL". if daemon process then "./log/suite_stdout.log" else "STDOUT" default: "STDOUT"
157
- --process-stdout-log-level=VAL
158
- Logging severity threshold. value of --log-common-level must be one of debug,info,warn,error,fatal default: "info"
159
- --process-stdout-log-progname=VAL
160
- program name to include in log messages.
161
- --process-stdout-log-datetime-format=VAL
162
- A string suitable for passing to strftime.
163
-
164
- process_stderr_log:
165
- --process-stderr-log-output=VAL
166
- file path or "STDOUT" / "STDERR" / "NULL". if daemon process then "./log/suite_stderr.log" else "STDOUT" default: "STDOUT"
167
- --process-stderr-log-level=VAL
168
- Logging severity threshold. value of --log-common-level must be one of debug,info,warn,error,fatal default: "info"
169
- --process-stderr-log-progname=VAL
170
- program name to include in log messages.
171
- --process-stderr-log-datetime-format=VAL
172
- A string suitable for passing to strftime.
173
-
174
- General:
175
- --version show version
176
- --dump-skelton dump skelton of config
177
- --help show this help message
178
- END_OF_HELP
@@ -1,217 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
-
4
- describe "config" do
5
-
6
- context "app1 setting" do
7
- context "static" do
8
-
9
- describe App1::ProcessConfig.daemon do
10
- it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
11
- its(:type){ should == :boolean }
12
- its(:__name__){ should == :daemon }
13
- its(:description){ should == 'process works on background.'}
14
- its(:default){ should == nil}
15
- end
16
-
17
- describe App1::ProcessConfig.pid_dir do
18
- it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
19
- its(:type){ should == :directory }
20
- its(:__name__){ should == :pid_dir }
21
- its(:description){ should == 'path/to/dir for PID created.'}
22
- its(:default){ should == nil}
23
- end
24
- end
25
-
26
- context "dynamic" do
27
- before(:all) do
28
- @suite = build_suite1
29
- end
30
-
31
- subject do
32
- @suite
33
- end
34
-
35
- describe "accessors" do
36
- it { subject.action.should == "start"}
37
- it { subject.config.should == nil}
38
- it { subject.process.should be_a(App1::ProcessConfig) }
39
- it { subject.process.daemon.should == nil}
40
- it { subject.process.pid_dir.should == nil}
41
- it { subject.db.should be_a(Tengine::Support::Config::Mongoid::Connection) }
42
- it { subject.db.host.should == "localhost"}
43
- it { subject.db.port.should == 27017}
44
- it { subject.db.username.should == nil}
45
- it { subject.db.password.should == nil}
46
- it { subject.db.database.should == "tengine_production"}
47
- it { subject.event_queue.connection.host.should == "localhost"}
48
- it { subject.event_queue.connection.port.should == 5672}
49
- it { subject.event_queue.exchange.name.should == "tengine_event_exchange"}
50
- it { subject.event_queue.exchange.type.should == 'direct'}
51
- it { subject.event_queue.exchange.durable.should == true}
52
- it { subject.event_queue.queue.name.should == "tengine_event_queue"}
53
- it { subject.event_queue.queue.durable.should == true}
54
- it { subject.log_common.output.should == "STDOUT"}
55
- it { subject.log_common.rotation.should == 3}
56
- it { subject.log_common.rotation_size.should == 1024 * 1024}
57
- it { subject.log_common.level.should == "info"}
58
- it { subject.application_log.output.should == "STDOUT"}
59
- it { subject.application_log.rotation.should == 3}
60
- it { subject.application_log.rotation_size.should == 1024 * 1024}
61
- it { subject.application_log.level.should == "info"}
62
- end
63
-
64
- it :to_hash do
65
- subject.to_hash.should == {
66
- :action => 'start',
67
- :config => nil,
68
- :process => {
69
- :daemon => nil,
70
- :pid_dir => nil,
71
- },
72
- :db => {
73
- :host => 'localhost',
74
- :port => 27017,
75
- :username => nil,
76
- :password => nil,
77
- :database => 'tengine_production'
78
- },
79
- :event_queue => {
80
- :connection => {
81
- :host => 'localhost',
82
- :port => 5672,
83
- :vhost => nil,
84
- :user => nil,
85
- :pass => nil,
86
- :heartbeat_interval => 0,
87
- },
88
- :exchange => {
89
- :name => 'tengine_event_exchange',
90
- :type => 'direct',
91
- :durable => true,
92
- },
93
- :queue => {
94
- :name => 'tengine_event_queue',
95
- :durable => true,
96
- },
97
- },
98
-
99
- :log_common => {
100
- :output => "STDOUT" ,
101
- :rotation => 3 ,
102
- :rotation_size => 1024 * 1024,
103
- :level => 'info' ,
104
- :progname => nil, :datetime_format => nil,
105
- }.freeze,
106
-
107
- :application_log => {
108
- :output => "STDOUT",
109
- :rotation=>3, :rotation_size=>1048576, :level=>"info",
110
- :progname => nil, :datetime_format => nil,
111
- }.freeze,
112
-
113
- :process_stdout_log => {
114
- :output => "STDOUT",
115
- :rotation=>3, :rotation_size=>1048576, :level=>"info",
116
- :progname => nil, :datetime_format => nil,
117
- }.freeze,
118
-
119
- :process_stderr_log => {
120
- :output => "STDOUT",
121
- :rotation=>3, :rotation_size=>1048576, :level=>"info",
122
- :progname => nil, :datetime_format => nil,
123
- }.freeze,
124
- }
125
- end
126
-
127
- it "suite has children" do
128
- subject.children.map(&:__name__).should == [
129
- :action, :config,
130
- :process, :db, :event_queue, :log_common,
131
- :application_log, :process_stdout_log, :process_stderr_log, :separator10, :version, :dump_skelton, :help]
132
- end
133
-
134
- context "suite returns child by name" do
135
- {
136
- :process => App1::ProcessConfig,
137
- :db => Tengine::Support::Config::Mongoid::Connection,
138
- :event_queue => Tengine::Support::Config::Definition::Group,
139
- [:event_queue, :connection] => NilClass,
140
- [:event_queue, :exchange ] => NilClass,
141
- [:event_queue, :queue ] => NilClass,
142
- :log_common => Tengine::Support::Config::Logger,
143
- :application_log => App1::LoggerConfig,
144
- :process_stdout_log => App1::LoggerConfig,
145
- :process_stderr_log => App1::LoggerConfig,
146
- }.each do |name, klass|
147
- it{ subject.child_by_name(name).should be_a(klass) }
148
- end
149
-
150
- {
151
- :process => App1::ProcessConfig,
152
- :db => Tengine::Support::Config::Mongoid::Connection,
153
- :event_queue => Tengine::Support::Config::Definition::Group,
154
- [:event_queue, :connection] => Tengine::Support::Config::Amqp::Connection,
155
- [:event_queue, :exchange ] => Tengine::Support::Config::Amqp::Exchange,
156
- [:event_queue, :queue ] => Tengine::Support::Config::Amqp::Queue,
157
- :log_common => Tengine::Support::Config::Logger,
158
- :application_log => App1::LoggerConfig,
159
- :process_stdout_log => App1::LoggerConfig,
160
- :process_stderr_log => App1::LoggerConfig,
161
- }.each do |name_array, klass|
162
- it{ subject.find(name_array).should be_a(klass) }
163
- end
164
- end
165
-
166
- context "parent and children" do
167
- it do
168
- log_common = subject.find(:log_common)
169
- application_log = subject.find(:application_log)
170
- log_common.should_not == application_log
171
- log_common.children.each do |log_common_child|
172
- application_log_child = application_log.child_by_name(log_common_child.__name__)
173
- application_log_child.should_not be_nil
174
- application_log_child.__name__.should == log_common_child.__name__
175
- application_log_child.object_id.should_not == log_common_child.object_id
176
- application_log_child.__parent__.should == application_log
177
- log_common_child.__parent__.should == log_common
178
- end
179
- end
180
- end
181
-
182
- context "dependencies" do
183
- it do
184
- application_log = subject.find(:application_log)
185
- application_log.process_config.should_not be_nil
186
- application_log.process_config.should be_a(App1::ProcessConfig)
187
- application_log.log_common.should_not be_nil
188
- application_log.log_common.should be_a(Tengine::Support::Config::Logger)
189
- end
190
- end
191
-
192
- context "parameters" do
193
- it{ subject.application_log.logger_name.should == "application" }
194
- it{ subject.process_stdout_log.logger_name.should == "suite_stdout" }
195
- it{ subject.process_stderr_log.logger_name.should == "suite_stderr" }
196
- end
197
-
198
- end
199
- end
200
-
201
- describe ConfigSuite3 do
202
- context "instance" do
203
- subject{ ConfigSuite3.new }
204
-
205
- it "ログの出力先のデフォルト値" do
206
- subject.application_log.output.should == "STDOUT"
207
- end
208
-
209
- it "明示的にnilを設定してもデフォルト値が得られる" do
210
- subject.application_log.output = nil
211
- subject.application_log.output.should == "STDOUT"
212
- end
213
-
214
- end
215
- end
216
-
217
- end
@@ -1,69 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/../../../../spec_helper')
3
-
4
- require 'active_support'
5
- require "tengine/support/core_ext/array/deep_dup"
6
-
7
- describe "tengine/support/core_ext/array/deep_dup" do
8
-
9
- original = [
10
- :a,
11
- [
12
- :b,
13
- [:c, :d].freeze,
14
- {
15
- :e => {
16
- :f => [:g, :h].freeze,
17
- :i => {:j => :k}.freeze,
18
- }.freeze
19
- }.freeze
20
- ].freeze
21
- ].freeze
22
-
23
- context "Hash#deep_dupがある場合" do
24
- before do
25
- load("tengine/support/core_ext/hash/deep_dup.rb")
26
- end
27
-
28
- subject{ original.deep_dup }
29
- it { subject.should == original }
30
- it { subject.object_id.should_not == original.object_id }
31
- it { subject[1].object_id.should_not == original[1].object_id }
32
- it { subject[1][1].object_id.should_not == original[1][1].object_id }
33
- it { subject[1][2].object_id.should_not == original[1][2].object_id }
34
- it { subject[1][2][:e].object_id.should_not == original[1][2][:e].object_id }
35
- it { subject[1][2][:e][:f].object_id.should_not == original[1][2][:e][:f].object_id }
36
- it { subject[1][2][:e][:i].object_id.should_not == original[1][2][:e][:i].object_id }
37
- end
38
-
39
- context "Hash#deep_dupがない場合" do
40
- before do
41
- if Hash.instance_methods.include?(:deep_dup)
42
- Hash.class_eval do
43
- undef deep_dup
44
- end
45
- end
46
- end
47
- after do
48
- load("tengine/support/core_ext/hash/deep_dup.rb")
49
- end
50
-
51
- subject{ original.deep_dup }
52
- it { subject.should == original }
53
- it { subject.object_id.should_not == original.object_id }
54
- it { subject[1].object_id.should_not == original[1].object_id }
55
- it { subject[1][1].object_id.should_not == original[1][1].object_id }
56
-
57
- context "オブジェクトが変わらない" do
58
- before do
59
- pending "なぜかobject_idが変わってしまう。" if RUBY_VERSION == "1.8.7"
60
- end
61
-
62
- it { subject[1][2].object_id.should == original[1][2].object_id }
63
- it { subject[1][2][:e].object_id.should == original[1][2][:e].object_id }
64
- it { subject[1][2][:e][:f].object_id.should == original[1][2][:e][:f].object_id }
65
- it { subject[1][2][:e][:i].object_id.should == original[1][2][:e][:i].object_id }
66
- end
67
- end
68
-
69
- end
@@ -1,16 +0,0 @@
1
- require File.expand_path('../../../../spec_helper', File.dirname(__FILE__))
2
- require "tengine/support/core_ext/enumerable/deep_freeze"
3
-
4
- describe Enumerable do
5
- describe "#deep_freeze" do
6
- subject { { "q" => { "w" => { "e" => { "r" => { "t" => { "y" => "u" } } } } } }.deep_freeze }
7
- it "recursive destructive freezing of the subject" do
8
- subject["q"].frozen?.should be_true
9
- subject["q"]["w"].frozen?.should be_true
10
- subject["q"]["w"]["e"].frozen?.should be_true
11
- subject["q"]["w"]["e"]["r"].frozen?.should be_true
12
- subject["q"]["w"]["e"]["r"]["t"].frozen?.should be_true
13
- subject["q"]["w"]["e"]["r"]["t"]["y"].frozen?.should be_true
14
- end
15
- end
16
- end
@@ -1,29 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.expand_path('../../../../spec_helper', File.dirname(__FILE__))
3
- require "tengine/support/core_ext/enumerable/each_next_tick"
4
-
5
- describe Enumerable do
6
- describe "#each_next_tick" do
7
- it "eachと同じ順にiterateする" do
8
- str = ""
9
- EM.run do
10
- [1, 2, 3, 4].each_next_tick do |i|
11
- str << i.to_s
12
- end
13
- EM.add_timer 0.1 do EM.stop end
14
- end
15
- str.should == "1234"
16
- end
17
-
18
- it "next_tickでやる" do
19
- str = ""
20
- EM.run do
21
- [1, 2, 3, 4].each_next_tick do |i|
22
- str << i.to_s
23
- end
24
- str.should be_empty
25
- EM.add_timer 0.1 do EM.stop end
26
- end
27
- end
28
- end
29
- end
@@ -1,28 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/../../../../spec_helper')
3
-
4
- require 'active_support'
5
- require "tengine/support/core_ext/hash/compact"
6
-
7
- describe Hash do
8
- describe "#compact!" do
9
- it "Array#compat!と同じ" do
10
- h = { :foo => :bar, :baz => nil }
11
- h.compact!
12
- h.should include(:foo)
13
- h.should_not include(:baz)
14
- end
15
- end
16
-
17
- describe "#compact" do
18
- it "非破壊的" do
19
- h = { :foo => :bar, :baz => nil }
20
- hh = h.compact
21
- h.should include(:foo)
22
- h.should include(:baz)
23
- hh.should include(:foo)
24
- hh.should_not include(:baz)
25
- end
26
- end
27
- end
28
-
@@ -1,66 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/../../../../spec_helper')
3
-
4
- require 'active_support'
5
- require "tengine/support/core_ext/hash/deep_dup"
6
-
7
- describe "tengine/support/core_ext/hash/deep_dup" do
8
-
9
- original = {
10
- :a => {
11
- :b => {
12
- :c => :d
13
- }.freeze,
14
- :e => [
15
- :f,
16
- {:g => :h}.freeze,
17
- [:i, :j].freeze
18
- ].freeze
19
- }.freeze
20
- }.freeze
21
-
22
- context "Array#deep_dupがある場合" do
23
- before do
24
- load("tengine/support/core_ext/array/deep_dup.rb")
25
- end
26
-
27
- subject{ original.deep_dup }
28
- it { subject.should == original }
29
- it { subject.object_id.should_not == original.object_id }
30
- it { subject[:a].object_id.should_not == original[:a].object_id }
31
- it { subject[:a][:b].object_id.should_not == original[:a][:b].object_id }
32
- it { subject[:a][:e].object_id.should_not == original[:a][:e].object_id }
33
- it { subject[:a][:e][1].object_id.should_not == original[:a][:e][1].object_id }
34
- it { subject[:a][:e][2].object_id.should_not == original[:a][:e][2].object_id }
35
- end
36
-
37
- context "Array#deep_dupがない場合" do
38
- before do
39
- if Array.instance_methods.include?(:deep_dup)
40
- Array.class_eval do
41
- remove_method(:deep_dup)
42
- end
43
- end
44
- end
45
- after do
46
- load("tengine/support/core_ext/array/deep_dup.rb")
47
- end
48
-
49
- subject{ original.deep_dup }
50
- it { subject.should == original }
51
- it { subject.object_id.should_not == original.object_id }
52
- it { subject[:a].object_id.should_not == original[:a].object_id }
53
- it { subject[:a][:b].object_id.should_not == original[:a][:b].object_id }
54
-
55
- context "オブジェクトが変わらない" do
56
- before do
57
- pending "なぜかobject_idが変わってしまう。" if RUBY_VERSION == "1.8.7"
58
- end
59
-
60
- it { subject[:a][:e].object_id.should == original[:a][:e].object_id }
61
- it { subject[:a][:e][1].object_id.should == original[:a][:e][1].object_id }
62
- it { subject[:a][:e][2].object_id.should == original[:a][:e][2].object_id }
63
- end
64
- end
65
-
66
- end