alter-ego 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,284 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ module AssertionsSpecHelper
4
+ def do_success(&block)
5
+ do_assertion(@success_values.first, &block)
6
+ end
7
+ def do_failure(&block)
8
+ do_assertion(@failure_values.first, &block)
9
+ end
10
+ end
11
+
12
+ describe "any assertion", :shared => true do
13
+ it "on failure, should raise an exception with trimmed backtrace" do
14
+ begin
15
+ do_failure
16
+ rescue AssertionFailureError => e
17
+ e.backtrace.first.should include(__FILE__)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "a basic assertion", :shared => true do
23
+ it "should raise AssertionFailureError when it fails" do
24
+ @failure_values.each do |value|
25
+ lambda do
26
+ do_assertion(value)
27
+ end.should raise_error(AssertionFailureError)
28
+ end
29
+ end
30
+
31
+ it "should not raise an exception when it succeeds" do
32
+ @success_values.each do |value|
33
+ lambda do
34
+ do_assertion(value)
35
+ end.should_not raise_error
36
+ end
37
+ end
38
+
39
+ it "should return its argument on success" do
40
+ @success_values.each do |value|
41
+ do_assertion(value).should equal(value)
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ describe "an assertion taking a block", :shared => true do
48
+ it "should fail if the block result is not true" do
49
+ lambda do
50
+ do_success { false }
51
+ end.should raise_error(AssertionFailureError)
52
+ end
53
+ end
54
+
55
+ describe "an assertion yielding passed values", :shared => true do
56
+
57
+ it_should_behave_like "an assertion taking a block"
58
+
59
+ it "should yield values that pass the test" do
60
+ @success_values.each do |value|
61
+ did_yield = false
62
+ do_assertion(value) do |yielded_value|
63
+ did_yield = true
64
+ yielded_value.should equal(value)
65
+ true
66
+ end
67
+ did_yield.should be_true
68
+ end
69
+ end
70
+
71
+ it "should not yield values that fail the test" do
72
+ @failure_values.each do |value|
73
+ did_yield = false
74
+ lambda do
75
+ do_assertion(value) do |yielded_value|
76
+ did_yield = true
77
+ end
78
+ end.should raise_error(AssertionFailureError)
79
+ did_yield.should be_false
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+ describe "an assertion taking multiple values", :shared => true do
86
+ def gather_arguments(values)
87
+ args = []
88
+ # gather 3 arguments
89
+ 3.times do |i|
90
+ args[i] = values[i % values.size]
91
+ end
92
+ args
93
+ end
94
+
95
+ it "should not raise error if all values succeed test" do
96
+ values = gather_arguments(@success_values)
97
+ lambda { do_assertion(*values) }.should_not raise_error
98
+ end
99
+
100
+ it "should raise error if all values fail test" do
101
+ values = gather_arguments(@failure_values)
102
+ lambda { do_assertion(*values) }.should raise_error(AssertionFailureError)
103
+ end
104
+
105
+ it "should raise error if one values fails test" do
106
+ values = gather_arguments(@success_values)
107
+ values[1] = @failure_values.first
108
+ lambda { do_assertion(*values) }.should raise_error(AssertionFailureError)
109
+ end
110
+
111
+ it "should return the last argument on success" do
112
+ values = gather_arguments(@success_values)
113
+ do_assertion(*values).should equal(values.last)
114
+ end
115
+
116
+ end
117
+
118
+ describe Assertions, "#assert" do
119
+
120
+ include Assertions
121
+ include AssertionsSpecHelper
122
+
123
+ def do_assertion(*args, &block)
124
+ assert(*args, &block)
125
+ end
126
+
127
+ before :each do
128
+ @success_values = [true, "", 0]
129
+ @failure_values = [false, nil]
130
+ end
131
+
132
+ it_should_behave_like "any assertion"
133
+ it_should_behave_like "a basic assertion"
134
+ it_should_behave_like "an assertion taking multiple values"
135
+ it_should_behave_like "an assertion yielding passed values"
136
+ end
137
+
138
+ describe Assertions, "#assert_exists" do
139
+
140
+ include Assertions
141
+ include AssertionsSpecHelper
142
+
143
+ def do_assertion(*args, &block)
144
+ assert_exists(*args, &block)
145
+ end
146
+
147
+ before :each do
148
+ @success_values = ["foo", 123, false]
149
+ @failure_values = [nil]
150
+ end
151
+
152
+ it_should_behave_like "any assertion"
153
+ it_should_behave_like "a basic assertion"
154
+ it_should_behave_like "an assertion taking multiple values"
155
+ it_should_behave_like "an assertion yielding passed values"
156
+
157
+ end
158
+
159
+ describe Assertions, "#assert_one_or_more" do
160
+
161
+ include Assertions
162
+ include AssertionsSpecHelper
163
+
164
+ def do_assertion(*args, &block)
165
+ assert_one_or_more(*args, &block)
166
+ end
167
+
168
+ before :each do
169
+ @success_values = [[1], {:foo => :bar }]
170
+ @failure_values = [nil, [], "foo"]
171
+ end
172
+
173
+ it_should_behave_like "any assertion"
174
+ it_should_behave_like "a basic assertion"
175
+ it_should_behave_like "an assertion taking multiple values"
176
+ it_should_behave_like "an assertion yielding passed values"
177
+ end
178
+
179
+ describe Assertions, "#deny" do
180
+
181
+ include Assertions
182
+ include AssertionsSpecHelper
183
+
184
+ def do_assertion(*args, &block)
185
+ deny(*args, &block)
186
+ end
187
+
188
+ before :each do
189
+ @success_values = [false, nil]
190
+ @failure_values = [true, "", 0]
191
+ end
192
+
193
+ it_should_behave_like "any assertion"
194
+ it_should_behave_like "a basic assertion"
195
+ it_should_behave_like "an assertion taking multiple values"
196
+ it_should_behave_like "an assertion yielding passed values"
197
+ end
198
+
199
+ describe Assertions, "#assert_keys" do
200
+
201
+ include Assertions
202
+
203
+ def do_assertion(*args, &block)
204
+ assert_keys(*args, &block)
205
+ end
206
+
207
+ def do_success(&block)
208
+ assert_keys({}, &block)
209
+ end
210
+
211
+ def do_failure(&block)
212
+ assert_keys({}, :foo, &block)
213
+ end
214
+
215
+ it_should_behave_like "any assertion"
216
+ it_should_behave_like "an assertion taking a block"
217
+
218
+ it "should fail if a specified key does not exist" do
219
+ lambda { assert_keys({}, :foo) }.should raise_error(AssertionFailureError)
220
+ end
221
+
222
+ it "should fail if a specified key is nil" do
223
+ lambda do
224
+ assert_keys({:foo => nil}, :foo)
225
+ end.should raise_error(AssertionFailureError)
226
+ end
227
+
228
+ it "should fail if any of the specified keys are nil" do
229
+ lambda do
230
+ assert_keys({:foo => true, :bar => nil}, :foo, :bar)
231
+ end.should raise_error(AssertionFailureError)
232
+ end
233
+
234
+ it "should fail if the given hash is nil" do
235
+ lambda do
236
+ assert_keys(nil)
237
+ end.should raise_error(AssertionFailureError)
238
+ end
239
+
240
+ it "should fail if given something unlike a hash" do
241
+ lambda do
242
+ assert_keys(true)
243
+ end.should raise_error(AssertionFailureError)
244
+ end
245
+
246
+ it "should succeed if no keys are given" do
247
+ lambda do
248
+ assert_keys({:foo => true, :bar => nil})
249
+ end.should_not raise_error
250
+ end
251
+
252
+ it "should yield key values if they all exist" do
253
+ did_yield = false
254
+ assert_keys({:foo => 23, :bar => 32}, :foo, :bar) do |x, y|
255
+ did_yield = true
256
+ x.should == 23
257
+ y.should == 32
258
+ true
259
+ end
260
+ did_yield.should be_true
261
+ end
262
+
263
+ it "should yield nothing if a key is missing" do
264
+ begin
265
+ did_yield = false
266
+ assert_keys({:foo => 23, :bar => 32}, :foo, :bar) do |x, y|
267
+ did_yield = true
268
+ end
269
+ rescue AssertionFailureError
270
+ did_yield.should be_false
271
+ end
272
+ end
273
+
274
+ it "should return the hash" do
275
+ @hash = { :buz => 42 }
276
+ assert_keys(@hash, :buz).should equal(@hash)
277
+ end
278
+ end
279
+
280
+ describe AssertionFailureError do
281
+ it "should derive from Exception" do
282
+ AssertionFailureError.superclass.should equal(Exception)
283
+ end
284
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'alter_ego'
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alter-ego
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Avdi Grimm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDKDCCAhCgAwIBAgIBADANBgkqhkiG9w0BAQUFADA6MQ0wCwYDVQQDDARhdmRp
14
+ MRQwEgYKCZImiZPyLGQBGRYEYXZkaTETMBEGCgmSJomT8ixkARkWA29yZzAeFw0w
15
+ ODExMjYwMzQwMTBaFw0wOTExMjYwMzQwMTBaMDoxDTALBgNVBAMMBGF2ZGkxFDAS
16
+ BgoJkiaJk/IsZAEZFgRhdmRpMRMwEQYKCZImiZPyLGQBGRYDb3JnMIIBIjANBgkq
17
+ hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxp+TCbzj+cyaiE1xAqxO+irHbdNF+9y4
18
+ rZF3gCs0wfIcqeKDIvlks7FvH0Qj6yiAj8YHUgmuLORat2IBLBmX/G+G0Z2L6MLs
19
+ bNwx4YpbTW1cwOFVENSWwNjsvY68/I/EpAeRdtiskG/J33TDxi427dyBDSHsrQ8J
20
+ 4oC24EnKwsTOdHwkEaDEmZJQeo5ienR7dalAwIPCIm4tA41kbilLVpMVp0f1hn5o
21
+ cVFYZgJFOdNnggVO9B/0/doQhxvC4Jdj2XeoOdIkjul1VjCeF+s+i/PhnKk/Y0++
22
+ /9fBCqzfFHYay5TOtTLDlzc7WoN5NBtKChn1gG0AnD+mJ4EnjvgTIQIDAQABozkw
23
+ NzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUen5OQUuU+3P6OyVZ
24
+ NsrtAIO7DQcwDQYJKoZIhvcNAQEFBQADggEBAGwXuO2cpDc9m8iJmmbSjnDhhQYL
25
+ OssAG5bMy88JnrD+KufXA4BKvLTLkNtTSaNFvL74+FSIK8VwCUpEyn8rsYi3s6N8
26
+ /f5+5LDg19Jm6dmkRgFGQjF8cW0PheDtlY0Ywo+wdUhD+LFH+2VanZNx2dz6IjSh
27
+ A0uvcb+roaNG70ESPvoJO4PZFCkrgS2QE9TwnhRLi1DONaGmbMYWSZku4tHFEu+R
28
+ B/QQd37jgRGtEcplcoMaoCOqAvlIu6QkQt4X3jVhNGqeF2Wgmb1QXEF8cH/hqX4T
29
+ NNbtubu/GbyYwC2cb3Clh5gMrAYS765Q8U2aySfRySAFaQyPub+h0uVWkIc=
30
+ -----END CERTIFICATE-----
31
+
32
+ date: 2008-11-28 00:00:00 -05:00
33
+ default_executable:
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: activesupport
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.0.2
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: newgem
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.1.0
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.8.0
64
+ version:
65
+ description: AlterEgo is a Ruby implementation of the State pattern as described by the Gang of Four. It differs from other Ruby state machine libraries in that it focuses on providing polymorphic behavior based on object state. In effect, it makes it easy to give an object different personalities depending on the state it is in.
66
+ email:
67
+ - avdi@avdi.org
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ extra_rdoc_files:
73
+ - History.txt
74
+ - Manifest.txt
75
+ - PostInstall.txt
76
+ - README.rdoc
77
+ files:
78
+ - History.txt
79
+ - Manifest.txt
80
+ - PostInstall.txt
81
+ - README.rdoc
82
+ - State_Design_Pattern_UML_Class_Diagram.png
83
+ - Rakefile
84
+ - TODO
85
+ - lib/assertions.rb
86
+ - spec/assertions_spec.rb
87
+ - lib/alter_ego.rb
88
+ - script/console
89
+ - script/destroy
90
+ - script/generate
91
+ - spec/spec.opts
92
+ - spec/spec_helper.rb
93
+ - spec/alter_ego_spec.rb
94
+ - tasks/rspec.rake
95
+ has_rdoc: true
96
+ homepage: http://alter-ego.rubyforge.org
97
+ post_install_message:
98
+ rdoc_options:
99
+ - --main
100
+ - README.rdoc
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: "0"
108
+ version:
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: "0"
114
+ version:
115
+ requirements: []
116
+
117
+ rubyforge_project: alter-ego
118
+ rubygems_version: 1.2.0
119
+ signing_key:
120
+ specification_version: 2
121
+ summary: AlterEgo is a Ruby implementation of the State pattern as described by the Gang of Four
122
+ test_files: []
123
+
@@ -0,0 +1,2 @@
1
+ �?(��(��y�c.�#�~�Z��+�p��8���!W�J!S���N"�t>4]��-��g��xG�=�F\
2
+ Y�ɏ�m�(�;���.��>e"���>O