diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..90730c7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index d8372fb..d4aad2c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,20 @@ 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 @@ -13,6 +27,7 @@ PLATFORMS DEPENDENCIES dorian-to_struct! + rspec RUBY VERSION ruby 3.3.0p0 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..d7363d4 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,2 @@ +require "rspec" +require_relative "../lib/dorian-to_struct" diff --git a/spec/to_struct_spec.rb b/spec/to_struct_spec.rb new file mode 100644 index 0000000..8e00a7e --- /dev/null +++ b/spec/to_struct_spec.rb @@ -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