Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Replace validator middlware stack with Cop plugins #131

Merged
merged 11 commits into from
Jul 3, 2014
Merged

Replace validator middlware stack with Cop plugins #131

merged 11 commits into from
Jul 3, 2014

Conversation

maxlinc
Copy link
Collaborator

@maxlinc maxlinc commented Jul 2, 2014

This replaces the validator middleware with a much better, more extensible "Cop" system.

A cop investigates that a request/response complies with a contract. A custom cop could also check for organizational conventions that are outside of the contract (e.g. security requirements). A cop issues citations. The samples/cops.rb code shows a custom cop:

class MyCustomCop
  def investigate(_request, _response, contract)
    citations = []
    citations << 'Contract must have a request schema' if contract.request.schema.empty?
    citations << 'Contract must have a response schema' if contract.response.schema.empty?
    citations
  end
end

Pacto::Cops.active_cops << MyCustomCop.new

Obsoletes #91, because there is no more "body_only" feature. Instead, you can set the active cops to only include Pacto::Cops::RequestBodyCop and/or Pacto::Cops::ResponseBodyCop.

I am planning to rename rspec matchers and rake tasks to go with investigate rather than validate when it makes sense, but I'm going to do that as a separate PR since it is a bigger breaking change while this is (more) internal.

@coveralls
Copy link

Coverage Status

Coverage decreased (-4.75%) when pulling 33cb8d4 on cops into 5ed62aa on master.

maxlinc added a commit that referenced this pull request Jul 3, 2014
Replace validator middleware stack with Cop plugins
Obsoletes #91 (no more "body_only" option, but you can change the active cops to only include body validators)
@maxlinc maxlinc merged commit d044549 into master Jul 3, 2014
@maxlinc maxlinc deleted the cops branch July 3, 2014 19:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants