Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias @value to @exception in Try::Error #177

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/dry/monads/try.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class Error < Try
def initialize(exception)
super()

@exception = exception
@exception = @value = exception
end

# @return [String]
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/try_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
it { is_expected.to eql(described_class.new([ZeroDivisionError], "foo")) }
it { is_expected.not_to eql(error[division_error]) }

it "deconstructs to the value" do
expect(subject.deconstruct).to eq ["foo"]
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please test it with pattern matching rather than hitting .deconstruct directly? It's done like this in other tests. Also equality is checked via eql rather than eq

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review @flash-gordon - please see 9caca77


it "dumps to string" do
expect(subject.to_s).to eql('Try::Value("foo")')
expect(value[[], unit].to_s).to eql("Try::Value()")
Expand Down Expand Up @@ -210,6 +214,10 @@
let(:upcase_value) { described_class.new([ZeroDivisionError], "FOO") }
let(:upcase_error) { try::Error.new(division_error) }

it "deconstructs to the exception" do
expect(subject.deconstruct).to eq [division_error]
end

describe ".call" do
it "is an alias for new" do
expect(try::Error.(division_error)).to eql(subject)
Expand Down
Loading