Created
April 26, 2020 22:24
-
-
Save WojciechKo/769db8f43a5e9333c07f759847ee04dd to your computer and use it in GitHub Desktop.
When do notation is used by including `Do::All` it makes every methods publicly available. To execute run `ruby dry_monad_private_methods_issue.rb`
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
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'dry-monads', '1.3.5' | |
gem 'rspec', '3.9.0' | |
end | |
require 'dry-monads' | |
class Service | |
include Dry::Monads[:result, :do] | |
def call | |
yield fetch_data | |
end | |
private | |
def fetch_data | |
Success(:data) | |
end | |
end | |
RSpec.describe Service, :aggregate_failures do | |
subject(:service) { Service.new } | |
describe '#call' do | |
it 'returns data' do | |
expect(service.call).to eq(:data) | |
end | |
end | |
describe '#fetch_data' do | |
it 'raises NoMethodError' do | |
expect { service.fetch_data }.to raise_error(NoMethodError) | |
end | |
end | |
end | |
RSpec::Core::Runner.run(['spec', '--format', 'doc']) | |
# $ ruby dry_monad_private_issue.rb | |
# | |
# Service | |
# #call | |
# returns data | |
# #fetch_data | |
# raises NoMethodError (FAILED - 1) | |
# | |
# Failures: | |
# | |
# 1) Service#fetch_data raises NoMethodError | |
# Failure/Error: expect { service.fetch_data }.to raise_error(NoMethodError) | |
# expected NoMethodError but nothing was raised | |
# # dry_monad_private_methods_issue.rb:36:in `block (3 levels) in <main>' | |
# # dry_monad_private_methods_issue.rb:41:in `<main>' | |
# | |
# Finished in 0.01185 seconds (files took 0.13012 seconds to load) | |
# 2 examples, 1 failure | |
# | |
# Failed examples: | |
# | |
# rspec dry_monad_private_methods_issue.rb:35 # Service#fetch_data raises NoMethodError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment