{"id":13521248,"url":"https://github.com/mocktools/ruby-dns-mock","last_synced_at":"2025-04-04T16:16:57.788Z","repository":{"id":40247126,"uuid":"323097031","full_name":"mocktools/ruby-dns-mock","owner":"mocktools","description":"DNS mock server written on 💎 Ruby. Mimic any DNS records for your test environment with fake DNS server.","archived":false,"fork":false,"pushed_at":"2024-12-25T19:38:24.000Z","size":258,"stargazers_count":65,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T15:11:19.672Z","etag":null,"topics":["developer-tools","dns","dns-mock","dns-server","fake-dns","fake-server","hacktoberfest","mock","mock-server","mocktools","rspec","ruby","testing","testing-tools"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mocktools.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["bestwebua"]}},"created_at":"2020-12-20T14:59:24.000Z","updated_at":"2025-03-18T21:49:02.000Z","dependencies_parsed_at":"2023-02-14T17:01:35.713Z","dependency_job_id":"912797a3-141b-4858-a967-cf52ca271259","html_url":"https://github.com/mocktools/ruby-dns-mock","commit_stats":{"total_commits":102,"total_committers":1,"mean_commits":102.0,"dds":0.0,"last_synced_commit":"9188bd097d376c53df292816ed3c31638b6e4ed0"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mocktools%2Fruby-dns-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mocktools%2Fruby-dns-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mocktools%2Fruby-dns-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mocktools%2Fruby-dns-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mocktools","download_url":"https://codeload.github.com/mocktools/ruby-dns-mock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208190,"owners_count":20901570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["developer-tools","dns","dns-mock","dns-server","fake-dns","fake-server","hacktoberfest","mock","mock-server","mocktools","rspec","ruby","testing","testing-tools"],"created_at":"2024-08-01T06:00:31.527Z","updated_at":"2025-04-04T16:16:57.769Z","avatar_url":"https://github.com/mocktools.png","language":"Ruby","funding_links":["https://github.com/sponsors/bestwebua"],"categories":["Testing","Mocks"],"sub_categories":[],"readme":"# ![Ruby DnsMock - mimic any DNS records for your test environment and even more!](https://repository-images.githubusercontent.com/323097031/ba2a0780-df26-11eb-954b-5e3204587eb2)\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/5ea9da61ef468b8ad4c4/maintainability)](https://codeclimate.com/github/mocktools/ruby-dns-mock/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/5ea9da61ef468b8ad4c4/test_coverage)](https://codeclimate.com/github/mocktools/ruby-dns-mock/test_coverage)\n[![CircleCI](https://circleci.com/gh/mocktools/ruby-dns-mock/tree/master.svg?style=svg)](https://circleci.com/gh/mocktools/ruby-dns-mock/tree/master)\n[![Gem Version](https://badge.fury.io/rb/dns_mock.svg)](https://badge.fury.io/rb/dns_mock)\n[![Downloads](https://img.shields.io/gem/dt/dns_mock.svg?colorA=004d99\u0026colorB=0073e6)](https://rubygems.org/gems/dns_mock)\n[![In Awesome Ruby](https://raw.githubusercontent.com/sindresorhus/awesome/main/media/mentioned-badge.svg)](https://github.com/markets/awesome-ruby)\n[![GitHub](https://img.shields.io/github/license/mocktools/ruby-dns-mock)](LICENSE.txt)\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)\n\n💎 Ruby DNS mock. Mimic any DNS records for your test environment and even more.\n\n## Table of Contents\n\n- [Features](#features)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [RSpec](#rspec)\n    - [DnsMock RSpec helper](#dnsmock-rspec-helper)\n    - [DnsMock RSpec interface](#dnsmock-rspec-interface)\n- [Contributing](#contributing)\n- [License](#license)\n- [Code of Conduct](#code-of-conduct)\n- [Credits](#credits)\n- [Versioning](#versioning)\n- [Changelog](CHANGELOG.md)\n\n## Features\n\n- Ability to mimic any DNS records (`A`, `AAAA`, `CNAME`, `MX`, `NS`, `PTR`, `SOA`, `SRV` and `TXT`)\n- Automatically converts host names to RDNS/[Punycode](https://en.wikipedia.org/wiki/Punycode) representation\n- Lightweight UDP DNS mock server with dynamic/manual port assignment\n- Test framework agnostic (it's PORO, so you can use it outside of `RSpec`, `Test::Unit` or `MiniTest`)\n- Simple and intuitive DSL\n- Only one runtime dependency\n\n## Requirements\n\nRuby MRI 2.5.0+\n\n## Installation\n\nAdd this line to your application's `Gemfile`:\n\n```ruby\ngroup :development, :test do\n  gem 'dns_mock', require: false\nend\n```\n\nAnd then execute:\n\n```bash\nbundle\n```\n\nOr install it yourself as:\n\n```bash\ngem install dns_mock\n```\n\n## Usage\n\n```ruby\n# Example of mocked DNS records, please follow this data structure\n\nrecords = {\n  'example.com' =\u003e {\n    a: %w[1.1.1.1 2.2.2.2],\n    aaaa: %w[2a00:1450:4001:81e::200e],\n    ns: %w[ns1.domain.com ns2.domain.com],\n    mx: %w[mx1.domain.com mx2.domain.com:50], # you can specify host(s) or host(s) with priority, use '.:0' for definition null MX record\n    txt: %w[txt_record_1 txt_record_2],\n    cname: 'mañana.com', # you can specify hostname in UTF-8. It will be converted to xn--maana-pta.com automatically\n    soa: [\n      {\n        mname: 'dns1.domain.com',\n        rname: 'dns2.domain.com',\n        serial: 2_035_971_683,\n        refresh: 10_000,\n        retry: 2_400,\n        expire: 604_800,\n        minimum: 3_600\n      }\n    ]\n  },\n  '1.2.3.4' =\u003e { # You can define RDNS host address without lookup prefix. It will be converted to 4.3.2.1.in-addr.arpa automatically\n    ptr: %w[domain_1.com domain_2.com]\n  },\n  '_sip._tcp.example.com' =\u003e { # Please use {_service._proto.domain} pattern to follow the valid RFC-2782 SRV host pattern representation\n    srv: [\n      {\n        priority: 0,\n        weight: 10,\n        port: 5_060,\n        target: 'domain.com'\n      }\n    ]\n  }\n}\n\n# Public DnsMock interface\n# records:Hash, port:Integer, exception_if_not_found:Boolean\n# are optional params. By default creates dns mock server with\n# empty records. A free port for server will be randomly assigned\n# in the range from 49152 to 65535, if record not found exception\n# won't raises. Please note if you specify zero port number,\n# free port number will be randomly assigned as a server port too.\n# Returns current dns mock server\ndns_mock_server = DnsMock.start_server(records: records) # =\u003e DnsMock::Server instance\n\n# returns current dns mock server port\ndns_mock_server.port # =\u003e 49322\n\n# returns current collected server lookup messsages\n# represented as array of Resolv::DNS::Message instances\ndns_mock_server.messages # =\u003e [#\u003cResolv::DNS::Message\u003e]\n\n# interface to setup mock records.\n# Available only in case when server mocked records is empty\ndns_mock_server.assign_mocks(records) # =\u003e true/nil\n\n# interface to reset current mocked records\ndns_mock_server.reset_mocks! # =\u003e true\n\n# interface to clear collected lookup messages\ndns_mock_server.clear_messages! # =\u003e true\n\n# interface to stop current dns mock server\ndns_mock_server.stop! # =\u003e true\n\n# returns list of running dns mock servers\nDnsMock.running_servers # =\u003e [DnsMock::Server instance]\n\n# interface to stop all running dns mock servers\nDnsMock.stop_running_servers! # =\u003e true\n```\n\n### RSpec\n\nRequire this either in your Gemfile or in RSpec's support scripts. So either:\n\n```ruby\n# Gemfile\n\ngroup :test do\n  gem 'rspec'\n  gem 'dns_mock', require: 'dns_mock/test_framework/rspec'\nend\n```\n\nor\n\n```ruby\n# spec/support/config/dns_mock.rb\n\nrequire 'dns_mock/test_framework/rspec'\n```\n\n#### DnsMock RSpec helper\n\nJust add `DnsMock::TestFramework::RSpec::Helper` if you wanna use shortcut `dns_mock_server` for DnsMock server instance inside of your `RSpec.describe` blocks:\n\n```ruby\n# spec/support/config/dns_mock.rb\n\nRSpec.configure do |config|\n  config.include DnsMock::TestFramework::RSpec::Helper\nend\n```\n\n```ruby\n# Your awesome first_a_record_spec.rb\n\nRSpec.describe FirstARecord do\n  subject(:service) do\n    described_class.call(\n      hostname,\n      dns_gateway_host: 'localhost',\n      dns_gateway_port: dns_mock_server.port\n    )\n  end\n\n  let(:hostname) { 'example.com' }\n  let(:first_a_record) { '1.2.3.4' }\n  let(:records) { { hostname =\u003e { a: [first_a_record] } } }\n\n  before { dns_mock_server.assign_mocks(records) }\n\n  it { is_expected.to eq(first_a_record) }\nend\n```\n\n#### DnsMock RSpec interface\n\nIf you won't use `DnsMock::TestFramework::RSpec::Helper` you can use `DnsMock::TestFramework::RSpec::Interface` directly instead:\n\n```ruby\nDnsMock::TestFramework::RSpec::Interface.start_server    # creates and runs DnsMock server instance\nDnsMock::TestFramework::RSpec::Interface.stop_server!    # stops current DnsMock server instance\nDnsMock::TestFramework::RSpec::Interface.reset_mocks!    # resets mocks in current DnsMock server instance\nDnsMock::TestFramework::RSpec::Interface.clear_server!   # stops and clears current DnsMock server instance\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at \u003chttps://github.com/mocktools/ruby-dns-mock\u003e. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. Please check the [open tickets](https://github.com/mocktools/ruby-dns-mock/issues). Be sure to follow Contributor Code of Conduct below and our [Contributing Guidelines](CONTRIBUTING.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the DnsMock project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).\n\n## Credits\n\n- [The Contributors](https://github.com/mocktools/ruby-dns-mock/graphs/contributors) for code and awesome suggestions\n- [The Stargazers](https://github.com/mocktools/ruby-dns-mock/stargazers) for showing their support\n\n## Versioning\n\nDnsMock uses [Semantic Versioning 2.0.0](https://semver.org)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmocktools%2Fruby-dns-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmocktools%2Fruby-dns-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmocktools%2Fruby-dns-mock/lists"}