compo 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'compo'
3
3
 
4
- describe Compo::Composites::Parentless do
4
+ RSpec.describe Compo::Composites::Parentless do
5
5
  let(:child) { double(:child) }
6
6
 
7
7
  describe '#add' do
@@ -12,17 +12,20 @@ describe Compo::Composites::Parentless do
12
12
  end
13
13
 
14
14
  it 'calls #update_parent on the child with a Parentless' do
15
- expect(child).to receive(:update_parent).once do |parent, _|
16
- expect(parent).to be_a(Compo::Composites::Parentless)
17
- end
18
15
  subject.add(:id, child)
16
+
17
+ expect(child).to have_received(:update_parent).once.with(
18
+ a_kind_of(Compo::Composites::Parentless),
19
+ anything
20
+ )
19
21
  end
20
22
 
21
23
  it 'calls #update_parent on the child with a nil-returning ID proc' do
22
- expect(child).to receive(:update_parent).once do |_, idp|
23
- expect(idp.call).to be_nil
24
- end
25
24
  subject.add(:id, child)
25
+ expect(child).to have_received(:update_parent).once.with(
26
+ anything,
27
+ an_object_satisfying { |idp| idp.call.nil? }
28
+ )
26
29
  end
27
30
  end
28
31
 
@@ -40,13 +43,20 @@ describe Compo::Composites::Parentless do
40
43
  specify { expect(subject.url).to eq('') }
41
44
  end
42
45
 
43
- describe '#child_url' do
44
- specify { expect(subject.child_url(:id)).to eq('') }
45
- end
46
-
47
46
  describe '#parent' do
48
47
  it 'returns the exact same Parentless object' do
49
48
  expect(subject.parent).to be(subject)
50
49
  end
51
50
  end
51
+
52
+ describe '#on_node' do
53
+ it 'ignores the block given' do
54
+ expect { |block| subject.on_node(&block) }.to_not yield_control
55
+ end
56
+
57
+ it 'returns nil' do
58
+ expect(subject.on_node { |subject| subject }).to be_nil
59
+ expect(subject.on_node { 3 }).to be_nil
60
+ end
61
+ end
52
62
  end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+ require 'compo'
3
+
4
+ RSpec.describe Compo::Finders::Root do
5
+ subject { Compo::Finders::Root }
6
+
7
+ it { should < Enumerable }
8
+
9
+ describe '.find' do
10
+ context 'when given a root' do
11
+ it 'returns the root' do
12
+ l = Compo::Branches::Leaf.new
13
+
14
+ expect { |b| subject.find(l, &b) }.to yield_with_args(l)
15
+ end
16
+ end
17
+
18
+ context 'when given a leaf' do
19
+ it 'returns its root' do
20
+ a = Compo::Branches::Hash.new
21
+ b = Compo::Branches::Hash.new
22
+ l = Compo::Branches::Leaf.new
23
+
24
+ l.move_to(b, :l)
25
+ b.move_to(a, :b)
26
+
27
+ expect { |block| subject.find(l, &block) }.to yield_with_args(a)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '.each' do
33
+ subject { Compo::Finders::Root.new(leaf) }
34
+
35
+ context 'when given a root' do
36
+ let(:leaf) { Compo::Branches::Leaf.new }
37
+
38
+ it 'returns the root' do
39
+ expect { |block| subject.each(&block) }.to yield_with_args(leaf)
40
+ end
41
+ end
42
+
43
+ context 'when given a leaf' do
44
+ let(:root) { Compo::Branches::Hash.new }
45
+ let(:a) { Compo::Branches::Hash.new }
46
+ let(:b) { Compo::Branches::Hash.new }
47
+ let(:c) { Compo::Branches::Hash.new }
48
+ let(:leaf) do
49
+ l = Compo::Branches::Leaf.new
50
+
51
+ l.move_to(c, :l)
52
+ c.move_to(b, :c)
53
+ b.move_to(a, :b)
54
+ a.move_to(root, :a)
55
+
56
+ l
57
+ end
58
+
59
+ it 'returns each item in the path' do
60
+ expect { |b| subject.each(&b) }.to yield_successive_args(
61
+ leaf, c, b, a, root
62
+ )
63
+ end
64
+ end
65
+ end
66
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'simplecov'
2
2
 
3
3
  RSpec.configure do |config|
4
+ config.expose_dsl_globally = false
4
5
  config.expect_with :rspec do |c|
5
6
  c.syntax = :expect
6
7
  end
@@ -1,6 +1,6 @@
1
1
  require 'compo'
2
2
 
3
- shared_examples 'a URL finding' do
3
+ RSpec.shared_examples 'a URL finding' do
4
4
  let(:target) { Compo::Branches::Leaf.new }
5
5
 
6
6
  context 'when given a nil URL' do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'compo'
3
3
  require 'url_finder_shared_examples'
4
4
 
5
- describe Compo::Finders::Url do
5
+ RSpec.describe Compo::Finders::Url do
6
6
  subject { Compo::Finders::Url }
7
7
  describe '.find' do
8
8
  context 'when given a nil root' do
@@ -1,10 +1,14 @@
1
- shared_examples 'a URL referenceable object' do
1
+ RSpec.shared_examples 'a URL referenceable object' do
2
2
  let(:parent) { nil }
3
- let(:id) { double(:id) }
3
+ let(:id) { :id }
4
+ let(:parent_id) { :parent_id }
4
5
 
5
6
  before(:each) do
6
- allow(subject).to receive(:id).and_return(id)
7
- allow(subject).to receive(:parent).and_return(parent)
7
+ allow(subject).to receive_messages(
8
+ id: id,
9
+ parent: parent,
10
+ root?: false
11
+ )
8
12
  end
9
13
 
10
14
  describe '#url' do
@@ -15,26 +19,24 @@ shared_examples 'a URL referenceable object' do
15
19
  context 'when the UrlReferenceable has a parent' do
16
20
  let(:parent) { double(:parent) }
17
21
  before(:each) do
18
- allow(parent).to receive(:child_url).and_return(:child_url)
22
+ allow(parent).to receive_messages(
23
+ parent: Compo::Composites::Parentless.new,
24
+ root?: true
25
+ )
19
26
  end
20
27
 
21
28
  it 'calls #id' do
22
- expect(subject).to receive(:id)
23
29
  subject.url
30
+ expect(subject).to have_received(:id)
24
31
  end
25
32
 
26
33
  it 'calls #parent' do
27
- expect(subject).to receive(:parent)
28
34
  subject.url
35
+ expect(subject).to have_received(:parent)
29
36
  end
30
37
 
31
- it 'calls #child_url on the parent with the ID' do
32
- expect(parent).to receive(:child_url).with(id)
33
- subject.url
34
- end
35
-
36
- it 'returns the result of calling #child_url' do
37
- expect(subject.url).to eq(:child_url)
38
+ it 'returns /id' do
39
+ expect(subject.url).to eq('/id')
38
40
  end
39
41
  end
40
42
  end
@@ -7,6 +7,6 @@ class MockUrlReferenceable
7
7
  include Compo::Mixins::UrlReferenceable
8
8
  end
9
9
 
10
- describe MockUrlReferenceable do
10
+ RSpec.describe MockUrlReferenceable do
11
11
  it_behaves_like 'a URL referenceable object'
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Windsor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backports
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
- - !ruby/object:Gem::Dependency
42
- name: fuubar
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +56,16 @@ dependencies:
70
56
  name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - ">="
59
+ - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '0'
61
+ version: '3'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ">="
66
+ - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '0'
68
+ version: '3'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: simplecov
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -122,9 +108,10 @@ dependencies:
122
108
  - - ">="
123
109
  - !ruby/object:Gem::Version
124
110
  version: '0'
125
- description: "\n Compo provides mixins and classes that assist in implementing
126
- a variant of\n the Composite design pattern, in which each child has an ID that
127
- uniquely\n identifies it inside the parent's child set.\n "
111
+ description: |2
112
+ Compo provides mixins and classes that assist in implementing a variant of
113
+ the Composite design pattern, in which each child has an ID that uniquely
114
+ identifies it inside the parent's child set.
128
115
  email:
129
116
  - matt.windsor@ury.org.uk
130
117
  executables: []
@@ -133,6 +120,7 @@ extra_rdoc_files: []
133
120
  files:
134
121
  - ".gitignore"
135
122
  - ".rspec"
123
+ - ".travis.yml"
136
124
  - CHANGELOG
137
125
  - Gemfile
138
126
  - LICENSE.txt
@@ -153,6 +141,7 @@ files:
153
141
  - lib/compo/composites/leaf.rb
154
142
  - lib/compo/composites/parentless.rb
155
143
  - lib/compo/finders.rb
144
+ - lib/compo/finders/root.rb
156
145
  - lib/compo/finders/url.rb
157
146
  - lib/compo/mixins.rb
158
147
  - lib/compo/mixins/movable.rb
@@ -177,6 +166,7 @@ files:
177
166
  - spec/movable_spec.rb
178
167
  - spec/parent_tracker_spec.rb
179
168
  - spec/parentless_spec.rb
169
+ - spec/root_finder_spec.rb
180
170
  - spec/spec_helper.rb
181
171
  - spec/url_finder_shared_examples.rb
182
172
  - spec/url_finder_spec.rb
@@ -225,6 +215,7 @@ test_files:
225
215
  - spec/movable_spec.rb
226
216
  - spec/parent_tracker_spec.rb
227
217
  - spec/parentless_spec.rb
218
+ - spec/root_finder_spec.rb
228
219
  - spec/spec_helper.rb
229
220
  - spec/url_finder_shared_examples.rb
230
221
  - spec/url_finder_spec.rb