File: base_hash.rb

package info (click to toggle)
ruby-snaky-hash 2.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,156 kB
  • sloc: ruby: 1,298; javascript: 529; makefile: 4; sh: 4
file content (41 lines) | stat: -rw-r--r-- 1,163 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

# A shared context that provides a base hash with various key formats for testing
#
# @example Using the shared context
#   RSpec.describe MyClass do
#     include_context "base hash"
#     it "has data" do
#       expect(base_hash["varOne"]).to eq(1)
#     end
#   end
RSpec.shared_context "base hash" do
  let(:base_hash) do
    bh = {
      "varOne" => 1,
      "two" => 2,
      :three => 3,
      :varFour => 4,
      "fiveHumpHumps" => 5,
      :nested => {
        "NestedOne" => "One",
        :two => "two",
        "nested_three" => "three",
      },
      "nestedTwo" => {
        "nested_two" => 22,
        :nestedThree => 23,
      },
      :nestedThree => [
        {nestedFour: 4},
        {"nestedFour" => 4},
      ],
      "spaced Key" => "When would this happen?",
      "trailing spaces " => "better safe than sorry",
      "extra   spaces" => "hopefully this never happens",
    }
    # Hashie v5 is the oldest version of hashie that works with non-symbolizable keys
    bh[4] = "not symbolizable" if defined?(Hashie::VERSION) && Gem::Version.new(Hashie::VERSION) >= Gem::Version.new("5.0.0")
    bh
  end
end