pax_global_header00006660000000000000000000000064147616651360014531gustar00rootroot0000000000000052 comment=649783d52d15ceb034eeef893a258cb78ec0e156 socketry-async-rspec-649783d/000077500000000000000000000000001476166513600161135ustar00rootroot00000000000000socketry-async-rspec-649783d/.editorconfig000066400000000000000000000000641476166513600205700ustar00rootroot00000000000000root = true [*] indent_style = tab indent_size = 2 socketry-async-rspec-649783d/.github/000077500000000000000000000000001476166513600174535ustar00rootroot00000000000000socketry-async-rspec-649783d/.github/workflows/000077500000000000000000000000001476166513600215105ustar00rootroot00000000000000socketry-async-rspec-649783d/.github/workflows/async-v1.yaml000066400000000000000000000010441476166513600240340ustar00rootroot00000000000000name: Async v1 on: [push, pull_request] jobs: test: runs-on: ${{matrix.os}}-latest strategy: matrix: os: - ubuntu ruby: - "2.7" - "3.0" - "3.1" - "3.2" env: BUNDLE_GEMFILE: gems/async-v1.rb steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{matrix.ruby}} bundler-cache: true - name: Run tests timeout-minutes: 5 run: bundle exec rspec socketry-async-rspec-649783d/.github/workflows/async-v2.yaml000066400000000000000000000007721476166513600240440ustar00rootroot00000000000000name: Async v2 on: [push, pull_request] jobs: test: runs-on: ${{matrix.os}}-latest strategy: matrix: os: - ubuntu ruby: - "3.1" - "3.2" env: BUNDLE_GEMFILE: gems/async-v2.rb steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{matrix.ruby}} bundler-cache: true - name: Run tests timeout-minutes: 5 run: bundle exec rspec socketry-async-rspec-649783d/.github/workflows/coverage.yaml000066400000000000000000000021201476166513600241620ustar00rootroot00000000000000name: Coverage on: [push, pull_request] permissions: contents: read env: CONSOLE_OUTPUT: XTerm COVERAGE: PartialSummary jobs: test: name: ${{matrix.ruby}} on ${{matrix.os}} runs-on: ${{matrix.os}}-latest strategy: matrix: os: - ubuntu - macos ruby: - "3.2" steps: - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{matrix.ruby}} bundler-cache: true - name: Run tests timeout-minutes: 5 run: bundle exec bake test - uses: actions/upload-artifact@v2 with: name: coverage-${{matrix.os}}-${{matrix.ruby}} path: .covered.db validate: needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: ruby-version: "3.2" bundler-cache: true - uses: actions/download-artifact@v3 - name: Validate coverage timeout-minutes: 5 run: bundle exec bake covered:validate --paths */.covered.db \; socketry-async-rspec-649783d/.github/workflows/documentation.yaml000066400000000000000000000023171476166513600252500ustar00rootroot00000000000000name: Documentation on: push: branches: - main # Allows you to run this workflow manually from the Actions tab: workflow_dispatch: # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages: permissions: contents: read pages: write id-token: write # Allow one concurrent deployment: concurrency: group: "pages" cancel-in-progress: true env: CONSOLE_OUTPUT: XTerm BUNDLE_WITH: maintenance jobs: generate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: ruby-version: "3.2" bundler-cache: true - name: Installing packages run: sudo apt-get install wget - name: Generate documentation timeout-minutes: 5 run: bundle exec bake utopia:project:static --force no - name: Upload documentation artifact uses: actions/upload-pages-artifact@v1 with: path: docs deploy: runs-on: ubuntu-latest environment: name: github-pages url: ${{steps.deployment.outputs.page_url}} needs: generate steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v1 socketry-async-rspec-649783d/.github/workflows/test.yaml000066400000000000000000000017061476166513600233570ustar00rootroot00000000000000name: Test on: [push, pull_request] permissions: contents: read env: CONSOLE_OUTPUT: XTerm jobs: test: name: ${{matrix.ruby}} on ${{matrix.os}} runs-on: ${{matrix.os}}-latest continue-on-error: ${{matrix.experimental}} strategy: matrix: os: - ubuntu - macos ruby: - "2.7" - "3.0" - "3.1" - "3.2" experimental: [false] include: - os: ubuntu ruby: truffleruby experimental: true - os: ubuntu ruby: jruby experimental: true - os: ubuntu ruby: head experimental: true steps: - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{matrix.ruby}} bundler-cache: true - name: Run tests timeout-minutes: 10 run: bundle exec bake test socketry-async-rspec-649783d/.gitignore000066400000000000000000000001141476166513600200770ustar00rootroot00000000000000/.bundle/ /pkg/ /gems.locked /.covered.db /external /.rspec /.rspec_status socketry-async-rspec-649783d/.rspec000066400000000000000000000000701476166513600172250ustar00rootroot00000000000000--format documentation --warnings --require spec_helper socketry-async-rspec-649783d/async-rspec.gemspec000066400000000000000000000015721476166513600217140ustar00rootroot00000000000000# frozen_string_literal: true require_relative "lib/async/rspec/version" Gem::Specification.new do |spec| spec.name = "async-rspec" spec.version = Async::RSpec::VERSION spec.summary = "Helpers for writing specs against the async gem." spec.authors = ["Samuel Williams", "Janko Marohnić", "Olle Jonsson", "Cyril Roelandt", "Jeremy Jung", "Robin Goos"] spec.license = "MIT" spec.cert_chain = ['release.cert'] spec.signing_key = File.expand_path('~/.gem/release.pem') spec.homepage = "https://github.com/socketry/async-rspec" spec.files = Dir.glob(['{lib}/**/*', '*.md'], File::FNM_DOTMATCH, base: __dir__) spec.add_dependency "rspec", "~> 3.0" spec.add_dependency "rspec-files", "~> 1.0" spec.add_dependency "rspec-memory", "~> 1.0" spec.add_development_dependency "async" spec.add_development_dependency "bundler" spec.add_development_dependency "covered" end socketry-async-rspec-649783d/conduct.md000066400000000000000000000125611476166513600201010ustar00rootroot00000000000000 # Contributor Covenant Code of Conduct ## Our Pledge We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation. We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. ## Our Standards Examples of behavior that contributes to a positive environment for our community include: * Demonstrating empathy and kindness toward other people * Being respectful of differing opinions, viewpoints, and experiences * Giving and gracefully accepting constructive feedback * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience * Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: * The use of sexualized language or imagery, and sexual attention or advances of any kind * Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or email address, without their explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. ## Scope This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the reporter of any incident. ## Enforcement Guidelines Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: ### 1. Correction **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. ### 2. Warning **Community Impact**: A violation through a single incident or series of actions. **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. ### 3. Temporary Ban **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. ### 4. Permanent Ban **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. **Consequence**: A permanent ban from any sort of public interaction within the community. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations]. [homepage]: https://www.contributor-covenant.org [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html [Mozilla CoC]: https://github.com/mozilla/diversity [FAQ]: https://www.contributor-covenant.org/faq [translations]: https://www.contributor-covenant.org/translations socketry-async-rspec-649783d/gems.rb000066400000000000000000000005041476166513600173720ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2017-2023, by Samuel Williams. source 'https://rubygems.org' gemspec # gem "async", path: "../async" group :maintenance, optional: true do gem "bake-modernize" gem "bake-gem" gem "utopia-project" end group :test do gem "bake-test" end socketry-async-rspec-649783d/gems/000077500000000000000000000000001476166513600170465ustar00rootroot00000000000000socketry-async-rspec-649783d/gems/async-v1.rb000066400000000000000000000002701476166513600210330ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2021-2023, by Samuel Williams. source 'https://rubygems.org' gemspec path: "../" gem 'async', '~> 1.0' socketry-async-rspec-649783d/gems/async-v2.rb000066400000000000000000000002701476166513600210340ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2021-2023, by Samuel Williams. source 'https://rubygems.org' gemspec path: "../" gem 'async', '~> 2.0' socketry-async-rspec-649783d/lib/000077500000000000000000000000001476166513600166615ustar00rootroot00000000000000socketry-async-rspec-649783d/lib/async/000077500000000000000000000000001476166513600177765ustar00rootroot00000000000000socketry-async-rspec-649783d/lib/async/rspec.rb000066400000000000000000000003201476166513600214320ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2017-2023, by Samuel Williams. require_relative "rspec/version" require_relative "rspec/reactor" require_relative "rspec/memory" socketry-async-rspec-649783d/lib/async/rspec/000077500000000000000000000000001476166513600211125ustar00rootroot00000000000000socketry-async-rspec-649783d/lib/async/rspec/buffer.rb000066400000000000000000000011051476166513600227050ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2023, by Samuel Williams. require 'securerandom' module Async module RSpec module Buffer TMP = "/tmp" def self.open(mode = 'w+', root: TMP) path = File.join(root, SecureRandom.hex(32)) file = File.open(path, mode) File.unlink(path) return file unless block_given? begin yield file ensure file.close end end end ::RSpec.shared_context Buffer do let(:buffer) {Buffer.open} after(:each) {buffer.close} end end end socketry-async-rspec-649783d/lib/async/rspec/leaks.rb000066400000000000000000000003111476166513600225310ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2017-2023, by Samuel Williams. require 'rspec/files' module Async module RSpec Leaks = ::RSpec::Files::Leaks end end socketry-async-rspec-649783d/lib/async/rspec/memory.rb000066400000000000000000000003541476166513600227510ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2023, by Samuel Williams. # Copyright, 2018, by Janko Marohnić. require 'rspec/memory' module Async module RSpec Memory = ::RSpec::Memory end end socketry-async-rspec-649783d/lib/async/rspec/profile.rb000066400000000000000000000004341476166513600231000ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2017-2023, by Samuel Williams. module Async module RSpec module Profile end ::RSpec.shared_context Profile do before(:all) do warn "Profiling not enabled/supported." end end end end socketry-async-rspec-649783d/lib/async/rspec/reactor.rb000066400000000000000000000037551476166513600231100ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2017-2023, by Samuel Williams. # Copyright, 2023, by Robin Goos. require_relative 'leaks' require 'kernel/sync' require 'kernel/async' require 'async/reactor' require 'async/task' module Async module RSpec module Reactor def notify_failure(exception = $!) ::RSpec::Support.notify_failure(exception) end def run_in_reactor(reactor, duration = nil) result = nil timer_task = nil if duration timer_task = reactor.async do |task| # Wait for the timeout, at any point this task might be cancelled if the user code completes: task.annotate("Timer task duration=#{duration}.") task.sleep(duration) # The timeout expired, so generate an error: buffer = StringIO.new reactor.print_hierarchy(buffer) # Raise an error so it is logged: raise TimeoutError, "Run time exceeded duration #{duration}s:\n#{buffer.string}" end end spec_task = reactor.async do |spec_task| spec_task.annotate("running example") result = yield(spec_task) # We are finished, so stop the timer task if it was started: timer_task&.stop # Now stop the entire reactor: raise Async::Stop end begin timer_task&.wait spec_task.wait ensure spec_task.stop end return result end end ::RSpec.shared_context Reactor do include Reactor let(:reactor) {@reactor} # This is fiber local: rspec_context = Thread.current[:__rspec] include_context Async::RSpec::Leaks around(:each) do |example| duration = example.metadata.fetch(:timeout, 60) begin Sync do |task| @reactor = task.reactor task.annotate(self.class) run_in_reactor(@reactor, duration) do Thread.current[:__rspec] = rspec_context example.run end ensure @reactor = nil end end end end end end socketry-async-rspec-649783d/lib/async/rspec/ssl.rb000066400000000000000000000153341476166513600222460ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2023, by Samuel Williams. require 'openssl' module Async module RSpec module SSL module CertificateAuthority end module ValidCertificate end module InvalidCertificate end module VerifiedContexts end module HostCertificates end end ::RSpec.shared_context SSL::CertificateAuthority do # This key size is generally considered insecure, but it's fine for testing. let(:certificate_authority_key) {OpenSSL::PKey::RSA.new(2048)} let(:certificate_authority_name) {OpenSSL::X509::Name.parse("O=TestCA/CN=localhost")} # The certificate authority is used for signing and validating the certificate which is used for communciation: let(:certificate_authority) do certificate = OpenSSL::X509::Certificate.new certificate.subject = certificate_authority_name # We use the same issuer as the subject, which makes this certificate self-signed: certificate.issuer = certificate_authority_name certificate.public_key = certificate_authority_key.public_key certificate.serial = 1 certificate.version = 2 certificate.not_before = Time.now certificate.not_after = Time.now + 3600 extension_factory = OpenSSL::X509::ExtensionFactory.new extension_factory.subject_certificate = certificate extension_factory.issuer_certificate = certificate certificate.add_extension extension_factory.create_extension("basicConstraints", "CA:TRUE", true) certificate.add_extension extension_factory.create_extension("keyUsage", "keyCertSign, cRLSign", true) certificate.add_extension extension_factory.create_extension("subjectKeyIdentifier", "hash") certificate.add_extension extension_factory.create_extension("authorityKeyIdentifier", "keyid:always", false) certificate.sign certificate_authority_key, OpenSSL::Digest::SHA256.new end let(:certificate_store) do # The certificate store which is used for validating the server certificate: OpenSSL::X509::Store.new.tap do |certificates| certificates.add_cert(certificate_authority) end end end ::RSpec.shared_context SSL::ValidCertificate do include_context SSL::CertificateAuthority # The private key to use on the server side: let(:key) {OpenSSL::PKey::RSA.new(2048)} let(:certificate_name) {OpenSSL::X509::Name.parse("O=Test/CN=localhost")} # The certificate used for actual communication: let(:certificate) do certificate = OpenSSL::X509::Certificate.new certificate.subject = certificate_name certificate.issuer = certificate_authority.subject certificate.public_key = key.public_key certificate.serial = 2 certificate.version = 2 certificate.not_before = Time.now certificate.not_after = Time.now + 3600 extension_factory = OpenSSL::X509::ExtensionFactory.new() extension_factory.subject_certificate = certificate extension_factory.issuer_certificate = certificate_authority certificate.add_extension extension_factory.create_extension("keyUsage", "digitalSignature", true) certificate.add_extension extension_factory.create_extension("subjectKeyIdentifier", "hash") certificate.sign certificate_authority_key, OpenSSL::Digest::SHA256.new end end ::RSpec.shared_context SSL::HostCertificates do include_context SSL::CertificateAuthority let(:keys) do Hash[ hosts.collect{|name| [name, OpenSSL::PKey::RSA.new(2048)]} ] end # The certificate used for actual communication: let(:certificates) do Hash[ hosts.collect do |name| certificate_name = OpenSSL::X509::Name.parse("O=Test/CN=#{name}") certificate = OpenSSL::X509::Certificate.new certificate.subject = certificate_name certificate.issuer = certificate_authority.subject certificate.public_key = keys[name].public_key certificate.serial = 2 certificate.version = 2 certificate.not_before = Time.now certificate.not_after = Time.now + 3600 extension_factory = OpenSSL::X509::ExtensionFactory.new extension_factory.subject_certificate = certificate extension_factory.issuer_certificate = certificate_authority certificate.add_extension extension_factory.create_extension("keyUsage", "digitalSignature", true) certificate.add_extension extension_factory.create_extension("subjectKeyIdentifier", "hash") certificate.sign certificate_authority_key, OpenSSL::Digest::SHA256.new [name, certificate] end ] end let(:server_context) do OpenSSL::SSL::SSLContext.new.tap do |context| context.servername_cb = Proc.new do |socket, name| if hosts.include? name socket.hostname = name OpenSSL::SSL::SSLContext.new.tap do |context| context.cert = certificates[name] context.key = keys[name] end end end end end let(:client_context) do OpenSSL::SSL::SSLContext.new.tap do |context| context.cert_store = certificate_store context.verify_mode = OpenSSL::SSL::VERIFY_PEER end end end ::RSpec.shared_context SSL::InvalidCertificate do include_context SSL::CertificateAuthority # The private key to use on the server side: let(:key) {OpenSSL::PKey::RSA.new(2048)} let(:invalid_key) {OpenSSL::PKey::RSA.new(2048)} let(:certificate_name) {OpenSSL::X509::Name.parse("O=Test/CN=localhost")} # The certificate used for actual communication: let(:certificate) do certificate = OpenSSL::X509::Certificate.new certificate.subject = certificate_name certificate.issuer = certificate_authority.subject certificate.public_key = key.public_key certificate.serial = 2 certificate.version = 2 certificate.not_before = Time.now - 3600 certificate.not_after = Time.now extension_factory = OpenSSL::X509::ExtensionFactory.new() extension_factory.subject_certificate = certificate extension_factory.issuer_certificate = certificate_authority certificate.add_extension extension_factory.create_extension("keyUsage", "digitalSignature", true) certificate.add_extension extension_factory.create_extension("subjectKeyIdentifier", "hash") certificate.sign invalid_key, OpenSSL::Digest::SHA256.new end end ::RSpec.shared_context SSL::VerifiedContexts do let(:server_context) do OpenSSL::SSL::SSLContext.new.tap do |context| context.cert = certificate context.key = key end end let(:client_context) do OpenSSL::SSL::SSLContext.new.tap do |context| context.cert_store = certificate_store context.verify_mode = OpenSSL::SSL::VERIFY_PEER end end end end end socketry-async-rspec-649783d/lib/async/rspec/version.rb000066400000000000000000000002471476166513600231270ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2017-2023, by Samuel Williams. module Async module RSpec VERSION = "1.17.1" end end socketry-async-rspec-649783d/license.md000066400000000000000000000023661476166513600200660ustar00rootroot00000000000000# MIT License Copyright, 2017-2023, by Samuel Williams. Copyright, 2018, by Janko Marohnić. Copyright, 2019, by Jeremy Jung. Copyright, 2019, by Cyril Roelandt. Copyright, 2020-2021, by Olle Jonsson. Copyright, 2023, by Robin Goos. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. socketry-async-rspec-649783d/readme.md000066400000000000000000000047371476166513600177050ustar00rootroot00000000000000# Async::RSpec Provides useful `RSpec.shared_context`s for testing code that builds on top of [async](https://github.com/socketry/async). [![Development Status](https://github.com/socketry/async-rspec/workflows/Test/badge.svg)](https://github.com/socketry/async-rspec/actions?workflow=Test) ## Installation ``` shell $ bundle add async-rspec ``` Then add this require statement to the top of `spec/spec_helper.rb` ``` ruby require 'async/rspec' ``` ## Usage ### Async Reactor Many specs need to run within a reactor. A shared context is provided which includes all the relevant bits, including the above leaks checks. If your spec fails to run in less than 10 seconds, an `Async::TimeoutError` raises to prevent your test suite from hanging. ``` ruby require 'async/io' RSpec.describe Async::IO do include_context Async::RSpec::Reactor let(:pipe) {IO.pipe} let(:input) {Async::IO::Generic.new(pipe.first)} let(:output) {Async::IO::Generic.new(pipe.last)} it "should send and receive data within the same reactor" do message = nil output_task = reactor.async do message = input.read(1024) end reactor.async do output.write("Hello World") end output_task.wait expect(message).to be == "Hello World" input.close output.close end end ``` ### Changing Timeout You can change the timeout by specifying it as an option: ``` ruby RSpec.describe MySlowThing, timeout: 60 do # ... end ``` ### File Descriptor Leaks Leaking sockets and other kinds of IOs are a problem for long running services. `Async::RSpec::Leaks` tracks all open sockets both before and after the spec. If any are left open, a `RuntimeError` is raised and the spec fails. ``` ruby RSpec.describe "leaky ios" do include_context Async::RSpec::Leaks # The following fails: it "leaks io" do @input, @output = IO.pipe end end ``` In some cases, the Ruby garbage collector will close IOs. In the above case, it's possible that just writing `IO.pipe` will not leak as Ruby will garbage collect the resulting IOs immediately. It's still incorrect to not close IOs, so don't depend on this behaviour. ### Allocations This functionality was moved to [`rspec-memory`](https://github.com/socketry/rspec-memory). ## Contributing We welcome contributions to this project. 1. Fork it. 2. Create your feature branch (`git checkout -b my-new-feature`). 3. Commit your changes (`git commit -am 'Add some feature'`). 4. Push to the branch (`git push origin my-new-feature`). 5. Create new Pull Request. socketry-async-rspec-649783d/release.cert000066400000000000000000000033141476166513600204130ustar00rootroot00000000000000-----BEGIN CERTIFICATE----- MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11 ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2 9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/ c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp 8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8 voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg= -----END CERTIFICATE----- socketry-async-rspec-649783d/spec/000077500000000000000000000000001476166513600170455ustar00rootroot00000000000000socketry-async-rspec-649783d/spec/async/000077500000000000000000000000001476166513600201625ustar00rootroot00000000000000socketry-async-rspec-649783d/spec/async/rspec/000077500000000000000000000000001476166513600212765ustar00rootroot00000000000000socketry-async-rspec-649783d/spec/async/rspec/buffer_spec.rb000066400000000000000000000005771476166513600241170ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2023, by Samuel Williams. require 'async/rspec/buffer' RSpec.describe Async::RSpec::Buffer do include_context Async::RSpec::Buffer it "behaves like a file" do expect(buffer).to be_instance_of(File) end it "should not exist on disk" do expect(File).to_not be_exist(buffer.path) end end socketry-async-rspec-649783d/spec/async/rspec/leaks_spec.rb000066400000000000000000000006641476166513600237420ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2017-2023, by Samuel Williams. require 'async/rspec/leaks' RSpec.describe "leaks context" do include_context Async::RSpec::Leaks it "leaks io" do expect(before_ios).to be == current_ios input, output = IO.pipe expect(before_ios).to_not be == current_ios input.close output.close expect(before_ios).to be == current_ios end end socketry-async-rspec-649783d/spec/async/rspec/memory_spec.rb000066400000000000000000000041221476166513600241440ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2023, by Samuel Williams. # Copyright, 2018, by Janko Marohnić. require 'async/rspec/memory' RSpec.describe Async::RSpec::Memory do include_context Async::RSpec::Memory it "should execute code in block" do string = nil expect do string = String.new end.to limit_allocations(String => 1) expect(string).to_not be_nil end context "on supported platform", if: Async::RSpec::Memory::Trace.supported? do it "should not exceed specified count limit" do expect do 2.times{String.new} end.to limit_allocations(String => 2) expect do 2.times{String.new} end.to limit_allocations.of(String, count: 2) end it "should fail if there are untracked allocations" do expect do expect do Array.new end.to limit_allocations end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /it was not specified/) end it "should exceed specified count limit" do expect do expect do 6.times{String.new} end.to limit_allocations(String => 4) end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /expected exactly 4 instances/) end if Async::RSpec::Memory::Trace.supported? it "should be within specified count range" do expect do 2.times{String.new} end.to limit_allocations(String => 1..3) expect do 2.times{String.new} end.to limit_allocations.of(String, count: 1..3) end it "should exceed specified count range" do expect do expect do 6.times{String.new} end.to limit_allocations(String => 1..3) end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /expected within 1..3 instances/) end it "should not exceed specified size limit" do expect do "a" * 100_000 end.to limit_allocations.of(String, size: 100_001) end it "should exceed specified size limit" do expect do expect do "a" * 120_000 end.to limit_allocations(size: 100_000) end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /expected exactly 100000 bytes/) end end end socketry-async-rspec-649783d/spec/async/rspec/profile_spec.rb000066400000000000000000000005431476166513600242770ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2017-2023, by Samuel Williams. require 'async' require 'async/rspec/profile' RSpec.describe Async::RSpec::Profile do include_context Async::RSpec::Profile it "profiles the function" do Async do |parent| Async do |child| child.sleep(1) end.wait end end end socketry-async-rspec-649783d/spec/async/rspec/reactor_spec.rb000066400000000000000000000031771476166513600243040ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2017-2023, by Samuel Williams. # Copyright, 2023, by Robin Goos. require 'async/rspec/reactor' RSpec.describe Async::RSpec::Reactor do context "with shared context", timeout: 1 do include_context Async::RSpec::Reactor # The following fails: it "has reactor" do expect(reactor).to be_kind_of Async::Reactor end it "doesn't time out" do reactor.async do |task| expect do task.sleep(0.1) end.to_not raise_error end.wait end # it "times out" do # reactor.async do |task| # task.sleep(2) # end.wait # end # # it "propagates errors" do # reactor.async do |task| # raise "Boom!" # end.wait # end end context "timeouts", timeout: 1 do include Async::RSpec::Reactor it "times out" do expect do Sync do |task| run_in_reactor(task.reactor, 0.05) do |spec_task| spec_task.sleep(0.1) end end end.to raise_error(Async::TimeoutError) end it "doesn't time out" do expect do Sync do |task| run_in_reactor(task.reactor, 0.05) do |spec_task| spec_task.sleep(0.01) end end end.to_not raise_error end # it "propagates errors" do # expect do # run_in_reactor(reactor, 0.05) do # raise "Boom!" # end # end.to raise_error("Boom!") # end end context "rspec metadata", timeout: 1 do include_context Async::RSpec::Reactor it "should have access to example metadata" do expect(RSpec.current_example).not_to be_nil expect(RSpec.current_example.metadata[:described_class]).to eq(Async::RSpec::Reactor) end end end socketry-async-rspec-649783d/spec/async/rspec/ssl_spec.rb000066400000000000000000000015471476166513600234450ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2023, by Samuel Williams. require 'async/rspec/ssl' RSpec.describe Async::RSpec::SSL do context Async::RSpec::SSL::CertificateAuthority do include_context Async::RSpec::SSL::CertificateAuthority it "has a valid certificate authority" do expect(certificate_authority.verify(certificate_authority_key)).to be_truthy end end context Async::RSpec::SSL::ValidCertificate do include_context Async::RSpec::SSL::ValidCertificate it "can validate client certificate" do expect(certificate_store.verify(certificate)).to be_truthy end end context Async::RSpec::SSL::InvalidCertificate do include_context Async::RSpec::SSL::InvalidCertificate it "fails to validate certificate" do expect(certificate_store.verify(certificate)).to be_falsey end end end socketry-async-rspec-649783d/spec/spec_helper.rb000066400000000000000000000006771476166513600216750ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2017-2023, by Samuel Williams. require 'covered/rspec' RSpec.configure do |config| # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = ".rspec_status" # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! config.expect_with :rspec do |c| c.syntax = :expect end end