README.md in dns_mock-1.0.0 vs README.md in dns_mock-1.1.0
- old
+ new
@@ -14,10 +14,11 @@
- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
+ - [RSpec](#rspec)
- [Contributing](#contributing)
- [License](#license)
- [Code of Conduct](#code-of-conduct)
- [Credits](#credits)
- [Versioning](#versioning)
@@ -106,9 +107,71 @@
# returns list of running dns mock servers
DnsMock.running_servers # => [DnsMock::Server instance]
# interface to stop all running dns mock servers
DnsMock.stop_running_servers! # => true
+```
+
+### RSpec
+
+Require this either in your Gemfile or in RSpec's support scripts. So either:
+
+```ruby
+# Gemfile
+group :test do
+ gem 'rspec'
+ gem 'dns_mock', require: 'dns_mock/test_framework/rspec'
+end
+```
+
+or
+
+```ruby
+# spec/support/config/dns_mock.rb
+require 'dns_mock/test_framework/rspec'
+```
+
+#### DnsMock RSpec helper
+
+Just add `DnsMock::TestFramework::RSpec::Helper` if you wanna have shortcut for DnsMock server instance into your RSpec.describe blocks:
+
+```ruby
+# spec/support/config/dns_mock.rb
+RSpec.configure do |config|
+ config.include DnsMock::TestFramework::RSpec::Helper
+end
+```
+
+```ruby
+# your awesome first_a_record_spec.rb
+RSpec.describe FirstARecord do
+ subject(:service) do
+ described_class.call(
+ hostname,
+ dns_gateway_host: 'localhost',
+ dns_gateway_port: dns_mock_server.port
+ )
+ end
+
+ let(:hostname) { 'example.com' }
+ let(:first_a_record) { '1.2.3.4' }
+ let(:records) { { hostname => { a: [first_a_record] } } }
+
+ before { dns_mock_server.assign_mocks(records) }
+
+ it { is_expected.to eq(first_a_record) }
+end
+```
+
+#### DnsMock RSpec interface
+
+If you won't use `DnsMock::TestFramework::RSpec::Helper` you can use `DnsMock::TestFramework::RSpec::Interface` directly instead:
+
+```ruby
+DnsMock::TestFramework::RSpec::Interface.start_server # creates and runs DnsMock server instance
+DnsMock::TestFramework::RSpec::Interface.stop_server! # stops current DnsMock server instance
+DnsMock::TestFramework::RSpec::Interface.reset_mocks! # resets mocks in current DnsMock server instance
+DnsMock::TestFramework::RSpec::Interface.clear_server! # stops and clears current DnsMock server instance
```
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/mocktools/ruby-dns-mock. 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 tikets](https://github.com/mocktools/ruby-dns-mock/issues). Be shure to follow Contributor Code of Conduct below and our [Contributing Guidelines](CONTRIBUTING.md).