rambling-trie 2.3.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/LICENSE +1 -1
  4. data/README.md +45 -20
  5. data/lib/rambling/trie/comparable.rb +1 -2
  6. data/lib/rambling/trie/compressible.rb +2 -4
  7. data/lib/rambling/trie/compressor.rb +2 -12
  8. data/lib/rambling/trie/configuration/properties.rb +4 -11
  9. data/lib/rambling/trie/configuration/provider_collection.rb +10 -20
  10. data/lib/rambling/trie/container.rb +20 -32
  11. data/lib/rambling/trie/enumerable.rb +1 -2
  12. data/lib/rambling/trie/nodes/compressed.rb +1 -2
  13. data/lib/rambling/trie/nodes/missing.rb +1 -2
  14. data/lib/rambling/trie/nodes/node.rb +14 -27
  15. data/lib/rambling/trie/readers/plain_text.rb +1 -2
  16. data/lib/rambling/trie/readers/reader.rb +2 -4
  17. data/lib/rambling/trie/serializers/marshal.rb +10 -19
  18. data/lib/rambling/trie/serializers/yaml.rb +8 -15
  19. data/lib/rambling/trie/serializers/zip.rb +1 -1
  20. data/lib/rambling/trie/version.rb +1 -1
  21. data/lib/rambling/trie.rb +11 -16
  22. data/rambling-trie.gemspec +4 -4
  23. data/spec/integration/rambling/trie_spec.rb +36 -4
  24. data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +7 -7
  25. data/spec/lib/rambling/trie/container_spec.rb +4 -4
  26. data/spec/lib/rambling/trie/nodes/compressed_spec.rb +6 -0
  27. data/spec/lib/rambling/trie/nodes/raw_spec.rb +6 -4
  28. data/spec/lib/rambling/trie/serializers/file_spec.rb +1 -1
  29. data/spec/lib/rambling/trie/serializers/marshal_spec.rb +1 -1
  30. data/spec/lib/rambling/trie/serializers/yaml_spec.rb +1 -1
  31. data/spec/lib/rambling/trie/serializers/zip_spec.rb +4 -4
  32. data/spec/lib/rambling/trie_spec.rb +11 -11
  33. data/spec/spec_helper.rb +5 -5
  34. data/spec/support/shared_examples/a_container_word.rb +3 -3
  35. data/spec/support/shared_examples/a_serializable_trie.rb +1 -1
  36. data/spec/support/shared_examples/a_serializer.rb +2 -2
  37. data/spec/support/shared_examples/a_trie_node.rb +3 -2
  38. metadata +8 -8
@@ -6,10 +6,8 @@ module Rambling
6
6
  # Base class for all readers.
7
7
  class Reader
8
8
  # Yields each word read from given file.
9
- # @abstract Subclass and override {#each_word} to fit to a particular
10
- # file format.
11
- # @param [String] filepath the full path of the file to load the words
12
- # from.
9
+ # @abstract Subclass and override {#each_word} to fit to a particular file format.
10
+ # @param [String] filepath the full path of the file to load the words from.
13
11
  # @yield [String] Each line read from the file.
14
12
  # @return [self]
15
13
  def each_word filepath
@@ -6,36 +6,27 @@ module Rambling
6
6
  # Serializer for Ruby marshal format (+.marshal+) files.
7
7
  class Marshal < Serializer
8
8
  # Creates a new Marshal serializer.
9
- # @param [Serializer] serializer the serializer responsible to write to
10
- # and read from disk.
9
+ # @param [Serializer] serializer the serializer responsible to write to and read from disk.
11
10
  def initialize serializer = nil
12
- @serializer = serializer || Rambling::Trie::Serializers::File.new
13
11
  super()
12
+ @serializer = serializer || Rambling::Trie::Serializers::File.new
14
13
  end
15
14
 
16
- # Loads marshaled object from contents in filepath and deserializes it
17
- # into a {Nodes::Node Node}.
18
- # @param [String] filepath the full path of the file to load the
19
- # marshaled object from.
15
+ # Loads marshaled object from contents in filepath and deserializes it into a {Nodes::Node Node}.
16
+ # @param [String] filepath the full path of the file to load the marshaled object from.
20
17
  # @return [Nodes::Node] The deserialized {Nodes::Node Node}.
21
- # @see https://ruby-doc.org/core-2.7.0/Marshal.html#method-c-load
22
- # Marshal.load
23
- # @note Use of
24
- # {https://ruby-doc.org/core-2.7.0/Marshal.html#method-c-load
25
- # Marshal.load} is generally discouraged. Only use this with trusted
26
- # input.
18
+ # @see https://ruby-doc.org/core-2.7.0/Marshal.html#method-c-load Marshal.load
19
+ # @note Use of {https://ruby-doc.org/core-2.7.0/Marshal.html#method-c-load Marshal.load} is generally
20
+ # discouraged. Only use this with trusted input.
27
21
  def load filepath
28
22
  ::Marshal.load serializer.load filepath
29
23
  end
30
24
 
31
- # Serializes a {Nodes::Node Node} and dumps it as a marshaled object
32
- # into filepath.
25
+ # Serializes a {Nodes::Node Node} and dumps it as a marshaled object into filepath.
33
26
  # @param [Nodes::Node] node the node to serialize
34
- # @param [String] filepath the full path of the file to dump the
35
- # marshaled object into.
27
+ # @param [String] filepath the full path of the file to dump the marshaled object into.
36
28
  # @return [Numeric] number of bytes written to disk.
37
- # @see https://ruby-doc.org/core-2.7.0/Marshal.html#method-c-dump
38
- # Marshal.dump
29
+ # @see https://ruby-doc.org/core-2.7.0/Marshal.html#method-c-dump Marshal.dump
39
30
  def dump node, filepath
40
31
  serializer.dump ::Marshal.dump(node), filepath
41
32
  end
@@ -6,20 +6,16 @@ module Rambling
6
6
  # Serializer for Ruby yaml format (+.yaml+, or +.yml+) files.
7
7
  class Yaml < Serializer
8
8
  # Creates a new Yaml serializer.
9
- # @param [Serializer] serializer the serializer responsible to write to
10
- # and read from disk.
9
+ # @param [Serializer] serializer the serializer responsible to write to and read from disk.
11
10
  def initialize serializer = nil
12
- @serializer = serializer || Rambling::Trie::Serializers::File.new
13
11
  super()
12
+ @serializer = serializer || Rambling::Trie::Serializers::File.new
14
13
  end
15
14
 
16
- # Loads serialized object from YAML file in filepath and deserializes
17
- # it into a {Nodes::Node Node}.
18
- # @param [String] filepath the full path of the file to load the
19
- # serialized YAML object from.
15
+ # Loads serialized object from YAML file in filepath and deserializes it into a {Nodes::Node Node}.
16
+ # @param [String] filepath the full path of the file to load the serialized YAML object from.
20
17
  # @return [Nodes::Node] The deserialized {Nodes::Node Node}.
21
- # @see https://ruby-doc.org/stdlib-2.7.0/libdoc/psych/rdoc/Psych.html#method-c-safe_load
22
- # Psych.safe_load
18
+ # @see https://ruby-doc.org/stdlib-2.7.0/libdoc/psych/rdoc/Psych.html#method-c-safe_load Psych.safe_load
23
19
  def load filepath
24
20
  require 'yaml'
25
21
  ::YAML.safe_load(
@@ -33,14 +29,11 @@ module Rambling
33
29
  )
34
30
  end
35
31
 
36
- # Serializes a {Nodes::Node Node} and dumps it as a YAML object into
37
- # filepath.
32
+ # Serializes a {Nodes::Node Node} and dumps it as a YAML object into filepath.
38
33
  # @param [Nodes::Node] node the node to serialize
39
- # @param [String] filepath the full path of the file to dump the YAML
40
- # object into.
34
+ # @param [String] filepath the full path of the file to dump the YAML object into.
41
35
  # @return [Numeric] number of bytes written to disk.
42
- # @see https://ruby-doc.org/stdlib-2.7.0/libdoc/psych/rdoc/Psych.html#method-c-dump
43
- # Psych.dump
36
+ # @see https://ruby-doc.org/stdlib-2.7.0/libdoc/psych/rdoc/Psych.html#method-c-dump Psych.dump
44
37
  def dump node, filepath
45
38
  require 'yaml'
46
39
  serializer.dump ::YAML.dump(node), filepath
@@ -11,8 +11,8 @@ module Rambling
11
11
  # @param [Configuration::Properties] properties the configuration
12
12
  # properties set up so far.
13
13
  def initialize properties
14
- @properties = properties
15
14
  super()
15
+ @properties = properties
16
16
  end
17
17
 
18
18
  # Unzip contents from specified filepath and load in contents from
@@ -3,6 +3,6 @@
3
3
  module Rambling
4
4
  module Trie
5
5
  # Current version of the rambling-trie.
6
- VERSION = '2.3.1'
6
+ VERSION = '2.4.0'
7
7
  end
8
8
  end
data/lib/rambling/trie.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  %w(
4
- comparable compressible compressor configuration container enumerable
5
- inspectable invalid_operation readers serializers stringifyable nodes
6
- version
4
+ comparable compressible compressor configuration container enumerable inspectable invalid_operation
5
+ readers serializers stringifyable nodes version
7
6
  ).each do |file|
8
7
  require File.join('rambling', 'trie', file)
9
8
  end
@@ -23,8 +22,10 @@ module Rambling
23
22
  root = root_builder.call
24
23
 
25
24
  Rambling::Trie::Container.new root, compressor do |container|
25
+ # noinspection RubyMismatchedArgumentType
26
26
  if filepath
27
27
  reader ||= readers.resolve filepath
28
+ # noinspection RubyMismatchedArgumentType,RubyNilAnalysis
28
29
  reader.each_word filepath do |word|
29
30
  container << word
30
31
  end
@@ -39,15 +40,12 @@ module Rambling
39
40
  # Available formats are +yml+, +marshal+, and +zip+ versions of all the
40
41
  # previous formats. You can also define your own.
41
42
  # @param [String] filepath the file to load the words from.
42
- # @param [Serializer, nil] serializer the object responsible of loading
43
- # the trie from disk
43
+ # @param [Serializer, nil] serializer the object responsible of loading the trie from disk.
44
44
  # @return [Container] the trie just loaded.
45
45
  # @yield [Container] the trie just loaded.
46
46
  # @see Rambling::Trie::Serializers Serializers.
47
- # @note Use of
48
- # {https://ruby-doc.org/core-2.7.0/Marshal.html#method-c-load
49
- # Marshal.load} is generally discouraged. Only use the +.marshal+
50
- # format with trusted input.
47
+ # @note Use of # {https://ruby-doc.org/core-2.7.0/Marshal.html#method-c-load Marshal.load} is generally
48
+ # discouraged. Only use the +.marshal+ format with trusted input.
51
49
  def load filepath, serializer = nil
52
50
  serializer ||= serializers.resolve filepath
53
51
  root = serializer.load filepath
@@ -62,21 +60,18 @@ module Rambling
62
60
  # previous formats. You can also define your own.
63
61
  # @param [Container] trie the trie to dump into disk.
64
62
  # @param [String] filepath the file to dump to serialized trie into.
65
- # @param [Serializers::Serializer, nil] serializer the object responsible
66
- # for trie serialization.
63
+ # @param [Serializers::Serializer, nil] serializer the object responsible for trie serialization.
67
64
  # @return [void]
68
- # serializing and dumping the trie into disk.
69
65
  # @see Serializers Serializers.
70
66
  def dump trie, filepath, serializer = nil
71
67
  serializer ||= serializers.resolve filepath
68
+ # noinspection RubyNilAnalysis
72
69
  serializer.dump trie.root, filepath
73
70
  end
74
71
 
75
72
  # Provides configuration properties for the +Rambling::Trie+ gem.
76
- # @return [Configuration::Properties] the configured properties of the
77
- # gem.
78
- # @yield [Configuration::Properties] the configured properties of the
79
- # gem.
73
+ # @return [Configuration::Properties] the configured properties of the gem.
74
+ # @yield [Configuration::Properties] the configured properties of the gem.
80
75
  def config
81
76
  yield properties if block_given?
82
77
  properties
@@ -5,7 +5,7 @@ require 'rambling/trie/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.authors = ['Edgar Gonzalez', 'Lilibeth De La Cruz']
8
- gem.email = ['edggonzalezg@gmail.com', 'lilibethdlc@gmail.com']
8
+ gem.email = %w(edggonzalezg@gmail.com lilibethdlc@gmail.com)
9
9
 
10
10
  gem.description = <<~DESCRIPTION.gsub(%r{\s+}, ' ')
11
11
  The Rambling Trie is a Ruby implementation of the trie data structure, which
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  DESCRIPTION
14
14
 
15
15
  gem.summary = 'A Ruby implementation of the trie data structure.'
16
- gem.homepage = 'http://github.com/gonzedge/rambling-trie'
16
+ gem.homepage = 'https://github.com/gonzedge/rambling-trie'
17
17
  gem.date = Time.now.strftime '%Y-%m-%d'
18
18
  gem.metadata = {
19
19
  'changelog_uri' => 'https://github.com/gonzedge/rambling-trie/blob/master/CHANGELOG.md',
@@ -35,7 +35,7 @@ Gem::Specification.new do |gem|
35
35
  gem.platform = Gem::Platform::RUBY
36
36
  gem.required_ruby_version = '>= 2.7', '< 4'
37
37
 
38
- gem.add_development_dependency 'rake', '~> 13.0'
38
+ gem.add_development_dependency 'rake', '~> 13.1'
39
39
  gem.add_development_dependency 'rspec', '~> 3.12'
40
- gem.add_development_dependency 'yard', '~> 0.9.28'
40
+ gem.add_development_dependency 'yard', '~> 0.9.34'
41
41
  end
@@ -6,6 +6,38 @@ require 'zip'
6
6
  describe Rambling::Trie do
7
7
  let(:assets_path) { File.join ::SPEC_ROOT, 'assets' }
8
8
 
9
+ describe '::VERSION' do
10
+ let(:root_path) { File.join ::SPEC_ROOT, '..' }
11
+ let(:readme_path) { File.join root_path, 'README.md' }
12
+ let(:readme) { File.read readme_path }
13
+ let(:changelog_path) { File.join root_path, 'CHANGELOG.md' }
14
+ let(:changelog) { File.read changelog_path }
15
+
16
+ let(:changelog_versions) do
17
+ matches = []
18
+ changelog.scan %r{^## (\d+\.\d+\.\d+)} do |match|
19
+ matches << match[0]
20
+ end
21
+ matches
22
+ end
23
+
24
+ it 'matches with the version in the README badge' do
25
+ match = %r{\?version=(?<version>.*)$}.match readme
26
+ expect(match['version']).to eq Rambling::Trie::VERSION
27
+ end
28
+
29
+ it 'is the version before the one at the top of the CHANGELOG' do
30
+ changelog_version = Gem::Version.new changelog_versions.first
31
+ lib_version = Gem::Version.new "#{Rambling::Trie::VERSION}.0"
32
+ expect(changelog_version).to eq lib_version.bump
33
+ end
34
+
35
+ it 'is included in the CHANGELOG diffs' do
36
+ changelog_versions.shift
37
+ expect(changelog_versions.first).to eq Rambling::Trie::VERSION
38
+ end
39
+ end
40
+
9
41
  context 'when providing words directly' do
10
42
  it_behaves_like 'a compressible trie' do
11
43
  let(:trie) { described_class.create }
@@ -18,7 +50,7 @@ describe Rambling::Trie do
18
50
  context 'when provided with words with unicode characters' do
19
51
  it_behaves_like 'a compressible trie' do
20
52
  let(:trie) { described_class.create }
21
- let(:words) do
53
+ let :words do
22
54
  %w(poquísimas palabras para nuestra prueba de integración completa 🙃)
23
55
  end
24
56
 
@@ -50,14 +82,14 @@ describe Rambling::Trie do
50
82
  context 'when serialized with Ruby marshal format (default)' do
51
83
  it_behaves_like 'a serializable trie' do
52
84
  let(:trie_to_serialize) { described_class.create words_filepath }
53
- let(:format) { :marshal }
85
+ let(:file_format) { :marshal }
54
86
  end
55
87
  end
56
88
 
57
89
  context 'when serialized with YAML' do
58
90
  it_behaves_like 'a serializable trie' do
59
91
  let(:trie_to_serialize) { described_class.create words_filepath }
60
- let(:format) { :yml }
92
+ let(:file_format) { :yml }
61
93
  end
62
94
  end
63
95
 
@@ -77,7 +109,7 @@ describe Rambling::Trie do
77
109
 
78
110
  it_behaves_like 'a serializable trie' do
79
111
  let(:trie_to_serialize) { described_class.create words_filepath }
80
- let(:format) { 'marshal.zip' }
112
+ let(:file_format) { 'marshal.zip' }
81
113
  end
82
114
  end
83
115
  end
@@ -4,18 +4,18 @@ require 'spec_helper'
4
4
 
5
5
  describe Rambling::Trie::Configuration::ProviderCollection do
6
6
  let(:configured_default) { nil }
7
- let(:configured_providers) do
7
+ let :configured_providers do
8
8
  { one: first_provider, two: second_provider }
9
9
  end
10
10
 
11
- let(:first_provider) do
11
+ let :first_provider do
12
12
  instance_double 'Rambling::Trie::Serializers::Marshal', :first_provider
13
13
  end
14
- let(:second_provider) do
14
+ let :second_provider do
15
15
  instance_double 'Rambling::Trie::Serializers::Marshal', :second_provider
16
16
  end
17
17
 
18
- let(:provider_collection) do
18
+ let :provider_collection do
19
19
  described_class.new(
20
20
  :provider,
21
21
  configured_providers,
@@ -72,7 +72,7 @@ describe Rambling::Trie::Configuration::ProviderCollection do
72
72
  end
73
73
 
74
74
  describe '#add' do
75
- let(:provider) do
75
+ let :provider do
76
76
  instance_double 'Rambling::Trie::Serializers::Marshal', :provider
77
77
  end
78
78
 
@@ -86,7 +86,7 @@ describe Rambling::Trie::Configuration::ProviderCollection do
86
86
  end
87
87
 
88
88
  describe '#default=' do
89
- let(:other_provider) do
89
+ let :other_provider do
90
90
  instance_double 'Rambling::Trie::Serializers::Marshal', :other_provider
91
91
  end
92
92
 
@@ -155,7 +155,7 @@ describe Rambling::Trie::Configuration::ProviderCollection do
155
155
 
156
156
  describe '#reset' do
157
157
  let(:configured_default) { second_provider }
158
- let(:provider) do
158
+ let :provider do
159
159
  instance_double 'Rambling::Trie::Serializers::Marshal', :provider
160
160
  end
161
161
 
@@ -171,7 +171,7 @@ describe Rambling::Trie::Container do
171
171
 
172
172
  describe '#word?' do
173
173
  it_behaves_like 'a propagating node' do
174
- let(:method) { :word? }
174
+ let(:method_name) { :word? }
175
175
  end
176
176
 
177
177
  context 'when word is contained' do
@@ -202,7 +202,7 @@ describe Rambling::Trie::Container do
202
202
  describe '#partial_word?' do
203
203
  context 'with underlying node' do
204
204
  it_behaves_like 'a propagating node' do
205
- let(:method) { :partial_word? }
205
+ let(:method_name) { :partial_word? }
206
206
  end
207
207
  end
208
208
 
@@ -329,7 +329,7 @@ describe Rambling::Trie::Container do
329
329
 
330
330
  describe '#==' do
331
331
  context 'when the root nodes are the same' do
332
- let(:other_container) do
332
+ let :other_container do
333
333
  described_class.new container.root, compressor
334
334
  end
335
335
 
@@ -340,7 +340,7 @@ describe Rambling::Trie::Container do
340
340
 
341
341
  context 'when the root nodes are not the same' do
342
342
  let(:other_root) { Rambling::Trie::Nodes::Raw.new }
343
- let(:other_container) do
343
+ let :other_container do
344
344
  described_class.new other_root, compressor
345
345
  end
346
346
 
@@ -7,6 +7,12 @@ describe Rambling::Trie::Nodes::Compressed do
7
7
  let(:compressor) { Rambling::Trie::Compressor.new }
8
8
  let(:node) { compressor.compress raw_node }
9
9
 
10
+ describe '#new' do
11
+ it 'is not a word' do
12
+ expect(node).not_to be_word
13
+ end
14
+ end
15
+
10
16
  it_behaves_like 'a trie node implementation' do
11
17
  def add_word_to_tree word
12
18
  add_word raw_node, word
@@ -5,6 +5,12 @@ require 'spec_helper'
5
5
  describe Rambling::Trie::Nodes::Raw do
6
6
  let(:node) { described_class.new }
7
7
 
8
+ describe '#new' do
9
+ it 'is not a word' do
10
+ expect(node).not_to be_word
11
+ end
12
+ end
13
+
8
14
  it_behaves_like 'a trie node implementation' do
9
15
  def add_word_to_tree word
10
16
  add_word node, word
@@ -17,10 +23,6 @@ describe Rambling::Trie::Nodes::Raw do
17
23
  def assign_letter letter
18
24
  node.letter = letter
19
25
  end
20
-
21
- it 'is not a word' do
22
- expect(node).not_to be_word
23
- end
24
26
  end
25
27
 
26
28
  describe '#compressed?' do
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  describe Rambling::Trie::Serializers::File do
6
6
  it_behaves_like 'a serializer' do
7
- let(:format) { :file }
7
+ let(:file_format) { :file }
8
8
  let(:content) { trie.to_a.join ' ' }
9
9
  let(:format_content) { ->(content) { content } }
10
10
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  describe Rambling::Trie::Serializers::Marshal do
6
6
  it_behaves_like 'a serializer' do
7
- let(:format) { :marshal }
7
+ let(:file_format) { :marshal }
8
8
  let(:format_content) { Marshal.method(:dump) }
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  describe Rambling::Trie::Serializers::Yaml do
6
6
  it_behaves_like 'a serializer' do
7
- let(:format) { :yml }
7
+ let(:file_format) { :yml }
8
8
  let(:format_content) { YAML.method(:dump) }
9
9
  end
10
10
  end
@@ -8,14 +8,14 @@ describe Rambling::Trie::Serializers::Zip do
8
8
  yml: YAML.method(:dump),
9
9
  marshal: Marshal.method(:dump),
10
10
  file: Marshal.method(:dump),
11
- }.each do |format, dump_method|
12
- context "with '.#{format}'" do
11
+ }.each do |file_format, dump_method|
12
+ context "with '.#{file_format}'" do
13
13
  it_behaves_like 'a serializer' do
14
14
  let(:properties) { Rambling::Trie::Configuration::Properties.new }
15
15
  let(:serializer) { described_class.new properties }
16
- let(:format) { :zip }
16
+ let(:file_format) { :zip }
17
17
 
18
- let(:filepath) { File.join tmp_path, "trie-root.#{format}.zip" }
18
+ let(:filepath) { File.join tmp_path, "trie-root.#{file_format}.zip" }
19
19
  let(:format_content) { ->(content) { zip dump_method.call content } }
20
20
  let(:filename) { File.basename(filepath).gsub %r{\.zip}, '' }
21
21
 
@@ -28,14 +28,14 @@ describe Rambling::Trie do
28
28
 
29
29
  context 'with a filepath' do
30
30
  let(:filepath) { 'a test filepath' }
31
- let(:reader) do
31
+ let :reader do
32
32
  instance_double 'Rambling::Trie::Readers::PlainText', :reader
33
33
  end
34
34
  let(:words) { %w(a couple of test words over here) }
35
35
 
36
36
  before do
37
37
  receive_and_yield = receive(:each_word)
38
- words.inject(receive_and_yield) do |yielder, word|
38
+ words.inject receive_and_yield do |yielder, word|
39
39
  yielder.and_yield word
40
40
  end
41
41
 
@@ -54,7 +54,7 @@ describe Rambling::Trie do
54
54
 
55
55
  context 'without any reader' do
56
56
  let(:filepath) { 'a test filepath' }
57
- let(:reader) do
57
+ let :reader do
58
58
  instance_double(
59
59
  'Rambling::Trie::Readers::PlainText',
60
60
  :reader,
@@ -82,7 +82,7 @@ describe Rambling::Trie do
82
82
  let(:root) { Rambling::Trie::Nodes::Raw.new }
83
83
  let(:compressor) { Rambling::Trie::Compressor.new }
84
84
  let(:container) { Rambling::Trie::Container.new root, compressor }
85
- let(:serializer) do
85
+ let :serializer do
86
86
  instance_double(
87
87
  'Rambling::True::Serializers::File',
88
88
  :serializer,
@@ -101,21 +101,21 @@ describe Rambling::Trie do
101
101
  end
102
102
 
103
103
  context 'without a serializer' do
104
- let(:marshal_serializer) do
104
+ let :marshal_serializer do
105
105
  instance_double(
106
106
  'Rambling::Trie::Serializers::Marshal',
107
107
  :marshal_serializer,
108
108
  load: nil,
109
109
  )
110
110
  end
111
- let(:default_serializer) do
111
+ let :default_serializer do
112
112
  instance_double(
113
113
  'Rambling::Trie::Serializers::File',
114
114
  :default_serializer,
115
115
  load: nil,
116
116
  )
117
117
  end
118
- let(:yaml_serializer) do
118
+ let :yaml_serializer do
119
119
  instance_double(
120
120
  'Rambling::Trie::Serializers::Yaml',
121
121
  :yaml_serializer,
@@ -168,26 +168,26 @@ describe Rambling::Trie do
168
168
  describe '.dump' do
169
169
  let(:filename) { 'a trie' }
170
170
  let(:root) { instance_double 'Rambling::Trie::Serializers::Marshal', :root }
171
- let(:compressor) do
171
+ let :compressor do
172
172
  instance_double 'Rambling::Trie::Serializers::Marshal', :compressor
173
173
  end
174
174
  let(:trie) { Rambling::Trie::Container.new root, compressor }
175
175
 
176
- let(:marshal_serializer) do
176
+ let :marshal_serializer do
177
177
  instance_double(
178
178
  'Rambling::Trie::Serializers::Marshal',
179
179
  :marshal_serializer,
180
180
  dump: nil,
181
181
  )
182
182
  end
183
- let(:yaml_serializer) do
183
+ let :yaml_serializer do
184
184
  instance_double(
185
185
  'Rambling::Trie::Serializers::Yaml',
186
186
  :yaml_serializer,
187
187
  dump: nil,
188
188
  )
189
189
  end
190
- let(:default_serializer) do
190
+ let :default_serializer do
191
191
  instance_double(
192
192
  'Rambling::Trie::Serializers::File',
193
193
  :default_serializer,
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  require 'yaml'
4
4
  require 'simplecov'
5
5
 
6
+ COVERAGE_FILTER = %r{/spec/}.freeze
7
+
6
8
  if ENV.key? 'COVERALLS_REPO_TOKEN'
7
9
  require 'coveralls'
8
10
 
@@ -11,11 +13,9 @@ if ENV.key? 'COVERALLS_REPO_TOKEN'
11
13
  Coveralls::SimpleCov::Formatter,
12
14
  ]
13
15
 
14
- Coveralls.wear! do
15
- add_filter '/spec/'
16
- end
16
+ Coveralls.wear! { add_filter COVERAGE_FILTER }
17
17
  else
18
- SimpleCov.start
18
+ SimpleCov.start { add_filter COVERAGE_FILTER }
19
19
  end
20
20
 
21
21
  require 'rspec'
@@ -27,7 +27,7 @@ RSpec.configure do |config|
27
27
  config.tty = true
28
28
  config.formatter = :documentation
29
29
  config.order = :random
30
- config.run_all_when_everything_filtered = true
30
+ config.filter_run_when_matching :focus
31
31
  config.raise_errors_for_deprecations!
32
32
  end
33
33
 
@@ -24,7 +24,7 @@ shared_examples_for 'a propagating node' do
24
24
  compressed_value, instance_double_class = test_params
25
25
 
26
26
  context "when root has compressed=#{compressed_value}" do
27
- let(:root) do
27
+ let :root do
28
28
  instance_double(
29
29
  instance_double_class,
30
30
  :root,
@@ -35,8 +35,8 @@ shared_examples_for 'a propagating node' do
35
35
  end
36
36
 
37
37
  it 'calls the root with the word characters' do
38
- container.public_send method, 'words'
39
- expect(root).to have_received(method).with %w(w o r d s)
38
+ container.public_send method_name, 'words'
39
+ expect(root).to have_received(method_name).with %w(w o r d s)
40
40
  end
41
41
  end
42
42
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  shared_examples_for 'a serializable trie' do
4
4
  let(:tmp_path) { File.join ::SPEC_ROOT, 'tmp' }
5
- let(:filepath) { File.join tmp_path, "trie-root.#{format}" }
5
+ let(:filepath) { File.join tmp_path, "trie-root.#{file_format}" }
6
6
 
7
7
  context 'with an uncompressed trie' do
8
8
  before { Rambling::Trie.dump trie_to_serialize, filepath }
@@ -5,7 +5,7 @@ shared_examples_for 'a serializer' do
5
5
 
6
6
  let(:trie) { Rambling::Trie.create }
7
7
  let(:tmp_path) { File.join ::SPEC_ROOT, 'tmp' }
8
- let(:filepath) { File.join tmp_path, "trie-root.#{format}" }
8
+ let(:filepath) { File.join tmp_path, "trie-root.#{file_format}" }
9
9
  let(:content) { trie.root }
10
10
 
11
11
  before do
@@ -52,7 +52,7 @@ shared_examples_for 'a serializer' do
52
52
 
53
53
  it "loads a compressed=#{compress_value} object" do
54
54
  loaded = serializer.load filepath
55
- expect(loaded.compressed?).to be compress_value if :file != format
55
+ expect(loaded.compressed?).to be compress_value unless :file == file_format
56
56
  end
57
57
  end
58
58
  end
@@ -21,7 +21,8 @@ shared_examples_for 'a trie node' do
21
21
  end
22
22
 
23
23
  context 'with a letter and a parent' do
24
- let(:parent) { node.class.new }
24
+ let(:parent) { node_class.new }
25
+ # noinspection RubyArgCount
25
26
  let(:node_with_parent) { node_class.new :a, parent }
26
27
 
27
28
  it 'does not have any letter' do
@@ -71,7 +72,7 @@ shared_examples_for 'a trie node' do
71
72
  end
72
73
 
73
74
  describe 'delegates and aliases' do
74
- let(:children_tree) do
75
+ let :children_tree do
75
76
  instance_double(
76
77
  'Hash',
77
78
  :children_tree,