Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from dsalahutdinov/feature/more_rspec_matchers
feature: add response chunks rspec matchers
- Loading branch information
Showing
8 changed files
with
91 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'base' | ||
|
||
module Logux | ||
module Test | ||
module Matchers | ||
class ResponseChunks < Base | ||
attr_reader :includes, :excludes, :meta | ||
|
||
def initialize(meta:, includes:, excludes: []) | ||
@meta = meta | ||
@includes = includes | ||
@excludes = excludes | ||
end | ||
|
||
def matches?(actual) | ||
@actual = JSON.parse(actual.body) | ||
|
||
match_includes? && match_excludes? | ||
end | ||
|
||
def failure_message | ||
data = "expected that #{pretty(@actual)} to has " \ | ||
"#{includes.join(', ')} chunks" | ||
!excludes.empty? && data += " and doesn't" \ | ||
" has #{excludes.join(', ')} chunks" | ||
data | ||
end | ||
|
||
private | ||
|
||
def match_includes? | ||
@actual.any? do |command| | ||
command.first.in?(includes) && | ||
(meta.nil? || (meta.present? && command[1] == meta)) | ||
end | ||
end | ||
|
||
def match_excludes? | ||
@actual.empty? || @actual.none? do |command| | ||
command.first.in?(excludes) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters