naught 1.0.0 → 2.0.0

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.
Files changed (55) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.txt +1 -1
  3. data/lib/naught/basic_object.rb +4 -14
  4. data/lib/naught/call_location.rb +131 -0
  5. data/lib/naught/caller_info.rb +128 -0
  6. data/lib/naught/chain_proxy.rb +51 -0
  7. data/lib/naught/conversions.rb +108 -34
  8. data/lib/naught/null_class_builder/command.rb +42 -5
  9. data/lib/naught/null_class_builder/commands/callstack.rb +89 -0
  10. data/lib/naught/null_class_builder/commands/define_explicit_conversions.rb +25 -9
  11. data/lib/naught/null_class_builder/commands/define_implicit_conversions.rb +22 -12
  12. data/lib/naught/null_class_builder/commands/impersonate.rb +21 -5
  13. data/lib/naught/null_class_builder/commands/mimic.rb +87 -25
  14. data/lib/naught/null_class_builder/commands/null_safe_proxy.rb +92 -0
  15. data/lib/naught/null_class_builder/commands/pebble.rb +21 -18
  16. data/lib/naught/null_class_builder/commands/predicates_return.rb +51 -31
  17. data/lib/naught/null_class_builder/commands/singleton.rb +18 -17
  18. data/lib/naught/null_class_builder/commands/traceable.rb +21 -12
  19. data/lib/naught/null_class_builder/commands.rb +10 -8
  20. data/lib/naught/null_class_builder.rb +217 -120
  21. data/lib/naught/stub_strategy.rb +30 -0
  22. data/lib/naught/version.rb +3 -1
  23. data/lib/naught.rb +31 -7
  24. metadata +34 -66
  25. data/.gitignore +0 -23
  26. data/.rspec +0 -2
  27. data/.rubocop.yml +0 -74
  28. data/.travis.yml +0 -20
  29. data/Changelog.md +0 -12
  30. data/Gemfile +0 -31
  31. data/Guardfile +0 -15
  32. data/README.markdown +0 -436
  33. data/Rakefile +0 -15
  34. data/naught.gemspec +0 -22
  35. data/spec/base_object_spec.rb +0 -47
  36. data/spec/basic_null_object_spec.rb +0 -35
  37. data/spec/blackhole_spec.rb +0 -16
  38. data/spec/explicit_conversions_spec.rb +0 -23
  39. data/spec/functions/actual_spec.rb +0 -22
  40. data/spec/functions/just_spec.rb +0 -22
  41. data/spec/functions/maybe_spec.rb +0 -35
  42. data/spec/functions/null_spec.rb +0 -34
  43. data/spec/implicit_conversions_spec.rb +0 -25
  44. data/spec/mimic_spec.rb +0 -117
  45. data/spec/naught/null_object_builder/command_spec.rb +0 -10
  46. data/spec/naught/null_object_builder_spec.rb +0 -31
  47. data/spec/naught_spec.rb +0 -101
  48. data/spec/pebble_spec.rb +0 -77
  49. data/spec/predicate_spec.rb +0 -84
  50. data/spec/singleton_null_object_spec.rb +0 -35
  51. data/spec/spec_helper.rb +0 -13
  52. data/spec/support/convertable_null.rb +0 -4
  53. data/spec/support/jruby.rb +0 -3
  54. data/spec/support/rubinius.rb +0 -3
  55. data/spec/support/ruby_18.rb +0 -3
data/.rubocop.yml DELETED
@@ -1,74 +0,0 @@
1
- AllCops:
2
- Includes:
3
- - 'Gemfile'
4
- - 'Rakefile'
5
- - 'naught.gemspec'
6
-
7
- # Avoid long parameter lists
8
- ParameterLists:
9
- Max: 4
10
- CountKeywordArgs: true
11
-
12
- ClassLength:
13
- Max: 144 # TODO: Lower to 100
14
-
15
- MethodLength:
16
- CountComments: false
17
- Max: 21 # TODO: Lower to 15
18
-
19
- # Avoid more than `Max` levels of nesting.
20
- BlockNesting:
21
- Max: 2
22
-
23
- # Align with the style guide.
24
- CollectionMethods:
25
- PreferredMethods:
26
- map: 'collect'
27
- reduce: 'inject'
28
- find: 'detect'
29
- find_all: 'select'
30
-
31
- # Limit line length
32
- LineLength:
33
- Enabled: false
34
-
35
- # Disable documentation checking until a class needs to be documented once
36
- Documentation:
37
- Enabled: false
38
-
39
- # Enforce Ruby 1.8-compatible hash syntax
40
- HashSyntax:
41
- EnforcedStyle: hash_rockets
42
-
43
- # No spaces inside hash literals
44
- SpaceInsideHashLiteralBraces:
45
- EnforcedStyle: no_space
46
-
47
- # Allow dots at the end of lines
48
- DotPosition:
49
- Enabled: false
50
-
51
- # Don't require magic comment at the top of every file
52
- Encoding:
53
- Enabled: false
54
-
55
- EmptyLinesAroundAccessModifier:
56
- Enabled: true
57
-
58
- # Align ends correctly
59
- EndAlignment:
60
- AlignWith: variable
61
-
62
- # Indentation of when/else
63
- CaseIndentation:
64
- IndentWhenRelativeTo: end
65
- IndentOneStep: false
66
-
67
- Lambda:
68
- Enabled: false
69
-
70
- MethodName:
71
- Enabled: false
72
-
73
- ClassVars:
74
- Enabled: false
data/.travis.yml DELETED
@@ -1,20 +0,0 @@
1
- before_install:
2
- - gem update --system 2.1.11
3
- - gem --version
4
- bundler_args: --without development
5
- language: ruby
6
- rvm:
7
- - 1.8.7
8
- - 1.9.2
9
- - 1.9.3
10
- - 2.0.0
11
- - 2.1.0
12
- - jruby
13
- - jruby-head
14
- - rbx
15
- - ruby-head
16
- matrix:
17
- allow_failures:
18
- - rvm: jruby-head
19
- - rvm: ruby-head
20
- fast_finish: true
data/Changelog.md DELETED
@@ -1,12 +0,0 @@
1
- ## 1.0.0
2
-
3
- - [Replace `::BasicObject` with `Naught::BasicObject`](https://github.com/avdi/naught/commit/8defad0bf9eb65e33054bf0a6e9c625c87c3e6df)
4
- - [Delegate explicit conversions to nil instead of defining them explicitly](https://github.com/avdi/naught/commit/85c195de80ed56993b88f47e09112c903a92a167)
5
- - Add support for (and run tests on) Ruby 1.8, 1.9, 2.0, 2.1, JRuby, and Rubinius
6
-
7
- ## 0.0.3
8
-
9
- Features:
10
-
11
- - New "pebble" mode (Guilherme Carvalho)
12
-
data/Gemfile DELETED
@@ -1,31 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in naught.gemspec
4
- gemspec
5
-
6
- gem 'rake'
7
-
8
- group :development do
9
- platforms :ruby_19, :ruby_20, :ruby_21 do
10
- gem 'guard'
11
- gem 'guard-bundler'
12
- gem 'guard-rspec'
13
- end
14
- gem 'pry'
15
- gem 'pry-rescue'
16
- end
17
-
18
- group :test do
19
- gem 'coveralls', :require => false
20
- gem 'json', :platforms => [:jruby, :rbx, :ruby_18, :ruby_19]
21
- gem 'libnotify'
22
- gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18]
23
- gem 'rspec', '>= 2.14'
24
- gem 'rubocop', '>= 0.16', :platforms => [:ruby_19, :ruby_20, :ruby_21]
25
- end
26
-
27
- platforms :rbx do
28
- gem 'racc'
29
- gem 'rubinius-coverage', '~> 2.0'
30
- gem 'rubysl', '~> 2.0'
31
- end
data/Guardfile DELETED
@@ -1,15 +0,0 @@
1
- guard 'bundler' do
2
- watch('Gemfile')
3
- watch(/^.+\.gemspec/)
4
- end
5
-
6
- guard :rspec, cli: '-fs --color --order rand' do
7
- watch(%r{^spec/.+_spec\.rb$})
8
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
- watch('spec/spec_helper.rb') { "spec" }
10
- end
11
-
12
- guard 'ctags-bundler', emacs: true, src_path: ["lib", "spec/support"] do
13
- watch(/^(lib|spec\/support)\/.*\.rb$/)
14
- watch('Gemfile.lock')
15
- end
data/README.markdown DELETED
@@ -1,436 +0,0 @@
1
- [![Build Status](https://travis-ci.org/avdi/naught.png?branch=master)](https://travis-ci.org/avdi/naught)
2
- [![Code Climate](https://codeclimate.com/github/avdi/naught.png)](https://codeclimate.com/github/avdi/naught)
3
- [![Coverage Status](https://coveralls.io/repos/avdi/naught/badge.png?branch=master)](https://coveralls.io/r/avdi/naught?branch=master)
4
- [![Gem Version](https://badge.fury.io/rb/naught.png)](http://badge.fury.io/rb/naught)
5
-
6
- A quick intro to Naught
7
- -------------------------
8
-
9
- #### What's all this now then?
10
-
11
- Naught is a toolkit for building [Null
12
- Objects](http://en.wikipedia.org/wiki/Null_Object_pattern) in Ruby.
13
-
14
- #### What's that supposed to mean?
15
-
16
- Null Objects can make your code more
17
- [confident](http://confidentruby.com).
18
-
19
- Here's a method that's not very sure of itself.
20
-
21
- ```ruby
22
- class Geordi
23
- def make_it_so(logger=nil)
24
- logger && logger.info("Reversing the flux phase capacitance!")
25
- logger && logger.info("Bounding a tachyon particle beam off of Data's cat!")
26
- logger && logger.warn("Warning, bogon levels are rising!")
27
- end
28
- end
29
- ```
30
-
31
- Now, observe as we give it a dash of confidence with the Null Object
32
- pattern!
33
-
34
- ```ruby
35
- class NullLogger
36
- def debug(*); end
37
- def info(*); end
38
- def warn(*); end
39
- def error(*); end
40
- def fatal(*); end
41
- end
42
-
43
- class Geordi
44
- def make_it_so(logger=NullLogger.new)
45
- logger.info "Reversing the flux phase capacitance!"
46
- logger.info "Bounding a tachyon particle beam off of Data's cat!"
47
- logger.warn "Warning, bogon levels are rising!"
48
- end
49
- end
50
- ```
51
-
52
- By providing a `NullLogger` which implements [some of] the `Logger`
53
- interface as no-op methods, we've gotten rid of those unsightly `&&`
54
- operators.
55
-
56
- #### That was simple enough. Why do I need a library for it?
57
-
58
- You don't! The Null Object pattern is a very simple one at its core.
59
-
60
- #### And yet here we are…
61
-
62
- Yes. While you don't *need* a Null Object library, this one offers some
63
- conveniences you probably won't find elsewhere.
64
-
65
- But there's an even more important reason I wrote this library. In the
66
- immortal last words of James T. Kirk: "It was… *fun!*"
67
-
68
- #### OK, so how do I use this thing?
69
-
70
- Well, what would you like to do?
71
-
72
- #### I dunno, gimme an object that responds to any message with nil
73
-
74
- Sure thing!
75
-
76
- ```ruby
77
- require 'naught'
78
-
79
- NullObject = Naught.build
80
-
81
- null = NullObject.new
82
- null.foo # => nil
83
- null.bar # => nil
84
- ```
85
-
86
- #### That was… weird. What's with this "build" business?
87
-
88
- Naught is a *toolkit* for building null object classes. It is not a
89
- one-size-fits-all solution.
90
-
91
- What else can I make for you?
92
-
93
- #### How about a "black hole" null object that supports infinite chaining of methods?
94
-
95
- OK.
96
-
97
- ```ruby
98
- require 'naught'
99
-
100
- BlackHole = Naught.build do |config|
101
- config.black_hole
102
- end
103
-
104
- null = BlackHole.new
105
- null.foo # => <null>
106
- null.foo.bar.baz # => <null>
107
- null << "hello" << "world" # => <null>
108
- ```
109
-
110
- #### What's that "config" thing?
111
-
112
- That's what you use to customize the generated class to your
113
- liking. Internally, Naught uses the [Builder
114
- Pattern](http://en.wikipedia.org/wiki/Builder_pattern) to make this work..
115
-
116
- #### Whatever. What if I want a null object that has conversions to Integer, String, etc. using sensible conversions to "zero values"?
117
-
118
- We can do that.
119
-
120
- ```ruby
121
- require 'naught'
122
-
123
- NullObject = Naught.build do |config|
124
- config.define_explicit_conversions
125
- end
126
-
127
- null = NullObject.new
128
-
129
- null.to_s # => ""
130
- null.to_i # => 0
131
- null.to_f # => 0.0
132
- null.to_a # => []
133
- null.to_h # => {}
134
- null.to_c # => (0+0i)
135
- null.to_r # => (0/1)
136
- ```
137
-
138
- #### Ah, but what about implicit conversions such as `#to_str`? Like what if I want a null object that implicitly splats the same way as an empty array?
139
-
140
- Gotcha covered.
141
-
142
- ```ruby
143
- require 'naught'
144
-
145
- NullObject = Naught.build do |config|
146
- config.define_implicit_conversions
147
- end
148
-
149
- null = NullObject.new
150
-
151
- null.to_str # => ""
152
- null.to_ary # => []
153
-
154
- a, b, c = []
155
- a # => nil
156
- b # => nil
157
- c # => nil
158
- x, y, z = null
159
- x # => nil
160
- y # => nil
161
- z # => nil
162
- ```
163
-
164
- #### How about a null object that only stubs out the methods from a specific class?
165
-
166
- That's what `mimic` is for.
167
-
168
- ```ruby
169
- require 'naught'
170
-
171
- NullIO = Naught.build do |config|
172
- config.mimic IO
173
- end
174
-
175
- null_io = NullIO.new
176
-
177
- null_io << "foo" # => nil
178
- null_io.readline # => nil
179
- null_io.foobar # =>
180
- # ~> -:11:in `<main>': undefined method `foobar' for
181
- # <null:IO>:NullIO (NoMethodError)
182
- ```
183
-
184
- There is also `impersonate` which takes `mimic` one step further. The
185
- generated null class will be derived from the impersonated class. This
186
- is handy when refitting legacy code that contains type checks.
187
-
188
- ```ruby
189
- require 'naught'
190
-
191
- NullIO = Naught.build do |config|
192
- config.impersonate IO
193
- end
194
-
195
- null_io = NullIO.new
196
- IO === null_io # => true
197
-
198
- case null_io
199
- when IO
200
- puts "Yep, checks out!"
201
- null_io << "some output"
202
- else
203
- raise "Hey, I expected an IO!"
204
- end
205
- # >> Yep, checks out!
206
- ```
207
-
208
- #### What about predicate methods? You know, the ones that end with question marks? Shouldn't they return `false` instead of `nil`?
209
-
210
- Sure, if you'd like.
211
-
212
- ```ruby
213
- require 'naught'
214
-
215
- NullObject = Naught.build do |config|
216
- config.predicates_return false
217
- end
218
-
219
- null = NullObject.new
220
- null.foo # => nil
221
- null.bar? # => false
222
- null.nil? # => false
223
- ```
224
-
225
- #### Alright smartypants. What if I want to add my own methods?
226
-
227
- Not a problem, just define them in the `.build` block.
228
-
229
- ```ruby
230
- require 'naught'
231
-
232
- NullObject = Naught.build do |config|
233
- config.define_explicit_conversions
234
- config.predicates_return false
235
- def to_path
236
- "/dev/null"
237
- end
238
-
239
- # You can override methods generated by Naught
240
- def to_s
241
- "NOTHING TO SEE HERE MOVE ALONG"
242
- end
243
-
244
- def nil?
245
- true
246
- end
247
- end
248
-
249
- null = NullObject.new
250
- null.to_path # => "/dev/null"
251
- null.to_s # => "NOTHING TO SEE HERE MOVE ALONG"
252
- null.nil? # => true
253
- ```
254
-
255
- #### Got anything else up your sleeve?
256
-
257
- Well, we can make the null class a singleton, since null objects
258
- generally have no state.
259
-
260
- ```ruby
261
- require 'naught'
262
-
263
- NullObject = Naught.build do |config|
264
- config.singleton
265
- end
266
-
267
- null = NullObject.instance
268
-
269
- null.__id__ # => 17844080
270
- NullObject.instance.__id__ # => 17844080
271
- NullObject.new # =>
272
- # ~> -:11:in `<main>': private method `new' called for
273
- # NullObject:Class (NoMethodError)
274
- ```
275
-
276
- Speaking of null objects with state, we can also enable tracing. This is
277
- handy for playing "where'd that null come from?!" Try doing *that* with
278
- `nil`!
279
-
280
- ```ruby
281
- require 'naught'
282
-
283
- NullObject = Naught.build do |config|
284
- config.traceable
285
- end
286
-
287
- null = NullObject.new # line 7
288
-
289
- null.__file__ # => "example.rb"
290
- null.__line__ # => 7
291
- ```
292
-
293
- We can even conditionally enable either singleton mode (for production)
294
- or tracing (for development). Here's an example of using the `$DEBUG`
295
- global variable (set with the `-d` option to ruby) to choose which one.
296
-
297
- ```ruby
298
- require 'naught'
299
-
300
- NullObject = Naught.build do |config|
301
- if $DEBUG
302
- config.traceable
303
- else
304
- config.singleton
305
- end
306
- end
307
- ```
308
-
309
- The only caveat is that when swapping between singleton and
310
- non-singleton implementations, you should be careful to always
311
- instantiate your null objects with `NullObject.get`, not `.new` or
312
- `.instance`. `.get` will work whether the class is implemented as a
313
- singleton or not.
314
-
315
- ```ruby
316
- NullObject.get # => <null>
317
- ```
318
-
319
- #### And if I want to know legacy code better?
320
-
321
- Naught can make a null object behave as a pebble object.
322
-
323
- ```ruby
324
- require 'naught'
325
-
326
- NullObject = Naught.build do |config|
327
- if $DEBUG
328
- config.pebble
329
- else
330
- config.black_hole
331
- end
332
- end
333
- ```
334
-
335
- Now you can pass the pebble object to your code and see which messages are sent to the pebble.
336
-
337
- ```ruby
338
- null = NullObject.new
339
-
340
- class MyConsumer < Struct.new(:producer)
341
- def consume
342
- producer.produce
343
- end
344
- end
345
-
346
- MyConsumer.new(null).consume
347
- # >> produce() from consume
348
- # => <null>
349
- ```
350
-
351
- #### Are you done yet?
352
-
353
- Just one more thing. For maximum convenience, Naught-generated null
354
- classes also come with a full suite of conversion functions which can be
355
- included into your classes.
356
-
357
- ```ruby
358
- require 'naught'
359
-
360
- NullObject = Naught.build
361
-
362
- include NullObject::Conversions
363
-
364
- # Convert nil to null objects. Everything else passes through.
365
- Maybe(42) # => 42
366
- Maybe(nil) # => <null>
367
- Maybe(NullObject.get) # => <null>
368
- Maybe{ 42 } # => 42
369
-
370
- # Insist on a non-null (or nil) value
371
- Just(42) # => 42
372
- Just(nil) rescue $! # => #<ArgumentError: Null value: nil>
373
- Just(NullObject.get) rescue $! # => #<ArgumentError: Null value: <null>>
374
-
375
- # nils and nulls become nulls. Everything else is rejected.
376
- Null() # => <null>
377
- Null(42) rescue $! # => #<ArgumentError: 42 is not null!>
378
- Null(nil) # => <null>
379
- Null(NullObject.get) # => <null>
380
-
381
- # Convert nulls back to nils. Everything else passes through. Useful
382
- # for preventing null objects from "leaking" into public API return
383
- # values.
384
- Actual(42) # => 42
385
- Actual(nil) # => nil
386
- Actual(NullObject.get) # => nil
387
- Actual { 42 } # => 42
388
- ```
389
-
390
- Installation
391
- --------------
392
-
393
- ``` {.example}
394
- gem install naught
395
- ```
396
-
397
- Requirements
398
- --------------
399
-
400
- - Ruby 1.9
401
-
402
- Contributing
403
- --------------
404
-
405
- - Fork, branch, submit PR, blah blah blah. Don't forget tests.
406
-
407
- Who's responsible
408
- -------------------
409
-
410
- Naught is by [Avdi Grimm](http://devblog.avdi.org/).
411
-
412
- Prior Art
413
- ---------
414
-
415
- This isn't the first Ruby Null Object library. Others to check out include:
416
-
417
- - [NullAndVoid](https://github.com/jfelchner/null_and_void)
418
- - [BlankSlate](https://github.com/saturnflyer/blank_slate)
419
-
420
-
421
- Further reading
422
- -----------------
423
-
424
- - [Null Object: Something for
425
- Nothing](http://www.two-sdg.demon.co.uk/curbralan/papers/europlop/NullObject.pdf)
426
- (PDF) by Kevlin Henney
427
- - [The Null Object
428
- Pattern](http://www.cs.oberlin.edu/~jwalker/refs/woolf.ps) (PS) by
429
- Bobby Woolf
430
- - [NullObject](http://www.c2.com/cgi/wiki?NullObject) on WikiWiki
431
- - [Null Object
432
- pattern](http://en.wikipedia.org/wiki/Null_Object_pattern) on
433
- Wikipedia
434
- - [Null Objects and
435
- Falsiness](http://devblog.avdi.org/2011/05/30/null-objects-and-falsiness/),
436
- by Avdi Grimm
data/Rakefile DELETED
@@ -1,15 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- begin
7
- require 'rubocop/rake_task'
8
- Rubocop::RakeTask.new
9
- rescue LoadError
10
- task :rubocop do
11
- $stderr.puts 'Rubocop is disabled'
12
- end
13
- end
14
-
15
- task :default => [:spec, :rubocop]
data/naught.gemspec DELETED
@@ -1,22 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'naught/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'naught'
8
- spec.version = Naught::VERSION
9
- spec.authors = ['Avdi Grimm']
10
- spec.email = ['avdi@avdi.org']
11
- spec.description = %q{Naught is a toolkit for building Null Objects}
12
- spec.summary = spec.description
13
- spec.homepage = 'https://github.com/avdi/naught'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
- spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
- spec.require_paths = ['lib']
20
-
21
- spec.add_development_dependency 'bundler', '~> 1.3'
22
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'null object with a custom base class' do
4
-
5
- subject(:null) { custom_base_null_class.new }
6
-
7
- let(:custom_base_null_class) do
8
- Naught.build do |b|
9
- b.base_class = Object
10
- end
11
- end
12
-
13
- it 'respond to base class methods' do
14
- expect(null.methods).to be_an Array
15
- end
16
-
17
- it 'respond to unknown methods' do
18
- expect(null.foo).to be_nil
19
- end
20
-
21
- it 'exposes the default base class choice, for the curious' do
22
- default_base_class = :not_set
23
- Naught.build do |b|
24
- default_base_class = b.base_class
25
- end
26
- expect(default_base_class).to eq(Naught::BasicObject)
27
- end
28
-
29
- describe 'singleton null object' do
30
- subject(:null_instance) { custom_base_singleton_null_class.instance }
31
-
32
- let(:custom_base_singleton_null_class) do
33
- Naught.build do |b|
34
- b.singleton
35
- b.base_class = Object
36
- end
37
- end
38
-
39
- it 'can be cloned' do
40
- expect(null_instance.clone).to be(null_instance)
41
- end
42
-
43
- it 'can be duplicated' do
44
- expect(null_instance.dup).to be(null_instance)
45
- end
46
- end
47
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'basic null object' do
4
- let(:null_class) { Naught.build }
5
- subject(:null) { null_class.new }
6
-
7
- it 'responds to arbitrary messages and returns nil' do
8
- expect(null.info).to be_nil
9
- expect(null.foobaz).to be_nil
10
- expect(null.to_s).to be_nil
11
- end
12
-
13
- it 'accepts any arguments for any messages' do
14
- null.foobaz(1, 2, 3)
15
- end
16
-
17
- it 'reports that it responds to any message' do
18
- expect(null).to respond_to(:info)
19
- expect(null).to respond_to(:foobaz)
20
- expect(null).to respond_to(:to_s)
21
- end
22
-
23
- it 'can be inspected' do
24
- expect(null.inspect).to eq('<null>')
25
- end
26
-
27
- it 'knows its own class' do
28
- expect(null.class).to eq(null_class)
29
- end
30
-
31
- it 'aliases .new to .get' do
32
- expect(null_class.get.class).to be(null_class)
33
- end
34
-
35
- end