|
1 | | -require 'spec_helper' |
2 | | -require 'erb_renderer' |
| 1 | +require "spec_helper" |
| 2 | +require "erb_renderer" |
3 | 3 |
|
4 | | -RSpec.describe 'PropertyStruct' do |
5 | | - describe 'initialization and attribute access' do |
6 | | - it 'provides dynamic attribute access for hash keys' do |
7 | | - ps = PropertyStruct.new(name: 'test', value: 42) |
8 | | - expect(ps.name).to eq('test') |
| 4 | +RSpec.describe "PropertyStruct" do |
| 5 | + describe "initialization and attribute access" do |
| 6 | + it "provides dynamic attribute access for hash keys" do |
| 7 | + ps = PropertyStruct.new(name: "test", value: 42) |
| 8 | + expect(ps.name).to eq("test") |
9 | 9 | expect(ps.value).to eq(42) |
10 | 10 | end |
11 | 11 |
|
12 | | - it 'converts string keys to symbols' do |
13 | | - ps = PropertyStruct.new('name' => 'test', 'value' => 42) |
14 | | - expect(ps.name).to eq('test') |
| 12 | + it "converts string keys to symbols" do |
| 13 | + ps = PropertyStruct.new("name" => "test", "value" => 42) |
| 14 | + expect(ps.name).to eq("test") |
15 | 15 | expect(ps.value).to eq(42) |
16 | 16 | end |
17 | 17 |
|
18 | | - it 'supports nested attribute access' do |
19 | | - ps = PropertyStruct.new(config: { database: { host: 'localhost', port: 5432 } }) |
| 18 | + it "supports nested attribute access" do |
| 19 | + ps = PropertyStruct.new(config: {database: {host: "localhost", port: 5432}}) |
20 | 20 | nested = ps.config |
21 | 21 | expect(nested).to be_a(PropertyStruct) |
22 | 22 | expect(nested.database).to be_a(PropertyStruct) |
23 | | - expect(nested.database.host).to eq('localhost') |
| 23 | + expect(nested.database.host).to eq("localhost") |
24 | 24 | expect(nested.database.port).to eq(5432) |
25 | 25 | end |
26 | 26 |
|
27 | | - it 'handles arrays of hashes' do |
28 | | - ps = PropertyStruct.new(servers: [{ name: 'web1', ip: '10.0.0.1' }, { name: 'web2', ip: '10.0.0.2' }]) |
| 27 | + it "handles arrays of hashes" do |
| 28 | + ps = PropertyStruct.new(servers: [{name: "web1", ip: "10.0.0.1"}, {name: "web2", ip: "10.0.0.2"}]) |
29 | 29 | servers = ps.servers |
30 | 30 | expect(servers).to be_an(Array) |
31 | 31 | expect(servers.length).to eq(2) |
32 | | - expect(servers.first.name).to eq('web1') |
33 | | - expect(servers.last.ip).to eq('10.0.0.2') |
| 32 | + expect(servers.first.name).to eq("web1") |
| 33 | + expect(servers.last.ip).to eq("10.0.0.2") |
34 | 34 | end |
35 | 35 |
|
36 | | - it 'responds to method queries correctly' do |
37 | | - ps = PropertyStruct.new(existing_key: 'value') |
| 36 | + it "responds to method queries correctly" do |
| 37 | + ps = PropertyStruct.new(existing_key: "value") |
38 | 38 | expect(ps.respond_to?(:existing_key)).to be true |
39 | 39 | expect(ps.respond_to?(:nonexistent_key)).to be false |
40 | 40 | end |
41 | 41 | end |
42 | 42 |
|
43 | | - describe 'Ruby standard library method pass-through' do |
44 | | - it 'supports array operations like map' do |
| 43 | + describe "Ruby standard library method pass-through" do |
| 44 | + it "supports array operations like map" do |
45 | 45 | ps = PropertyStruct.new(ports: [8080, 8081, 8082]) |
46 | 46 | expect(ps.ports.map(&:to_s)).to eq(%w[8080 8081 8082]) |
47 | 47 | end |
48 | 48 |
|
49 | | - it 'supports string operations' do |
50 | | - ps = PropertyStruct.new(url: 'https://example.com') |
51 | | - expect(ps.url.start_with?('https')).to be true |
52 | | - expect(ps.url.split('://')).to eq(['https', 'example.com']) |
| 49 | + it "supports string operations" do |
| 50 | + ps = PropertyStruct.new(url: "https://example.com") |
| 51 | + expect(ps.url.start_with?("https")).to be true |
| 52 | + expect(ps.url.split("://")).to eq(["https", "example.com"]) |
53 | 53 | end |
54 | 54 |
|
55 | | - it 'supports hash operations via direct access' do |
56 | | - ps = PropertyStruct.new(config: { a: 1, b: 2, c: 3 }) |
| 55 | + it "supports hash operations via direct access" do |
| 56 | + ps = PropertyStruct.new(config: {a: 1, b: 2, c: 3}) |
57 | 57 | expect(ps.config.a).to eq(1) |
58 | 58 | expect(ps.config.b).to eq(2) |
59 | 59 | expect(ps.config.c).to eq(3) |
60 | 60 | end |
61 | 61 |
|
62 | | - it 'supports nil and empty checks' do |
63 | | - ps = PropertyStruct.new(empty_string: '', nil_value: nil, filled: 'data') |
| 62 | + it "supports nil and empty checks" do |
| 63 | + ps = PropertyStruct.new(empty_string: "", nil_value: nil, filled: "data") |
64 | 64 | expect(ps.empty_string.empty?).to be true |
65 | 65 | expect(ps.nil_value.nil?).to be true |
66 | 66 | expect(ps.filled.nil?).to be false |
67 | 67 | end |
68 | 68 | end |
69 | 69 |
|
70 | | - describe 'compatibility across Ruby versions' do |
71 | | - it 'works with ERB rendering' do |
| 70 | + describe "compatibility across Ruby versions" do |
| 71 | + it "works with ERB rendering" do |
72 | 72 | template = ERB.new("<%= ps.name.upcase %>: <%= ps.ports.join(',') %>") |
73 | | - ps = PropertyStruct.new(name: 'service', ports: [80, 443, 8080]) |
| 73 | + ps = PropertyStruct.new(name: "service", ports: [80, 443, 8080]) |
74 | 74 | result = template.result(binding) |
75 | | - expect(result).to eq('SERVICE: 80,443,8080') |
| 75 | + expect(result).to eq("SERVICE: 80,443,8080") |
76 | 76 | end |
77 | 77 |
|
78 | | - it 'maintains OpenStruct API compatibility' do |
| 78 | + it "maintains OpenStruct API compatibility" do |
79 | 79 | # Test that PropertyStruct can be used as a drop-in replacement for OpenStruct |
80 | | - ps = PropertyStruct.new(field1: 'value1', field2: 'value2') |
| 80 | + ps = PropertyStruct.new(field1: "value1", field2: "value2") |
81 | 81 | expect(ps).to respond_to(:field1) |
82 | 82 | expect(ps).to respond_to(:field2) |
83 | | - expect(ps.field1).to eq('value1') |
84 | | - expect(ps.field2).to eq('value2') |
| 83 | + expect(ps.field1).to eq("value1") |
| 84 | + expect(ps.field2).to eq("value2") |
85 | 85 | end |
86 | 86 | end |
87 | 87 | end |
0 commit comments