Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dorianmariecom committed Apr 3, 2024
1 parent 952092a commit 629ca1c
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI
on: push
jobs:
bundler-audit:
name: Bundler Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bin/bundler-audit check --update
rspec:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.0
bundler-cache: true
- run: bin/test
rubocop:
name: Rubocop
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bin/rubocop
yarn-audit:
name: Yarn Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: yarn audit
15 changes: 15 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@ PATH
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.5.1)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)

PLATFORMS
arm64-darwin-23
ruby

DEPENDENCIES
dorian-to_struct!
rspec

RUBY VERSION
ruby 3.3.0p0
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "rspec"
require_relative "../lib/dorian-to_struct"
41 changes: 41 additions & 0 deletions spec/to_struct_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require "spec_helper"

HASH = {
first_name: "Dorian",
last_name: "Marié",
events: [
{ name: "Party!" }
]
}

STRUCT = HASH.to_struct
DEEP_STRUCT = HASH.to_deep_struct

RSpec.describe "to_struct" do
describe "#to_struct" do
it "works" do
expect(STRUCT.first_name).to eq("Dorian")
expect(STRUCT.last_name).to eq("Marié")
end

it "raises an eerror on missing value" do
expect { STRUCT.birthday }.to raise_error(NoMethodError)
end

it "doesn't deep structify" do
expect { STRUCT.events.first.name }.to raise_error(NoMethodError)
end
end

describe "@to_deep_struct" do
it "works" do
expect(DEEP_STRUCT.first_name).to eq("Dorian")
expect(DEEP_STRUCT.last_name).to eq("Marié")
expect(DEEP_STRUCT.events.first.name).to eq("Party!")
end

it "raises an eerror on missing value" do
expect { DEEP_STRUCT.birthday }.to raise_error(NoMethodError)
end
end
end

0 comments on commit 629ca1c

Please sign in to comment.