umts-custom-matchers 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE.txt +1 -1
- data/README.md +64 -15
- data/lib/umts_custom_matchers.rb +10 -0
- data/lib/umts_custom_matchers/redirect_back.rb +128 -0
- data/lib/umts_custom_matchers/version.rb +5 -0
- metadata +19 -21
- data/.gitignore +0 -9
- data/.rspec +0 -2
- data/.rubocop.yml +0 -10
- data/.travis.yml +0 -12
- data/Gemfile +0 -4
- data/Rakefile +0 -8
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/umts-custom-matchers.rb +0 -3
- data/lib/umts-custom-matchers/redirect_back.rb +0 -30
- data/lib/umts-custom-matchers/version.rb +0 -3
- data/umts-custom-matchers.gemspec +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c882162c2ba6dcf128603574b4e02c5a09fdd46fe38beda2d29f8b42a4858e81
|
4
|
+
data.tar.gz: 93786143d1e726ef5742382d3eee172a9b750e562fc8dc8660be541ce1448f93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4f01c0ceadb6ce32545022b21ee925c4ec144d95d739b860b1144ea4bd4ba7ff10839aea5991d3eefa75c74957dfba36c6abe095955e9b5c1f74f9a83b7022c
|
7
|
+
data.tar.gz: 38467a95ae068a0b1afeb59758f12b2d78cb6648099628255080fe7d333a1602c86370bac1a5ecee618ebe5bf48f668f7c3f83de047a7333a80432529c1106e0
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2020 UMass Transportation Services
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -1,10 +1,20 @@
|
|
1
|
-
|
1
|
+
UmtsCustomMatchers
|
2
|
+
==================
|
2
3
|
|
3
|
-
Custom RSpec Rails-related matchers, used for UMass Transit's internal Rails
|
4
|
+
Custom RSpec Rails-related matchers, used for UMass Transit's internal Rails
|
5
|
+
development process.
|
4
6
|
|
5
|
-
|
7
|
+
Much of the inspiration for these solutions came from inspection of the
|
8
|
+
rspec-rails source code, so thanks to the rspec-rails team for making their
|
9
|
+
source code public.
|
6
10
|
|
7
|
-
|
11
|
+
[![Build Status][travis-badge]][travis-link]
|
12
|
+
[![Test Coverage][cc-coverage-badge]][cc-coverage-link]
|
13
|
+
[![Code Climate][cc-badge]][cc-link]
|
14
|
+
[![Issue Count][cc-issue-badge]][cc-issue-link]
|
15
|
+
|
16
|
+
Installation
|
17
|
+
------------
|
8
18
|
|
9
19
|
Add this line to your application's Gemfile:
|
10
20
|
|
@@ -14,27 +24,66 @@ gem 'umts-custom-matchers'
|
|
14
24
|
|
15
25
|
And then execute:
|
16
26
|
|
17
|
-
|
27
|
+
```
|
28
|
+
$ bundle
|
29
|
+
```
|
18
30
|
|
19
31
|
Or install it yourself as:
|
20
32
|
|
21
|
-
|
33
|
+
```
|
34
|
+
$ gem install umts-custom-matchers
|
35
|
+
```
|
36
|
+
|
37
|
+
Usage
|
38
|
+
-----
|
39
|
+
|
40
|
+
Require the matchers in your RSpec configuration file:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'umts_custom_matchers'
|
44
|
+
```
|
45
|
+
|
46
|
+
And include them:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
RSpec.configure do |config|
|
50
|
+
# ...
|
51
|
+
config.include UmtsCustomMatchers
|
52
|
+
end
|
53
|
+
```
|
22
54
|
|
23
|
-
|
55
|
+
Development
|
56
|
+
-----------
|
24
57
|
|
25
|
-
|
58
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
59
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
60
|
+
prompt that will allow you to experiment.
|
26
61
|
|
27
|
-
|
62
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
63
|
+
release a new version, update the version number in `version.rb`, and then run
|
64
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
65
|
+
git commits and tags, and push the `.gem` file to [rubygems.org][rg].
|
28
66
|
|
29
|
-
|
67
|
+
Contributing
|
68
|
+
------------
|
30
69
|
|
31
|
-
|
70
|
+
Bug reports and pull requests are welcome on GitHub at
|
71
|
+
https://github.com/umts/custom-matchers.
|
32
72
|
|
33
|
-
## Contributing
|
34
73
|
|
35
|
-
|
74
|
+
License
|
75
|
+
-------
|
36
76
|
|
77
|
+
The gem is available as open source under the terms of the [MIT License][lic].
|
37
78
|
|
38
|
-
|
79
|
+
[travis-badge]: https://travis-ci.org/umts/custom-matchers.svg?branch=master
|
80
|
+
[travis-link]: https://travis-ci.org/umts/custom-matchers
|
81
|
+
[cc-coverage-badge]: https://codeclimate.com/github/umts/custom-matchers/badges/coverage.svg
|
82
|
+
[cc-coverage-link]: https://codeclimate.com/github/umts/custom-matchers/coverage
|
83
|
+
[cc-badge]: https://codeclimate.com/github/umts/custom-matchers/badges/gpa.svg
|
84
|
+
[cc-link]: https://codeclimate.com/github/umts/custom-matchers
|
85
|
+
[cc-issue-badge]: https://codeclimate.com/github/umts/custom-matchers/badges/issue_count.svg
|
86
|
+
[cc-issue-link]: https://codeclimate.com/github/umts/custom-matchers
|
39
87
|
|
40
|
-
|
88
|
+
[rg]: https://rubygems.org
|
89
|
+
[lic]: http://opensource.org/licenses/MIT
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'action_controller'
|
4
|
+
require 'action_controller/test_case'
|
5
|
+
require 'rspec/rails/matchers'
|
6
|
+
|
7
|
+
##
|
8
|
+
#:nodoc:
|
9
|
+
module UmtsCustomMatchers
|
10
|
+
##
|
11
|
+
# Matcher for redirecting to "back". Asserts that the HTTP response code is
|
12
|
+
# a redirect, and also that the `Location` matches the HTTP_REFERER of the
|
13
|
+
# request.
|
14
|
+
class RedirectBack
|
15
|
+
MATCHER_MODULE = RSpec::Rails::Matchers
|
16
|
+
STATUS_CODE_MATCHER = MATCHER_MODULE::HaveHttpStatus::GenericStatus
|
17
|
+
REDIRECT_PATH_MATCHER = MATCHER_MODULE::RedirectTo::RedirectTo
|
18
|
+
|
19
|
+
ALLOWED_REQUEST_TYPES = [ActionController::TestRequest].freeze
|
20
|
+
ALLOWED_RESPONSE_TYPES = [ActionDispatch::TestResponse].freeze
|
21
|
+
|
22
|
+
def initialize(scope)
|
23
|
+
@scope = scope
|
24
|
+
end
|
25
|
+
|
26
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
27
|
+
# rubocop:disable Metrics/MethodLength
|
28
|
+
|
29
|
+
##
|
30
|
+
# Returns `true` if response is a `302`, and the location matches the `HTTP_REFERER`
|
31
|
+
# of the request. `false` otherwise.
|
32
|
+
def matches?(code)
|
33
|
+
path = 'http://test.host/redirect'
|
34
|
+
status_matcher = STATUS_CODE_MATCHER.new :redirect
|
35
|
+
path_matcher = REDIRECT_PATH_MATCHER.new @scope, path
|
36
|
+
|
37
|
+
verify_spec_type or return false
|
38
|
+
verify_request_type or return false
|
39
|
+
verify_response_type or return false
|
40
|
+
verify_input_type(code) or return false
|
41
|
+
|
42
|
+
@scope.request.env['HTTP_REFERER'] ||= path
|
43
|
+
code.call
|
44
|
+
@response = @scope.response
|
45
|
+
|
46
|
+
verify_status_code(status_matcher) or return false
|
47
|
+
verify_redirect_path(path_matcher) or return false
|
48
|
+
|
49
|
+
true
|
50
|
+
end
|
51
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
52
|
+
# rubocop:enable Metrics/MethodLength
|
53
|
+
|
54
|
+
##
|
55
|
+
#:nodoc:
|
56
|
+
def failure_message
|
57
|
+
@message
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
#:nodoc:
|
62
|
+
def failure_message_when_negated
|
63
|
+
'expected response not to redirect back, but did'
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
#:nodoc:
|
68
|
+
def supports_block_expectations?
|
69
|
+
true
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def verify_input_type(input)
|
75
|
+
return true if input.is_a? Proc
|
76
|
+
|
77
|
+
@message =
|
78
|
+
"expected block argument, but received #{input.class}"
|
79
|
+
false
|
80
|
+
end
|
81
|
+
|
82
|
+
def verify_redirect_path(matcher)
|
83
|
+
return true if matcher.matches? @response
|
84
|
+
|
85
|
+
@message = matcher.failure_message
|
86
|
+
false
|
87
|
+
end
|
88
|
+
|
89
|
+
def verify_request_type
|
90
|
+
return true if ALLOWED_REQUEST_TYPES.include? @scope.request.class
|
91
|
+
|
92
|
+
@message = "expected test request to be one of: \
|
93
|
+
#{ALLOWED_REQUEST_TYPES.join ', '}; \
|
94
|
+
but was #{@scope.request.class}"
|
95
|
+
false
|
96
|
+
end
|
97
|
+
|
98
|
+
def verify_response_type
|
99
|
+
return true if ALLOWED_RESPONSE_TYPES.include? @scope.response.class
|
100
|
+
|
101
|
+
@message = "expected test response to be one of: \
|
102
|
+
#{ALLOWED_RESPONSE_TYPES.join ', '}; \
|
103
|
+
but was #{@scope.response.class}"
|
104
|
+
false
|
105
|
+
end
|
106
|
+
|
107
|
+
def verify_spec_type
|
108
|
+
return true if @scope.respond_to?(:request) && @scope.respond_to?(:response)
|
109
|
+
|
110
|
+
@message = 'The redirect_back matcher is only valid for controller specs.'
|
111
|
+
false
|
112
|
+
end
|
113
|
+
|
114
|
+
def verify_status_code(matcher)
|
115
|
+
return true if matcher.matches? @response
|
116
|
+
|
117
|
+
@message = matcher.failure_message
|
118
|
+
false
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
##
|
123
|
+
# Wrapper method for `RedirectBack` can be used in examples if `UmtsCustomMatchers`
|
124
|
+
# is incuded.
|
125
|
+
def redirect_back
|
126
|
+
RedirectBack.new self
|
127
|
+
end
|
128
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umts-custom-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- UMass Transit Services
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
+
- - "<="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '3.0'
|
30
|
+
- - "<="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: bundler
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,26 +121,19 @@ executables: []
|
|
115
121
|
extensions: []
|
116
122
|
extra_rdoc_files: []
|
117
123
|
files:
|
118
|
-
- ".gitignore"
|
119
|
-
- ".rspec"
|
120
|
-
- ".rubocop.yml"
|
121
|
-
- ".travis.yml"
|
122
|
-
- Gemfile
|
123
124
|
- LICENSE.txt
|
124
125
|
- README.md
|
125
|
-
-
|
126
|
-
-
|
127
|
-
-
|
128
|
-
- lib/umts-custom-matchers.rb
|
129
|
-
- lib/umts-custom-matchers/redirect_back.rb
|
130
|
-
- lib/umts-custom-matchers/version.rb
|
131
|
-
- umts-custom-matchers.gemspec
|
126
|
+
- lib/umts_custom_matchers.rb
|
127
|
+
- lib/umts_custom_matchers/redirect_back.rb
|
128
|
+
- lib/umts_custom_matchers/version.rb
|
132
129
|
homepage: https://github.com/umts/custom-matchers
|
133
130
|
licenses:
|
134
131
|
- MIT
|
135
132
|
metadata:
|
136
133
|
allowed_push_host: https://rubygems.org
|
137
|
-
post_install_message:
|
134
|
+
post_install_message: The require location of this gem's libraries has been changed
|
135
|
+
to reflect better ruby conventions. Change any instance of `require 'umts-custom-matchers'
|
136
|
+
to `require 'umts_custom_matchers'
|
138
137
|
rdoc_options: []
|
139
138
|
require_paths:
|
140
139
|
- lib
|
@@ -142,15 +141,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
141
|
requirements:
|
143
142
|
- - ">="
|
144
143
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
144
|
+
version: '2.4'
|
146
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
146
|
requirements:
|
148
147
|
- - ">="
|
149
148
|
- !ruby/object:Gem::Version
|
150
149
|
version: '0'
|
151
150
|
requirements: []
|
152
|
-
|
153
|
-
rubygems_version: 2.4.8
|
151
|
+
rubygems_version: 3.0.1
|
154
152
|
signing_key:
|
155
153
|
specification_version: 4
|
156
154
|
summary: Custom RSpec Rails-related matcher, used for UMass Transit's internal Rails
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
data/.travis.yml
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.1.8
|
4
|
-
- 2.2.4
|
5
|
-
- 2.3.0
|
6
|
-
env: CODECLIMATE_REPO_TOKEN=2e3996c4e1980943b0b1350ecfccc3c7f1adf90952d7a6c176b4d4bcf4e6b0c6
|
7
|
-
before_install: gem install bundler
|
8
|
-
script: bundle exec rake
|
9
|
-
notifications:
|
10
|
-
email:
|
11
|
-
recipients:
|
12
|
-
- transit-it@admin.umass.edu
|
data/Gemfile
DELETED
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'umts/custom/matchers'
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require 'irb'
|
14
|
-
IRB.start
|
data/bin/setup
DELETED
data/lib/umts-custom-matchers.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'rspec/rails/matchers'
|
2
|
-
|
3
|
-
module UmtsCustomMatchers
|
4
|
-
class RedirectBack
|
5
|
-
MATCHER_MODULE = RSpec::Rails::Matchers
|
6
|
-
STATUS_CODE_MATCHER = MATCHER_MODULE::HaveHttpStatus::GenericStatus
|
7
|
-
REDIRECT_PATH_MATCHER = MATCHER_MODULE::RedirectTo::RedirectTo
|
8
|
-
|
9
|
-
def initialize(scope)
|
10
|
-
@scope = scope
|
11
|
-
end
|
12
|
-
|
13
|
-
def matches?(code)
|
14
|
-
path = 'http://test.host/redirect'
|
15
|
-
@scope.request.env['HTTP_REFERER'] = path
|
16
|
-
return false unless code.is_a? Proc
|
17
|
-
code.call
|
18
|
-
STATUS_CODE_MATCHER.new(:redirect).matches?(@scope.response) &&
|
19
|
-
REDIRECT_PATH_MATCHER.new(@scope, path).matches?(true)
|
20
|
-
end
|
21
|
-
|
22
|
-
def supports_block_expectations?
|
23
|
-
true
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def redirect_back
|
28
|
-
RedirectBack.new self
|
29
|
-
end
|
30
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'umts-custom-matchers/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'umts-custom-matchers'
|
8
|
-
spec.version = UmtsCustomMatchers::VERSION
|
9
|
-
spec.authors = ['UMass Transit Services']
|
10
|
-
spec.email = ['transit-it@admin.umass.edu']
|
11
|
-
|
12
|
-
spec.summary = "Custom RSpec Rails-related matcher, used for UMass
|
13
|
-
Transit's internal Rails development process."
|
14
|
-
spec.homepage = 'https://github.com/umts/custom-matchers'
|
15
|
-
spec.license = 'MIT'
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
-
else fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
22
|
-
end
|
23
|
-
|
24
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
25
|
-
spec.bindir = 'exe'
|
26
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
-
spec.require_paths = ['lib']
|
28
|
-
|
29
|
-
spec.add_dependency 'rspec-rails', '~>3.0'
|
30
|
-
|
31
|
-
spec.add_development_dependency 'bundler'
|
32
|
-
spec.add_development_dependency 'codeclimate-test-reporter'
|
33
|
-
spec.add_development_dependency 'pry-byebug'
|
34
|
-
spec.add_development_dependency 'rake'
|
35
|
-
spec.add_development_dependency 'rubocop'
|
36
|
-
spec.add_development_dependency 'simplecov'
|
37
|
-
end
|