naught 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/.rubocop.yml +74 -0
  4. data/.travis.yml +20 -2
  5. data/Changelog.md +8 -2
  6. data/Gemfile +24 -2
  7. data/README.markdown +30 -7
  8. data/Rakefile +11 -2
  9. data/lib/naught.rb +1 -1
  10. data/lib/naught/basic_object.rb +17 -0
  11. data/lib/naught/conversions.rb +55 -0
  12. data/lib/naught/null_class_builder.rb +33 -21
  13. data/lib/naught/null_class_builder/command.rb +3 -3
  14. data/lib/naught/null_class_builder/commands/define_explicit_conversions.rb +3 -7
  15. data/lib/naught/null_class_builder/commands/define_implicit_conversions.rb +7 -2
  16. data/lib/naught/null_class_builder/commands/impersonate.rb +2 -3
  17. data/lib/naught/null_class_builder/commands/mimic.rb +4 -7
  18. data/lib/naught/null_class_builder/commands/pebble.rb +3 -5
  19. data/lib/naught/null_class_builder/commands/predicates_return.rb +1 -2
  20. data/lib/naught/null_class_builder/commands/singleton.rb +1 -1
  21. data/lib/naught/null_class_builder/commands/traceable.rb +3 -2
  22. data/lib/naught/version.rb +1 -1
  23. data/naught.gemspec +11 -16
  24. data/spec/base_object_spec.rb +2 -2
  25. data/spec/basic_null_object_spec.rb +3 -3
  26. data/spec/blackhole_spec.rb +4 -4
  27. data/spec/explicit_conversions_spec.rb +23 -0
  28. data/spec/functions/actual_spec.rb +4 -4
  29. data/spec/functions/just_spec.rb +7 -7
  30. data/spec/functions/maybe_spec.rb +7 -7
  31. data/spec/functions/null_spec.rb +6 -6
  32. data/spec/implicit_conversions_spec.rb +5 -5
  33. data/spec/mimic_spec.rb +30 -35
  34. data/spec/naught/null_object_builder/command_spec.rb +1 -1
  35. data/spec/naught/null_object_builder_spec.rb +5 -5
  36. data/spec/naught_spec.rb +29 -23
  37. data/spec/pebble_spec.rb +13 -11
  38. data/spec/predicate_spec.rb +18 -14
  39. data/spec/singleton_null_object_spec.rb +4 -4
  40. data/spec/spec_helper.rb +4 -4
  41. data/spec/support/convertable_null.rb +2 -2
  42. data/spec/support/jruby.rb +3 -0
  43. data/spec/support/rubinius.rb +3 -0
  44. data/spec/support/ruby_18.rb +3 -0
  45. metadata +21 -82
  46. data/lib/naught/null_class_builder/conversions_module.rb +0 -57
  47. data/spec/conversions_spec.rb +0 -20
@@ -4,7 +4,7 @@ module Naught
4
4
  describe NullClassBuilder::Command do
5
5
  it 'is abstract' do
6
6
  command = NullClassBuilder::Command.new(nil)
7
- expect{command.call}.to raise_error(NotImplementedError)
7
+ expect { command.call }.to raise_error(NotImplementedError)
8
8
  end
9
9
  end
10
10
  end
@@ -16,16 +16,16 @@ module Naught
16
16
 
17
17
  it 'translates method calls into command invocations including arguments' do
18
18
  test_command = double
19
- NullClassBuilder::Commands::TestCommand.should_receive(:new).
20
- with(builder, "foo", 42).
19
+ expect(NullClassBuilder::Commands::TestCommand).to receive(:new).
20
+ with(builder, 'foo', 42).
21
21
  and_return(test_command)
22
- test_command.should_receive(:call).and_return("COMMAND RESULT")
23
- expect(builder.test_command("foo", 42)).to eq("COMMAND RESULT")
22
+ expect(test_command).to receive(:call).and_return('COMMAND RESULT')
23
+ expect(builder.test_command('foo', 42)).to eq('COMMAND RESULT')
24
24
  end
25
25
 
26
26
  it 'handles missing non-command missing methods normally' do
27
27
  expect(builder).not_to respond_to(:nonexistant_method)
28
- expect{builder.nonexistent_method}.to raise_error(NoMethodError)
28
+ expect { builder.nonexistent_method }.to raise_error(NoMethodError)
29
29
  end
30
30
  end
31
31
  end
@@ -2,19 +2,24 @@ require 'spec_helper'
2
2
 
3
3
  describe 'null object impersonating another type' do
4
4
  class Point
5
- def x; 23; end
6
- def y; 42; end
5
+ def x
6
+ 23
7
+ end
8
+
9
+ def y
10
+ 42
11
+ end
7
12
  end
8
13
 
9
14
  subject(:null) { impersonation_class.new }
10
- let(:impersonation_class) {
15
+ let(:impersonation_class) do
11
16
  Naught.build do |b|
12
17
  b.impersonate Point
13
18
  end
14
- }
19
+ end
15
20
 
16
21
  it 'matches the impersonated type' do
17
- expect(Point).to be === null
22
+ expect(null).to be_a Point
18
23
  end
19
24
 
20
25
  it 'responds to methods from the impersonated type' do
@@ -23,24 +28,24 @@ describe 'null object impersonating another type' do
23
28
  end
24
29
 
25
30
  it 'does not respond to unknown methods' do
26
- expect{null.foo}.to raise_error(NoMethodError)
31
+ expect { null.foo }.to raise_error(NoMethodError)
27
32
  end
28
33
  end
29
34
 
30
35
  describe 'traceable null object' do
31
- subject(:trace_null) {
36
+ subject(:trace_null) do
32
37
  null_object_and_line.first
33
- }
34
- let(:null_object_and_line) {
35
- obj = trace_null_class.new; line = __LINE__;
38
+ end
39
+ let(:null_object_and_line) do
40
+ obj, line = trace_null_class.new, __LINE__
36
41
  [obj, line]
37
- }
42
+ end
38
43
  let(:instantiation_line) { null_object_and_line.last }
39
- let(:trace_null_class) {
44
+ let(:trace_null_class) do
40
45
  Naught.build do |b|
41
46
  b.traceable
42
47
  end
43
- }
48
+ end
44
49
 
45
50
  it 'remembers the file it was instantiated from' do
46
51
  expect(trace_null.__file__).to eq(__FILE__)
@@ -51,42 +56,43 @@ describe 'traceable null object' do
51
56
  end
52
57
 
53
58
  def make_null
54
- trace_null_class.get(caller: caller(1))
59
+ trace_null_class.get(:caller => caller(1))
55
60
  end
56
61
 
57
62
  it 'can accept custom backtrace info' do
58
- obj = make_null; line = __LINE__
63
+ obj, line = make_null, __LINE__
59
64
  expect(obj.__line__).to eq(line)
60
65
  end
61
66
  end
62
67
 
63
68
  describe 'customized null object' do
64
69
  subject(:custom_null) { custom_null_class.new }
65
- let(:custom_null_class) {
70
+ let(:custom_null_class) do
66
71
  Naught.build do |b|
67
72
  b.define_explicit_conversions
68
73
  def to_path
69
- "/dev/null"
74
+ '/dev/null'
70
75
  end
76
+
71
77
  def to_s
72
- "NOTHING TO SEE HERE"
78
+ 'NOTHING TO SEE HERE'
73
79
  end
74
80
  end
75
- }
81
+ end
76
82
 
77
83
  it 'responds to custom-defined methods' do
78
- expect(custom_null.to_path).to eq("/dev/null")
84
+ expect(custom_null.to_path).to eq('/dev/null')
79
85
  end
80
86
 
81
87
  it 'allows generated methods to be overridden' do
82
- expect(custom_null.to_s).to eq("NOTHING TO SEE HERE")
88
+ expect(custom_null.to_s).to eq('NOTHING TO SEE HERE')
83
89
  end
84
90
  end
85
91
  TestNull = Naught.build
86
92
 
87
93
  describe 'a named null object class' do
88
- it 'has named ancestor modules' do
89
- expect(TestNull.ancestors[0..2].map(&:name)).to eq([
94
+ it 'has named ancestor modules', :pending => rubinius? do
95
+ expect(TestNull.ancestors[0..2].collect(&:name)).to eq([
90
96
  'TestNull',
91
97
  'TestNull::Customizations',
92
98
  'TestNull::GeneratedMethods'
@@ -17,12 +17,12 @@ describe 'pebble null object' do
17
17
  end
18
18
 
19
19
  subject(:null) { null_class.new }
20
- let(:null_class) {
20
+ let(:null_class) do
21
21
  output = test_output # getting local binding
22
22
  Naught.build do |b|
23
23
  b.pebble output
24
24
  end
25
- }
25
+ end
26
26
 
27
27
  let(:test_output) { StringIO.new }
28
28
 
@@ -33,7 +33,7 @@ describe 'pebble null object' do
33
33
 
34
34
  it 'prints the arguments received' do
35
35
  expect(test_output).to receive(:puts).with(/^info\(\'foo\', 5, \:sym\)/)
36
- null.info("foo", 5, :sym)
36
+ null.info('foo', 5, :sym)
37
37
  end
38
38
 
39
39
  it 'prints the name of the caller' do
@@ -45,30 +45,32 @@ describe 'pebble null object' do
45
45
  expect(null.info).to be(null)
46
46
  end
47
47
 
48
- context "when is called from a block" do
49
- it "prints the indication of a block" do
48
+ context 'when is called from a block' do
49
+ it 'prints the indication of a block',
50
+ :pending => jruby? || rubinius? || ruby_18? do
50
51
  expect(test_output).to receive(:puts).twice.
51
52
  with(/from block/)
52
53
  Caller.new.call_method_inside_block(null)
53
54
  end
54
55
 
55
- it "prints the name of the method that has the block" do
56
+ it 'prints the name of the method that has the block' do
56
57
  expect(test_output).to receive(:puts).twice.
57
- with(/in call_method_inside_block$/)
58
+ with(/call_method_inside_block$/)
58
59
  Caller.new.call_method_inside_block(null)
59
60
  end
60
61
  end
61
62
 
62
- context "when is called from many levels blocks" do
63
- it "prints the indication of blocks and its levels" do
63
+ context 'when is called from many levels blocks' do
64
+ it 'prints the indication of blocks and its levels',
65
+ :pending => jruby? || rubinius? || ruby_18? do
64
66
  expect(test_output).to receive(:puts).exactly(4).times.
65
67
  with(/from block \(2 levels\)/)
66
68
  Caller.new.call_method_inside_nested_block(null)
67
69
  end
68
70
 
69
- it "prints the name of the method that has the block" do
71
+ it 'prints the name of the method that has the block' do
70
72
  expect(test_output).to receive(:puts).exactly(4).times.
71
- with(/in call_method_inside_nested_block$/)
73
+ with(/call_method_inside_nested_block$/)
72
74
  Caller.new.call_method_inside_nested_block(null)
73
75
  end
74
76
  end
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe 'a null object with predicates_return(false)' do
4
4
  subject(:null) { null_class.new }
5
- let(:null_class) {
5
+ let(:null_class) do
6
6
  Naught.build do |config|
7
7
  config.predicates_return false
8
8
  end
9
- }
9
+ end
10
10
 
11
11
  it 'responds to predicate-style methods with false' do
12
12
  expect(null.too_much_coffee?).to eq(false)
@@ -17,52 +17,56 @@ describe 'a null object with predicates_return(false)' do
17
17
  end
18
18
 
19
19
  describe '(black hole)' do
20
- let(:null_class) {
20
+ let(:null_class) do
21
21
  Naught.build do |config|
22
22
  config.black_hole
23
23
  config.predicates_return false
24
24
  end
25
- }
25
+ end
26
26
 
27
27
  it 'responds to predicate-style methods with false' do
28
28
  expect(null.too_much_coffee?).to eq(false)
29
29
  end
30
30
 
31
31
  it 'responds to other methods with self' do
32
- expect(null.foobar).to be(null)
32
+ expect(null.foobar).to be(null)
33
33
  end
34
34
  end
35
35
 
36
36
  describe '(black hole, reverse order config)' do
37
- let(:null_class) {
37
+ let(:null_class) do
38
38
  Naught.build do |config|
39
39
  config.predicates_return false
40
40
  config.black_hole
41
41
  end
42
- }
42
+ end
43
43
 
44
44
  it 'responds to predicate-style methods with false' do
45
45
  expect(null.too_much_coffee?).to eq(false)
46
46
  end
47
47
 
48
48
  it 'responds to other methods with self' do
49
- expect(null.foobar).to be(null)
49
+ expect(null.foobar).to be(null)
50
50
  end
51
51
  end
52
52
 
53
-
54
53
  class Coffee
55
- def black?; true; end
56
- def origin; "Ethiopia"; end
54
+ def black?
55
+ true
56
+ end
57
+
58
+ def origin
59
+ 'Ethiopia'
60
+ end
57
61
  end
58
62
 
59
63
  describe '(mimic)' do
60
- let(:null_class) {
64
+ let(:null_class) do
61
65
  Naught.build do |config|
62
66
  config.mimic Coffee
63
67
  config.predicates_return false
64
68
  end
65
- }
69
+ end
66
70
 
67
71
  it 'responds to predicate-style methods with false' do
68
72
  expect(null.black?).to eq(false)
@@ -74,7 +78,7 @@ describe 'a null object with predicates_return(false)' do
74
78
 
75
79
  it 'does not respond to undefined methods' do
76
80
  expect(null).not_to respond_to(:leaf_variety)
77
- expect{null.leaf_variety}.to raise_error(NoMethodError)
81
+ expect { null.leaf_variety }.to raise_error(NoMethodError)
78
82
  end
79
83
  end
80
84
  end
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'singleton null object' do
4
- subject(:null_class) {
4
+ subject(:null_class) do
5
5
  Naught.build do |b|
6
6
  b.singleton
7
7
  end
8
- }
8
+ end
9
9
 
10
10
  it 'does not respond to .new' do
11
- expect{ null_class.new }.to raise_error
11
+ expect { null_class.new }.to raise_error
12
12
  end
13
13
 
14
14
  it 'has only one instance' do
@@ -30,6 +30,6 @@ describe 'singleton null object' do
30
30
  expect(null_class.get).to be null_class.instance
31
31
  end
32
32
  it 'permits arbitrary arguments to be passed to .get' do
33
- null_class.get(42, foo: "bar")
33
+ null_class.get(42, :foo => 'bar')
34
34
  end
35
35
  end
@@ -1,7 +1,7 @@
1
- GEM_ROOT = File.expand_path("../../", __FILE__)
2
- $:.unshift File.join(GEM_ROOT, "lib")
1
+ GEM_ROOT = File.expand_path('../../', __FILE__)
2
+ $LOAD_PATH.unshift File.join(GEM_ROOT, 'lib')
3
3
 
4
- if ENV["TRAVIS"]
4
+ if ENV['TRAVIS']
5
5
  require 'coveralls'
6
6
  Coveralls.wear!
7
7
  else
@@ -10,4 +10,4 @@ else
10
10
  end
11
11
 
12
12
  require 'naught'
13
- Dir[File.join(GEM_ROOT, "spec", "support", "**/*.rb")].each { |f| require f }
13
+ Dir[File.join(GEM_ROOT, 'spec', 'support', '**/*.rb')].each { |f| require f }
@@ -1,4 +1,4 @@
1
1
  ConvertableNull = Naught.build do |b|
2
- b.null_equivalents << ""
2
+ b.null_equivalents << ''
3
3
  b.traceable
4
- end
4
+ end
@@ -0,0 +1,3 @@
1
+ def jruby?
2
+ RUBY_PLATFORM == 'java'
3
+ end
@@ -0,0 +1,3 @@
1
+ def rubinius?
2
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
3
+ end
@@ -0,0 +1,3 @@
1
+ def ruby_18?
2
+ RUBY_VERSION.to_f == 1.8
3
+ end
metadata CHANGED
@@ -1,99 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: naught
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avdi Grimm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-08 00:00:00.000000000 Z
11
+ date: 2014-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: '2.14'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: '2.14'
55
- - !ruby/object:Gem::Dependency
56
- name: guard
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard-rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: guard-bundler
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
27
  description: Naught is a toolkit for building Null Objects
98
28
  email:
99
29
  - avdi@avdi.org
@@ -101,8 +31,10 @@ executables: []
101
31
  extensions: []
102
32
  extra_rdoc_files: []
103
33
  files:
104
- - .gitignore
105
- - .travis.yml
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - ".travis.yml"
106
38
  - Changelog.md
107
39
  - Gemfile
108
40
  - Guardfile
@@ -110,6 +42,8 @@ files:
110
42
  - README.markdown
111
43
  - Rakefile
112
44
  - lib/naught.rb
45
+ - lib/naught/basic_object.rb
46
+ - lib/naught/conversions.rb
113
47
  - lib/naught/null_class_builder.rb
114
48
  - lib/naught/null_class_builder/command.rb
115
49
  - lib/naught/null_class_builder/commands.rb
@@ -121,13 +55,12 @@ files:
121
55
  - lib/naught/null_class_builder/commands/predicates_return.rb
122
56
  - lib/naught/null_class_builder/commands/singleton.rb
123
57
  - lib/naught/null_class_builder/commands/traceable.rb
124
- - lib/naught/null_class_builder/conversions_module.rb
125
58
  - lib/naught/version.rb
126
59
  - naught.gemspec
127
60
  - spec/base_object_spec.rb
128
61
  - spec/basic_null_object_spec.rb
129
62
  - spec/blackhole_spec.rb
130
- - spec/conversions_spec.rb
63
+ - spec/explicit_conversions_spec.rb
131
64
  - spec/functions/actual_spec.rb
132
65
  - spec/functions/just_spec.rb
133
66
  - spec/functions/maybe_spec.rb
@@ -142,6 +75,9 @@ files:
142
75
  - spec/singleton_null_object_spec.rb
143
76
  - spec/spec_helper.rb
144
77
  - spec/support/convertable_null.rb
78
+ - spec/support/jruby.rb
79
+ - spec/support/rubinius.rb
80
+ - spec/support/ruby_18.rb
145
81
  homepage: https://github.com/avdi/naught
146
82
  licenses:
147
83
  - MIT
@@ -152,17 +88,17 @@ require_paths:
152
88
  - lib
153
89
  required_ruby_version: !ruby/object:Gem::Requirement
154
90
  requirements:
155
- - - '>='
91
+ - - ">="
156
92
  - !ruby/object:Gem::Version
157
93
  version: '0'
158
94
  required_rubygems_version: !ruby/object:Gem::Requirement
159
95
  requirements:
160
- - - '>='
96
+ - - ">="
161
97
  - !ruby/object:Gem::Version
162
98
  version: '0'
163
99
  requirements: []
164
100
  rubyforge_project:
165
- rubygems_version: 2.0.3
101
+ rubygems_version: 2.2.1
166
102
  signing_key:
167
103
  specification_version: 4
168
104
  summary: Naught is a toolkit for building Null Objects
@@ -170,7 +106,7 @@ test_files:
170
106
  - spec/base_object_spec.rb
171
107
  - spec/basic_null_object_spec.rb
172
108
  - spec/blackhole_spec.rb
173
- - spec/conversions_spec.rb
109
+ - spec/explicit_conversions_spec.rb
174
110
  - spec/functions/actual_spec.rb
175
111
  - spec/functions/just_spec.rb
176
112
  - spec/functions/maybe_spec.rb
@@ -185,3 +121,6 @@ test_files:
185
121
  - spec/singleton_null_object_spec.rb
186
122
  - spec/spec_helper.rb
187
123
  - spec/support/convertable_null.rb
124
+ - spec/support/jruby.rb
125
+ - spec/support/rubinius.rb
126
+ - spec/support/ruby_18.rb