No commit activity in last 3 years
No release in over 3 years
Manage and convert Pact expectations to stubs for Remote Facade.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
>= 1.9
~> 10.0
~> 3.0

Runtime

>= 0.5.4
 Project Readme

Build Status

PactExpectations

Pact response convert to stub.

Installation

Add this line to your application's Gemfile:

gem 'pact_expectations'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pact_expectations

Usage

for example

class APIClient
  def item(id)
    # Sending api request
  end
end

PactExpectations.add_response_body_for(
  "a request for an item",
  Pact.like(
    id: 1,
    name: "pen",
  ),
)

## CDC testing with Pact
describe APIClient, pact: true do
  describe "#item" do
      before do
        api
          .given("an item exists")
          .upon_receiving("a request for an item")
          .with(method: :get, path: "/item/1")
          .will_respond_with(
            status: 200,
            body: PactExpectations.response_body_for("a request for an item"),
          )
      end
      it { expect(APIClient.item(1).name).to eq "pen" }
    end
  end
end

## Stub Remote Facade's method
describe ItemsController do
  describe "show" do
    before do
      allow(APIClient).to(
        receive(:item).with(1).and_return(PactExpectations.reified_body_for("a request for an item"))
      )
    end
    it do
      get :show, id: 1
      expect(assigns[:item].name).to eq "pen"
    end
  end
end

Verify expectation was called.

RSpec.configure do |config|
  config.after(:suite) do
    PactExpectations.verify if ENV["PACT_VERIFY_EXPECTATIONS"] == "1"
  end
end

Development

After checking out the repo, run bundle install to install dependencies. Then, run rake spec to run the tests.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/yoshiori/pact_expectations.

Special Thanks

Taiki Ono gave me a lot of advice.