Created
January 2, 2025 17:15
-
-
Save drench/bd1220c97ce1016973b9ea53a9d2fc3f to your computer and use it in GitHub Desktop.
Trying some things out with Data.define
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe Data do | |
subject { data.new(**input) } | |
let(:data) { Data.define(:a, :b) } | |
context "when providing all arguments" do | |
context "with string keys" do | |
let(:input) { { "a" => 1, "b" => true } } | |
it { is_expected.to have_attributes(a: 1, b: true) } | |
end | |
context "with symbol keys" do | |
let(:input) { { a: 1, b: true } } | |
it { is_expected.to have_attributes(a: 1, b: true) } | |
end | |
context "with mixed keys" do | |
let(:input) { { "a" => 1, :b => true } } | |
it { is_expected.to have_attributes(a: 1, b: true) } | |
end | |
context "with nil values" do | |
let(:input) { { a: nil, b: nil } } | |
it { is_expected.to have_attributes(a: nil, b: nil) } | |
end | |
end | |
context "when providing extra arguments" do | |
let(:input) { { a: 1, b: true, c: :sea } } | |
it { expect { subject }.to raise_error(ArgumentError) } | |
end | |
context "when providing too few arguments" do | |
let(:input) { { a: 1 } } | |
it { expect { subject }.to raise_error(ArgumentError) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rspec
output: