-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "spec2" | ||
require "http/client/response" | ||
|
||
struct RedirectToMatcher | ||
include Spec2::Matcher | ||
|
||
getter expected : String | ||
getter actual : String? | ||
|
||
def initialize(@expected : String) | ||
end | ||
|
||
def match(response : HTTP::Client::Response?) | ||
@actual = response.try &.headers["Location"]? | ||
@expected == @actual && response.try &.status_code >= 300 | ||
end | ||
|
||
def failure_message | ||
<<-MSG | ||
bad redirect | ||
\t\t expected to redirect to: "#{expected}" | ||
\t\t but redirects to: "#{actual}" | ||
MSG | ||
end | ||
|
||
def failure_message_when_negated | ||
<<-MSG | ||
bad redirect | ||
\t\t expected not to redirect to: "#{expected}" | ||
\t\t but redirects to: "#{actual}" | ||
MSG | ||
end | ||
|
||
def description | ||
"(should redirect to #{expected_to})" | ||
end | ||
end | ||
|
||
Spec2.register_matcher redirect_to do |url| | ||
RedirectToMatcher.new url | ||
end |