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

Update code to fix warnings from dry-monads #72

Merged
merged 3 commits into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ script:
after_success:
- '[ -d coverage ] && bundle exec codeclimate-test-reporter'
rvm:
- 2.1.10
- 2.2.7
- 2.3.4
- 2.4.1
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 0.10.3 - to-be-released
# 0.11.0 / to-be-released

## Fixed

Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ source "https://rubygems.org"

gemspec

gem "dry-monads", git: "https://github.com/dry-rb/dry-monads.git"
gem "dry-matcher", git: "https://github.com/dry-rb/dry-matcher.git"

group :test do
gem "simplecov"
gem "codeclimate-test-reporter"
Expand Down
2 changes: 1 addition & 1 deletion dry-transaction.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
spec.files = Dir["README.md", "LICENSE.md", "Gemfile*", "Rakefile", "lib/**/*", "spec/**/*"]
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.1.0"
spec.required_ruby_version = ">= 2.2.0"

spec.add_runtime_dependency "dry-container", ">= 0.2.8"
spec.add_runtime_dependency "dry-matcher", ">= 0.5.0"
Expand Down
6 changes: 3 additions & 3 deletions lib/dry/transaction/result_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ module Transaction
ResultMatcher = Dry::Matcher.new(
success: Dry::Matcher::Case.new(
match: -> result { result.right? },
resolve: -> result { result.value }
resolve: -> result { result.value! }
),
failure: Dry::Matcher::Case.new(
match: -> result, step_name = nil {
if step_name
result.left? && result.value.step.step_name == step_name
result.left? && result.left.step.step_name == step_name
else
result.left?
end
},
resolve: -> result { result.value.value }
resolve: -> result { result.left.value }
)
)
end
Expand Down
10 changes: 5 additions & 5 deletions spec/integration/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Test::Container
end

it "wraps the result of the final operation" do
expect(transaction.call(input).value).to eq(name: "Jane", email: "[email protected]")
expect(transaction.call(input).value!).to eq(name: "Jane", email: "[email protected]")
end

it "can be called multiple times to the same effect" do
Expand Down Expand Up @@ -256,7 +256,7 @@ def persist(input)
end

it "wraps the result of the failing operation" do
expect(transaction.call(input).value).to be_a Test::NotValidError
expect(transaction.call(input).left).to be_a Test::NotValidError
end

it "supports matching on failure" do
Expand Down Expand Up @@ -338,17 +338,17 @@ class Test::ContainerRaw
end

it "returns the failing value from the operation" do
expect(transaction.call(input).value).to eq "raw failure"
expect(transaction.call(input).left).to eq "raw failure"
end

it "returns an object that quacks like expected" do
result = transaction.call(input).value
result = transaction.call(input).left

expect(Array(result)).to eq(['raw failure'])
end

it "does not allow to call private methods on the result accidently" do
result = transaction.call(input).value
result = transaction.call(input).left

expect { result.print('') }.to raise_error(NoMethodError)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/transaction_without_steps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Test::Container
end

it "wraps the result of the final operation" do
expect(transaction.call().value).to eq(name: "Jane", email: "[email protected]")
expect(transaction.call().value!).to eq(name: "Jane", email: "[email protected]")
end

it "supports matching on success" do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/step_adapters/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
end

it "return the result of the operation as output" do
expect(subject.call(step, 'input').value).to eql 'INPUT'
expect(subject.call(step, 'input').value!).to eql 'INPUT'
end
end
end
4 changes: 2 additions & 2 deletions spec/unit/step_adapters/raw_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end

it "return the result of the operation as output" do
expect(subject.call(step, 'input').value).to eql 'INPUT'
expect(subject.call(step, 'input').left).to eql 'INPUT'
end
end

Expand All @@ -45,7 +45,7 @@
end

it "return the result of the operation as output" do
expect(subject.call(step, 'input').value).to eql 'INPUT'
expect(subject.call(step, 'input').value!).to eql 'INPUT'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/step_adapters/tee_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
end

it "return the original input as output" do
expect(subject.call(step, 'input').value).to eql 'input'
expect(subject.call(step, 'input').value!).to eql 'input'
end
end
end
12 changes: 6 additions & 6 deletions spec/unit/step_adapters/try_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@

it "return the raised error as output" do
result = subject.call(step, 1234)
expect(result.value).to be_a Test::NotValidError
expect(result.value.message).to eql 'not a string'
expect(result.left).to be_a Test::NotValidError
expect(result.left.message).to eql 'not a string'
end

context "when using the :raise option" do
Expand All @@ -60,8 +60,8 @@

it "return the error specified by :raise as output" do
result = subject.call(step, 1234)
expect(result.value).to be_a Test::BetterNamingError
expect(result.value.message).to eql 'not a string'
expect(result.left).to be_a Test::BetterNamingError
expect(result.left.message).to eql 'not a string'
end
end
end
Expand All @@ -73,7 +73,7 @@
end

it "return the result of the operation as output" do
expect(subject.call(step, 'input').value).to eql 'INPUT'
expect(subject.call(step, 'input').value!).to eql 'INPUT'
end

context "when using the :raise option" do
Expand All @@ -89,7 +89,7 @@
end

it "return the result of the operation as output" do
expect(subject.call(step, 'input').value).to eql 'INPUT'
expect(subject.call(step, 'input').value!).to eql 'INPUT'
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def test_success(*args); end

it "wraps value in StepFailure" do
aggregate_failures do
expect(subject.value).to be_a Dry::Transaction::StepFailure
expect(subject.value.value).to eq "error"
expect(subject.left).to be_a Dry::Transaction::StepFailure
expect(subject.left.value).to eq "error"
end
end

Expand Down