terrys-spec-helpers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/terrys-spec-helpers.rb +583 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/terrys-spec-helpers_spec.rb +7 -0
- metadata +127 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", ">= 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.8.4"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.7.5)
|
12
|
+
rake (0.9.2.2)
|
13
|
+
rdoc (3.12)
|
14
|
+
json (~> 1.4)
|
15
|
+
rspec (2.8.0)
|
16
|
+
rspec-core (~> 2.8.0)
|
17
|
+
rspec-expectations (~> 2.8.0)
|
18
|
+
rspec-mocks (~> 2.8.0)
|
19
|
+
rspec-core (2.8.0)
|
20
|
+
rspec-expectations (2.8.0)
|
21
|
+
diff-lcs (~> 1.1.2)
|
22
|
+
rspec-mocks (2.8.0)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
bundler (>= 1.0.0)
|
29
|
+
jeweler (~> 1.8.4)
|
30
|
+
rdoc (~> 3.12)
|
31
|
+
rspec (~> 2.8.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Terry S
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= terrys-spec-helpers
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to terrys-spec-helpers
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Terry S. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "terrys-spec-helpers"
|
18
|
+
gem.homepage = "http://github.com/itsterry/terrys-spec-helpers"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "A set of spec helpers generated during client projects and crystallized into one gem"
|
21
|
+
gem.description = "A set of spec helpers generated during client projects and crystallized into one gem"
|
22
|
+
gem.email = "itsterry@gmail.com"
|
23
|
+
gem.authors = ["Terry S"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::GemcutterTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "terrys-spec-helpers #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,583 @@
|
|
1
|
+
module Terrys_spec_helpers
|
2
|
+
|
3
|
+
def setup_variables(thing)
|
4
|
+
f=thing.to_s
|
5
|
+
@f=f.to_sym
|
6
|
+
@fp=(f+'=').to_sym
|
7
|
+
end
|
8
|
+
|
9
|
+
def accessor_present(thing)
|
10
|
+
describe "accessor #{thing}" do
|
11
|
+
before do
|
12
|
+
@o=@thing
|
13
|
+
@o.should be_valid
|
14
|
+
setup_variables(thing)
|
15
|
+
end
|
16
|
+
it 'should respond' do
|
17
|
+
@o.respond_to?(@f).should be_true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def acts_as_a_list
|
23
|
+
describe 'acts_as_list' do
|
24
|
+
describe 'given a blank position on save' do
|
25
|
+
before do
|
26
|
+
@o=@thing
|
27
|
+
@o.should be_valid
|
28
|
+
setup_variables('position')
|
29
|
+
end
|
30
|
+
it 'should add itself to the list' do
|
31
|
+
@o.send(@fp,nil)
|
32
|
+
@o.save
|
33
|
+
@o.send(@f).should_not be_nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def forbidden_string(thing,options={})
|
40
|
+
describe "FORBIDDEN attribute #{thing} (reverse captcha)" do
|
41
|
+
before do
|
42
|
+
if options[:pending]
|
43
|
+
pending options[:pending]
|
44
|
+
end
|
45
|
+
@o=@thing
|
46
|
+
@o.should be_valid
|
47
|
+
setup_variables(thing)
|
48
|
+
end
|
49
|
+
it 'should respond' do
|
50
|
+
@o.respond_to?(@f).should be_true
|
51
|
+
end
|
52
|
+
it "should accept a nil value" do
|
53
|
+
@o.send(@fp,nil)
|
54
|
+
@o.save
|
55
|
+
@o.should be_valid
|
56
|
+
end
|
57
|
+
it "should accept a blank value" do
|
58
|
+
@o.send(@fp,'')
|
59
|
+
@o.save
|
60
|
+
@o.should be_valid
|
61
|
+
end
|
62
|
+
it "should reject a non-blank value" do
|
63
|
+
@o.send(@fp,'t')
|
64
|
+
@o.save
|
65
|
+
@o.should_not be_valid
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def it_should_expose(variable)
|
72
|
+
it "should expose the #{variable} variable" do
|
73
|
+
controller.send(variable).should_not be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def it_should_return_200
|
78
|
+
it "returns http success" do
|
79
|
+
response.should be_success
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def it_should_set_flash_alert
|
84
|
+
it "should set a flash alert" do
|
85
|
+
flash[:alert].should_not be_nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def it_should_set_flash_notice
|
90
|
+
it "should set a flash notice" do
|
91
|
+
flash[:notice].should_not be_nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def mandatory_boolean(thing)
|
96
|
+
describe "attribute #{thing}" do
|
97
|
+
before do
|
98
|
+
@o=@thing
|
99
|
+
@o.should be_valid
|
100
|
+
setup_variables(thing)
|
101
|
+
end
|
102
|
+
it 'should respond' do
|
103
|
+
@o.respond_to?(@f).should be_true
|
104
|
+
end
|
105
|
+
it "should be invalid if #{thing} is not true" do
|
106
|
+
@o.send(@fp,nil)
|
107
|
+
@o.save.should_not be_true
|
108
|
+
end
|
109
|
+
it "should be valid if #{thing} is true" do
|
110
|
+
@o.send(@fp,true)
|
111
|
+
@o.save.should be_true
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def mandatory_collection(thing, options={})
|
117
|
+
describe "association #{thing}" do
|
118
|
+
before do
|
119
|
+
if options[:pending]
|
120
|
+
pending options[:pending]
|
121
|
+
end
|
122
|
+
@o=@thing
|
123
|
+
@o.should be_valid
|
124
|
+
setup_variables(thing)
|
125
|
+
end
|
126
|
+
it 'should respond' do
|
127
|
+
@o.respond_to?(@f).should be_true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def mandatory_date(thing)
|
133
|
+
describe "attribute #{thing}" do
|
134
|
+
before do
|
135
|
+
@o=@thing
|
136
|
+
@o.should be_valid
|
137
|
+
setup_variables(thing)
|
138
|
+
end
|
139
|
+
it 'should respond' do
|
140
|
+
@o.respond_to?(@f).should be_true
|
141
|
+
end
|
142
|
+
it "should reject a nil value" do
|
143
|
+
@o.send(@fp,nil)
|
144
|
+
@o.save
|
145
|
+
@o.should_not be_valid
|
146
|
+
end
|
147
|
+
it "should reject a blank value" do
|
148
|
+
@o.send(@fp,'')
|
149
|
+
@o.save
|
150
|
+
@o.should_not be_valid
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def mandatory_datetime(thing,default=nil)
|
156
|
+
describe "attribute #{thing}" do
|
157
|
+
before do
|
158
|
+
@o=@thing
|
159
|
+
@o.should be_valid
|
160
|
+
setup_variables(thing)
|
161
|
+
end
|
162
|
+
it 'should respond' do
|
163
|
+
@o.respond_to?(@f).should be_true
|
164
|
+
end
|
165
|
+
if default
|
166
|
+
it "should set a nil value to the default if default exists" do
|
167
|
+
@o.send(@fp,nil)
|
168
|
+
@o.save
|
169
|
+
@o.send(@f).should==default
|
170
|
+
end
|
171
|
+
else
|
172
|
+
it "should reject a nil value if no default exists" do
|
173
|
+
@o.send(@fp,nil)
|
174
|
+
@o.save
|
175
|
+
@o.should_not be_valid
|
176
|
+
end
|
177
|
+
end
|
178
|
+
if default
|
179
|
+
it "should set a blank value to the default if default exists" do
|
180
|
+
@o.send(@fp,'')
|
181
|
+
@o.save
|
182
|
+
@o.send(@f).should==default
|
183
|
+
end
|
184
|
+
else
|
185
|
+
it "should reject a blank value if no default exists" do
|
186
|
+
@o.send(@fp,nil)
|
187
|
+
@o.save
|
188
|
+
@o.should_not be_valid
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def mandatory_float(thing)
|
195
|
+
describe "attribute #{thing}" do
|
196
|
+
before do
|
197
|
+
@o=@thing
|
198
|
+
@o.should be_valid
|
199
|
+
setup_variables(thing)
|
200
|
+
end
|
201
|
+
it 'should respond' do
|
202
|
+
@o.respond_to?(@f).should be_true
|
203
|
+
end
|
204
|
+
it "should reject a nil value" do
|
205
|
+
@o.send(@fp,nil)
|
206
|
+
@o.save
|
207
|
+
@o.should_not be_valid
|
208
|
+
end
|
209
|
+
it "should reject a blank value" do
|
210
|
+
@o.send(@fp,'')
|
211
|
+
@o.save
|
212
|
+
@o.should_not be_valid
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def mandatory_integer(thing)
|
218
|
+
describe "attribute #{thing}" do
|
219
|
+
before do
|
220
|
+
@o=@thing
|
221
|
+
@o.should be_valid
|
222
|
+
setup_variables(thing)
|
223
|
+
end
|
224
|
+
it 'should respond' do
|
225
|
+
@o.respond_to?(@f).should be_true
|
226
|
+
end
|
227
|
+
it "should reject a nil value" do
|
228
|
+
@o.send(@fp,nil)
|
229
|
+
@o.save
|
230
|
+
@o.should_not be_valid
|
231
|
+
end
|
232
|
+
it "should reject a blank value" do
|
233
|
+
@o.send(@fp,'')
|
234
|
+
@o.save
|
235
|
+
@o.should_not be_valid
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def mandatory_integer_or_default(thing,default)
|
241
|
+
describe "attribute #{thing}" do
|
242
|
+
before do
|
243
|
+
@o=@thing
|
244
|
+
@o.should be_valid
|
245
|
+
setup_variables(thing)
|
246
|
+
end
|
247
|
+
it 'should respond' do
|
248
|
+
@o.respond_to?(@f).should be_true
|
249
|
+
end
|
250
|
+
it "should set a nil value to default" do
|
251
|
+
@o.send(@fp,nil)
|
252
|
+
@o.save
|
253
|
+
@o.send(@f).should==default
|
254
|
+
end
|
255
|
+
it "should set a blank value to default" do
|
256
|
+
@o.send(@fp,'')
|
257
|
+
@o.save
|
258
|
+
@o.send(@f).should==default
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def mandatory_string(thing,options={})
|
264
|
+
describe "attribute #{thing}" do
|
265
|
+
before do
|
266
|
+
if options[:pending]
|
267
|
+
pending options[:pending]
|
268
|
+
end
|
269
|
+
@o=@thing
|
270
|
+
@o.should be_valid
|
271
|
+
setup_variables(thing)
|
272
|
+
end
|
273
|
+
it 'should respond' do
|
274
|
+
@o.respond_to?(@f).should be_true
|
275
|
+
end
|
276
|
+
it "should reject a nil value" do
|
277
|
+
@o.send(@fp,nil)
|
278
|
+
@o.save
|
279
|
+
@o.should_not be_valid
|
280
|
+
end
|
281
|
+
it "should reject a blank value" do
|
282
|
+
@o.send(@fp,'')
|
283
|
+
@o.save
|
284
|
+
@o.should_not be_valid
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
end
|
289
|
+
|
290
|
+
def mandatory_string_or_default(thing,default)
|
291
|
+
describe "attribute #{thing}" do
|
292
|
+
before do
|
293
|
+
@o=@thing
|
294
|
+
@o.should be_valid
|
295
|
+
setup_variables(thing)
|
296
|
+
end
|
297
|
+
it 'should respond' do
|
298
|
+
@o.respond_to?(@f).should be_true
|
299
|
+
end
|
300
|
+
it "should set a nil value to default" do
|
301
|
+
@o.send(@fp,nil)
|
302
|
+
@o.save
|
303
|
+
@o.send(@f).should==default
|
304
|
+
end
|
305
|
+
it "should set a blank value to default" do
|
306
|
+
@o.send(@fp,'')
|
307
|
+
@o.save
|
308
|
+
@o.send(@f).should==default
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
def mandatory_unique_string(thing)
|
314
|
+
describe "unique attribute #{thing}" do
|
315
|
+
mandatory_string(thing)
|
316
|
+
before do
|
317
|
+
@o=@thing
|
318
|
+
@o.should be_valid
|
319
|
+
setup_variables(thing)
|
320
|
+
end
|
321
|
+
it "should reject a duplicate value" do
|
322
|
+
z=@o.class.new(@o.attributes)
|
323
|
+
z.send(@f).should==@o.send(@f)
|
324
|
+
z.should_not be_valid
|
325
|
+
z.send(@fp,'zzz')
|
326
|
+
z.should be_valid
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
end
|
331
|
+
|
332
|
+
def mandatory_belongs_to(thing,options={})
|
333
|
+
describe "belongs_to association #{thing}" do
|
334
|
+
before do
|
335
|
+
if options[:pending]
|
336
|
+
pending options[:pending]
|
337
|
+
end
|
338
|
+
f_id=thing.to_s.downcase+'_id'
|
339
|
+
@o=@thing
|
340
|
+
@o.should be_valid
|
341
|
+
setup_variables(f_id)
|
342
|
+
if options[:class_name]
|
343
|
+
@klass=options[:class_name]
|
344
|
+
else
|
345
|
+
@klass=thing
|
346
|
+
end
|
347
|
+
end
|
348
|
+
it 'should respond' do
|
349
|
+
@o.respond_to?(@f).should be_true
|
350
|
+
end
|
351
|
+
it "should reject a nil value" do
|
352
|
+
@o.send(@fp,nil)
|
353
|
+
@o.save
|
354
|
+
@o.should_not be_valid
|
355
|
+
end
|
356
|
+
it 'should reject an invalid value' do
|
357
|
+
@klass.find(@o.send(@f)).should_not be_nil
|
358
|
+
@o.should be_valid
|
359
|
+
@o.send(@fp,999999)
|
360
|
+
@klass.find_by_id(@o.send(@f)).should be_nil
|
361
|
+
@o.should_not be_valid
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
|
366
|
+
end
|
367
|
+
|
368
|
+
def optional_accessor(thing,options={})
|
369
|
+
before do
|
370
|
+
if options[:pending]
|
371
|
+
pending options[:pending]
|
372
|
+
end
|
373
|
+
f_id=thing.to_s.downcase+'_id'
|
374
|
+
@o=@thing
|
375
|
+
@o.should be_valid
|
376
|
+
setup_variables(f_id)
|
377
|
+
end
|
378
|
+
it 'should respond' do
|
379
|
+
@o.respond_to?(@f).should be_true
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
def optional_belongs_to(thing, options={})
|
384
|
+
describe "belongs_to association #{thing}" do
|
385
|
+
before do
|
386
|
+
if options[:pending]
|
387
|
+
pending options[:pending]
|
388
|
+
end
|
389
|
+
f_id=thing.to_s.downcase+'_id'
|
390
|
+
@o=@thing
|
391
|
+
@o.should be_valid
|
392
|
+
setup_variables(f_id)
|
393
|
+
if options[:class_name]
|
394
|
+
@klass=options[:class_name]
|
395
|
+
else
|
396
|
+
@klass=thing
|
397
|
+
end
|
398
|
+
end
|
399
|
+
it 'should respond' do
|
400
|
+
@o.respond_to?(@f).should be_true
|
401
|
+
end
|
402
|
+
it 'should make an invalid value nil' do
|
403
|
+
@o.send(@fp,999999)
|
404
|
+
@klass.find_by_id(@o.send(@f)).should be_nil
|
405
|
+
@o.valid?
|
406
|
+
@o.send(@f).should be_nil
|
407
|
+
end
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
def optional_boolean(thing)
|
412
|
+
describe "attribute #{thing}" do
|
413
|
+
before do
|
414
|
+
@o=@thing
|
415
|
+
@o.should be_valid
|
416
|
+
setup_variables(thing)
|
417
|
+
end
|
418
|
+
it 'should respond' do
|
419
|
+
@o.respond_to?(@f).should be_true
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
def optional_date(thing)
|
425
|
+
describe "attribute #{thing}" do
|
426
|
+
before do
|
427
|
+
@o=@thing
|
428
|
+
@o.should be_valid
|
429
|
+
setup_variables(thing)
|
430
|
+
end
|
431
|
+
it 'should respond' do
|
432
|
+
@o.respond_to?(@f).should be_true
|
433
|
+
end
|
434
|
+
it "should make a blank value nil" do
|
435
|
+
@o.send(@fp,'')
|
436
|
+
@o.save
|
437
|
+
@o.send(@f).should be_nil
|
438
|
+
end
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
442
|
+
def optional_datetime(thing)
|
443
|
+
describe "attribute #{thing}" do
|
444
|
+
before do
|
445
|
+
@o=@thing
|
446
|
+
@o.should be_valid
|
447
|
+
setup_variables(thing)
|
448
|
+
end
|
449
|
+
it 'should respond' do
|
450
|
+
@o.respond_to?(@f).should be_true
|
451
|
+
end
|
452
|
+
it "should make a blank value nil" do
|
453
|
+
@o.send(@fp,'')
|
454
|
+
@o.save
|
455
|
+
@o.send(@f).should be_nil
|
456
|
+
end
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
def optional_float(thing)
|
461
|
+
describe "attribute #{thing}" do
|
462
|
+
before do
|
463
|
+
@o=@thing
|
464
|
+
@o.should be_valid
|
465
|
+
setup_variables(thing)
|
466
|
+
end
|
467
|
+
it 'should respond' do
|
468
|
+
@o.respond_to?(@f).should be_true
|
469
|
+
end
|
470
|
+
it "should make a blank value nil" do
|
471
|
+
@o.send(@fp,'')
|
472
|
+
@o.save
|
473
|
+
@o.send(@f).should be_nil
|
474
|
+
end
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
def optional_integer(thing)
|
479
|
+
describe "attribute #{thing}" do
|
480
|
+
before do
|
481
|
+
@o=@thing
|
482
|
+
@o.should be_valid
|
483
|
+
setup_variables(thing)
|
484
|
+
end
|
485
|
+
it 'should respond' do
|
486
|
+
@o.respond_to?(@f).should be_true
|
487
|
+
end
|
488
|
+
it "should make a blank value nil" do
|
489
|
+
@o.send(@fp,'')
|
490
|
+
@o.save
|
491
|
+
@o.send(@f).should be_nil
|
492
|
+
end
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
def optional_string(thing)
|
497
|
+
describe "attribute #{thing}" do
|
498
|
+
before do
|
499
|
+
@o=@thing
|
500
|
+
@o.should be_valid
|
501
|
+
setup_variables(thing)
|
502
|
+
end
|
503
|
+
it 'should respond' do
|
504
|
+
@o.respond_to?(@f).should be_true
|
505
|
+
end
|
506
|
+
it "should make a blank value nil" do
|
507
|
+
@o.send(@fp,'')
|
508
|
+
@o.save
|
509
|
+
@o.send(@f).should be_nil
|
510
|
+
end
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
def there_can_be_only_one(thing,options={})
|
515
|
+
describe "there can only be one item with attribute #{thing} set to true" do
|
516
|
+
before do
|
517
|
+
if options[:pending]
|
518
|
+
pending options[:pending]
|
519
|
+
end
|
520
|
+
@o=@thing
|
521
|
+
@o.should be_valid
|
522
|
+
setup_variables(thing)
|
523
|
+
end
|
524
|
+
describe "where it is not the first item and #{thing} is true" do
|
525
|
+
before do
|
526
|
+
@z=@o.class.new(@o.attributes)
|
527
|
+
if options[:attributes]
|
528
|
+
@z.update_attributes(options[:attributes])
|
529
|
+
end
|
530
|
+
@o.send(@fp,false)
|
531
|
+
@z.send(@fp,true)
|
532
|
+
@z.save.should be_true
|
533
|
+
@o.save.should be_true
|
534
|
+
@z.send(@f).should be_true
|
535
|
+
@o.send(@f).should be_false
|
536
|
+
end
|
537
|
+
it "should set to false any other items with #{thing} set to true" do
|
538
|
+
@o.send(@fp,true)
|
539
|
+
@o.save.should be_true
|
540
|
+
@o.send(@f).should be_true
|
541
|
+
@z.send(@f).should be_false
|
542
|
+
end
|
543
|
+
end
|
544
|
+
end
|
545
|
+
|
546
|
+
end
|
547
|
+
|
548
|
+
def there_must_be_one(thing,options={})
|
549
|
+
describe "there must be at least one item with attribute #{thing} set to true" do
|
550
|
+
before do
|
551
|
+
if options[:pending]
|
552
|
+
pending options[:pending]
|
553
|
+
end
|
554
|
+
@o=@thing
|
555
|
+
@o.should be_valid
|
556
|
+
setup_variables(thing)
|
557
|
+
end
|
558
|
+
describe "where it is the first item and #{thing} is false" do
|
559
|
+
before do
|
560
|
+
(@o.class.all-[@o]).each{|o| o.delete}
|
561
|
+
@o.class.count.should==1
|
562
|
+
@o.send(@fp,false)
|
563
|
+
@o.send(@f).should be_false
|
564
|
+
end
|
565
|
+
it "it should set #{thing} to true" do
|
566
|
+
@o.save
|
567
|
+
@o.send(@f).should be_true
|
568
|
+
end
|
569
|
+
end
|
570
|
+
describe "where it is the last item with #{thing} set to true" do
|
571
|
+
before do
|
572
|
+
@o.send(@fp,true)
|
573
|
+
@o.save.should be_true
|
574
|
+
@o.send(@f).should be_true
|
575
|
+
end
|
576
|
+
it "should not be able to be destroyed" do
|
577
|
+
@o.destroy.should be_false
|
578
|
+
end
|
579
|
+
end
|
580
|
+
end
|
581
|
+
end
|
582
|
+
|
583
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'terrys-spec-helpers'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: terrys-spec-helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Terry S
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.8.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.8.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.4
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.4
|
78
|
+
description: A set of spec helpers generated during client projects and crystallized
|
79
|
+
into one gem
|
80
|
+
email: itsterry@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files:
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.rdoc
|
86
|
+
files:
|
87
|
+
- .document
|
88
|
+
- .rspec
|
89
|
+
- Gemfile
|
90
|
+
- Gemfile.lock
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.rdoc
|
93
|
+
- Rakefile
|
94
|
+
- VERSION
|
95
|
+
- lib/terrys-spec-helpers.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
- spec/terrys-spec-helpers_spec.rb
|
98
|
+
homepage: http://github.com/itsterry/terrys-spec-helpers
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
hash: -372868721
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.8.24
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: A set of spec helpers generated during client projects and crystallized into
|
126
|
+
one gem
|
127
|
+
test_files: []
|