proxy_pac_rb 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/proxy_pac_rb/rspec/matchers/base_matcher.rb +179 -0
- data/lib/proxy_pac_rb/rspec/matchers/proxy.rb +70 -16
- data/lib/proxy_pac_rb/rspec/matchers/url.rb +6 -3
- data/lib/proxy_pac_rb/rspec.rb +1 -0
- data/lib/proxy_pac_rb/version.rb +1 -1
- data/spec/rspec/compare_proxy_pac_files_spec.rb +13 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 984f1322c0f74a01b683e103e254f7b4213d90c7
|
4
|
+
data.tar.gz: 825d18e0d3704e069255de8914572c2d1f36c73d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d99f14756f8b5cad760498fde69ee96539639629d3d605fdf1865d4c00a8a30f438a20acd866e5bedc35cbfbadd9c80698fcb4684b16f474ec5327546dc4a9e8
|
7
|
+
data.tar.gz: 3f03f403d55172446e1ebeffda6294165fe94b36659fb704a34d8554fd6109d2b8f1bafeedaffbe0ee705fcbafc1f36106d16f83937d7fb2cc5ff1d73a3e3cfe
|
@@ -0,0 +1,179 @@
|
|
1
|
+
module ProxyPacRb
|
2
|
+
module RSpecMatchers
|
3
|
+
# @api private
|
4
|
+
#
|
5
|
+
# Used _internally_ as a base class for matchers that ship with
|
6
|
+
# rspec-expectations and rspec-rails.
|
7
|
+
#
|
8
|
+
# ### Warning:
|
9
|
+
#
|
10
|
+
# This class is for internal use, and subject to change without notice. We
|
11
|
+
# strongly recommend that you do not base your custom matchers on this
|
12
|
+
# class. If/when this changes, we will announce it and remove this warning.
|
13
|
+
class BaseMatcher
|
14
|
+
include RSpec::Matchers::Composable
|
15
|
+
|
16
|
+
# @api private
|
17
|
+
# Used to detect when no arg is passed to `initialize`.
|
18
|
+
# `nil` cannot be used because it's a valid value to pass.
|
19
|
+
UNDEFINED = Object.new.freeze
|
20
|
+
|
21
|
+
# @private
|
22
|
+
attr_reader :actual, :expected, :rescued_exception
|
23
|
+
|
24
|
+
def initialize(expected=UNDEFINED)
|
25
|
+
@expected = expected unless UNDEFINED.equal?(expected)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @api private
|
29
|
+
# Indicates if the match is successful. Delegates to `match`, which
|
30
|
+
# should be defined on a subclass. Takes care of consistently
|
31
|
+
# initializing the `actual` attribute.
|
32
|
+
def matches?(actual)
|
33
|
+
@actual = actual
|
34
|
+
match(expected, actual)
|
35
|
+
end
|
36
|
+
|
37
|
+
# @api private
|
38
|
+
# Used to wrap a block of code that will indicate failure by
|
39
|
+
# raising one of the named exceptions.
|
40
|
+
#
|
41
|
+
# This is used by rspec-rails for some of its matchers that
|
42
|
+
# wrap rails' assertions.
|
43
|
+
def match_unless_raises(*exceptions)
|
44
|
+
exceptions.unshift Exception if exceptions.empty?
|
45
|
+
begin
|
46
|
+
yield
|
47
|
+
true
|
48
|
+
rescue *exceptions => @rescued_exception
|
49
|
+
false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# @api private
|
54
|
+
# Generates a description using {EnglishPhrasing}.
|
55
|
+
# @return [String]
|
56
|
+
def description
|
57
|
+
desc = EnglishPhrasing.split_words(self.class.matcher_name)
|
58
|
+
desc << EnglishPhrasing.list(@expected) if defined?(@expected)
|
59
|
+
desc
|
60
|
+
end
|
61
|
+
|
62
|
+
# @api private
|
63
|
+
# Matchers are not diffable by default. Override this to make your
|
64
|
+
# subclass diffable.
|
65
|
+
def diffable?
|
66
|
+
false
|
67
|
+
end
|
68
|
+
|
69
|
+
# @api private
|
70
|
+
# Most matchers are value matchers (i.e. meant to work with `expect(value)`)
|
71
|
+
# rather than block matchers (i.e. meant to work with `expect { }`), so
|
72
|
+
# this defaults to false. Block matchers must override this to return true.
|
73
|
+
def supports_block_expectations?
|
74
|
+
false
|
75
|
+
end
|
76
|
+
|
77
|
+
# @api private
|
78
|
+
def expects_call_stack_jump?
|
79
|
+
false
|
80
|
+
end
|
81
|
+
|
82
|
+
# @private
|
83
|
+
def expected_formatted
|
84
|
+
RSpec::Support::ObjectInspector.inspect(@expected)
|
85
|
+
end
|
86
|
+
|
87
|
+
# @private
|
88
|
+
def actual_formatted
|
89
|
+
RSpec::Support::ObjectInspector.inspect(@actual)
|
90
|
+
end
|
91
|
+
|
92
|
+
# @private
|
93
|
+
def self.matcher_name
|
94
|
+
@matcher_name ||= underscore(name.split("::").last)
|
95
|
+
end
|
96
|
+
|
97
|
+
# @private
|
98
|
+
# Borrowed from ActiveSupport.
|
99
|
+
def self.underscore(camel_cased_word)
|
100
|
+
word = camel_cased_word.to_s.dup
|
101
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
102
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
103
|
+
word.tr!("-", "_")
|
104
|
+
word.downcase!
|
105
|
+
word
|
106
|
+
end
|
107
|
+
private_class_method :underscore
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def assert_ivars(*expected_ivars)
|
112
|
+
return unless (expected_ivars - present_ivars).any?
|
113
|
+
ivar_list = EnglishPhrasing.list(expected_ivars)
|
114
|
+
raise "#{self.class.name} needs to supply#{ivar_list}"
|
115
|
+
end
|
116
|
+
|
117
|
+
if RUBY_VERSION.to_f < 1.9
|
118
|
+
# :nocov:
|
119
|
+
def present_ivars
|
120
|
+
instance_variables.map { |v| v.to_sym }
|
121
|
+
end
|
122
|
+
# :nocov:
|
123
|
+
else
|
124
|
+
alias present_ivars instance_variables
|
125
|
+
end
|
126
|
+
|
127
|
+
# @private
|
128
|
+
module HashFormatting
|
129
|
+
# `{ :a => 5, :b => 2 }.inspect` produces:
|
130
|
+
#
|
131
|
+
# {:a=>5, :b=>2}
|
132
|
+
#
|
133
|
+
# ...but it looks much better as:
|
134
|
+
#
|
135
|
+
# {:a => 5, :b => 2}
|
136
|
+
#
|
137
|
+
# This is idempotent and safe to run on a string multiple times.
|
138
|
+
def improve_hash_formatting(inspect_string)
|
139
|
+
inspect_string.gsub(/(\S)=>(\S)/, '\1 => \2')
|
140
|
+
end
|
141
|
+
module_function :improve_hash_formatting
|
142
|
+
end
|
143
|
+
|
144
|
+
include HashFormatting
|
145
|
+
|
146
|
+
# @api private
|
147
|
+
# Provides default implementations of failure messages, based on the `description`.
|
148
|
+
module DefaultFailureMessages
|
149
|
+
# @api private
|
150
|
+
# Provides a good generic failure message. Based on `description`.
|
151
|
+
# When subclassing, if you are not satisfied with this failure message
|
152
|
+
# you often only need to override `description`.
|
153
|
+
# @return [String]
|
154
|
+
def failure_message
|
155
|
+
"expected #{description_of @actual} to #{description}"
|
156
|
+
end
|
157
|
+
|
158
|
+
# @api private
|
159
|
+
# Provides a good generic negative failure message. Based on `description`.
|
160
|
+
# When subclassing, if you are not satisfied with this failure message
|
161
|
+
# you often only need to override `description`.
|
162
|
+
# @return [String]
|
163
|
+
def failure_message_when_negated
|
164
|
+
"expected #{description_of @actual} not to #{description}"
|
165
|
+
end
|
166
|
+
|
167
|
+
# @private
|
168
|
+
def self.has_default_failure_messages?(matcher)
|
169
|
+
matcher.method(:failure_message).owner == self &&
|
170
|
+
matcher.method(:failure_message_when_negated).owner == self
|
171
|
+
rescue NameError
|
172
|
+
false
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
include DefaultFailureMessages
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -1,27 +1,81 @@
|
|
1
1
|
require 'proxy_pac_rb'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module ProxyPacRb
|
4
|
+
module RSpecMatchers
|
5
|
+
class BeTheSameProxyPacFile < BaseMatcher
|
6
|
+
def initialize(expected)
|
7
|
+
@file_a = begin
|
8
|
+
file = ProxyPacRb::ProxyPacFile.new(source: expected)
|
9
|
+
loader.load(file)
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
loader.load(@file_a)
|
11
|
+
file
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
@expected = @file_a.content
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
def matches?(actual)
|
18
|
+
@file_b = begin
|
19
|
+
file = ProxyPacRb::ProxyPacFile.new(source: actual)
|
20
|
+
loader.load(file)
|
21
|
+
|
22
|
+
file
|
23
|
+
end
|
24
|
+
|
25
|
+
@actual = @file_b.content
|
26
|
+
|
27
|
+
values_match?(@expected, @actual)
|
28
|
+
end
|
17
29
|
|
18
|
-
|
30
|
+
def diffable?
|
31
|
+
true
|
32
|
+
end
|
19
33
|
|
20
|
-
|
21
|
-
|
34
|
+
def failure_message
|
35
|
+
format(%(expected that proxy.pac "%s" is equal to proxy.pac "%s", but it is not.), @file_a.source.truncate(30), @file_b.source.truncate(30))
|
36
|
+
end
|
37
|
+
|
38
|
+
def failure_message_when_negated
|
39
|
+
format(%(expected that proxy.pac "%s" is not equal to proxy.pac "%s", but it is the same.), @file_a.source.truncate(30), @file_b.source.truncate(30))
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def loader
|
45
|
+
@loader ||= ProxyPacRb::ProxyPacLoader.new
|
46
|
+
end
|
47
|
+
end
|
22
48
|
end
|
49
|
+
end
|
23
50
|
|
24
|
-
|
25
|
-
|
51
|
+
module RSpec
|
52
|
+
module Matchers
|
53
|
+
def be_the_same_proxy_pac_file(expected)
|
54
|
+
ProxyPacLoader::RSpecMatchers::BeTheSameProxyPacFile.new(expected)
|
55
|
+
end
|
26
56
|
end
|
27
57
|
end
|
58
|
+
|
59
|
+
# RSpec::Matchers.define :be_the_same_proxy_pac_file do |expected|
|
60
|
+
# def loader
|
61
|
+
# @loader ||= ProxyPacRb::ProxyPacLoader.new
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# match do |actual|
|
65
|
+
#
|
66
|
+
# @file_b = begin
|
67
|
+
# file = ProxyPacRb::ProxyPacFile.new(source: expected)
|
68
|
+
# loader.load(file)
|
69
|
+
#
|
70
|
+
# file
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# @actual = @file_a.content
|
74
|
+
# @expected = @file_b.content
|
75
|
+
#
|
76
|
+
# binding.pry
|
77
|
+
#
|
78
|
+
# values_match?(@expected, @actual)
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# end
|
@@ -2,14 +2,17 @@ require 'proxy_pac_rb'
|
|
2
2
|
|
3
3
|
RSpec::Matchers.define :be_downloaded_via do |expected|
|
4
4
|
match do |actual|
|
5
|
-
|
5
|
+
@old_actual = actual
|
6
|
+
@actual = proxy_pac.find(actual).to_s
|
7
|
+
|
8
|
+
@actual == expected
|
6
9
|
end
|
7
10
|
|
8
11
|
failure_message do |actual|
|
9
|
-
format(%(expected that url "%s" is downloaded via "%s", but it is downloaded via "%s".),
|
12
|
+
format(%(expected that url "%s" is downloaded via "%s", but it is downloaded via "%s".), @old_actual, expected, @actual)
|
10
13
|
end
|
11
14
|
|
12
15
|
failure_message_when_negated do |actual|
|
13
|
-
format(%(expected that url "%s" is not downloaded via "%s", but it is downloaded via "%s".),
|
16
|
+
format(%(expected that url "%s" is not downloaded via "%s", but it is downloaded via "%s".), @old_actual, expected, @actual)
|
14
17
|
end
|
15
18
|
end
|
data/lib/proxy_pac_rb/rspec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'proxy_pac_rb'
|
2
2
|
require 'rspec'
|
3
3
|
|
4
|
+
require 'proxy_pac_rb/rspec/matchers/base_matcher'
|
4
5
|
require 'proxy_pac_rb/rspec/helpers'
|
5
6
|
ProxyPacRb.require_file_matching_pattern('rspec/matchers/*.rb')
|
6
7
|
ProxyPacRb.require_file_matching_pattern('rspec/shared_examples/*.rb')
|
data/lib/proxy_pac_rb/version.rb
CHANGED
@@ -26,14 +26,25 @@ RSpec.describe 'Compare to proxy.pac-files', type: :proxy_pac do
|
|
26
26
|
EOS
|
27
27
|
end
|
28
28
|
|
29
|
-
context 'when
|
29
|
+
context 'when expected is a ProxyPacFile' do
|
30
30
|
it { expect(proxy_pac).to be_the_same_proxy_pac_file file_b }
|
31
31
|
end
|
32
32
|
|
33
|
-
context 'when
|
33
|
+
context 'when actual a ProxyPacFile and' do
|
34
34
|
it { expect(file_b).to be_the_same_proxy_pac_file proxy_pac }
|
35
35
|
end
|
36
36
|
|
37
|
+
context 'when both are ProxyPacFile' do
|
38
|
+
let(:already_proxy_pac) { ProxyPacFile.new(source: file_b) }
|
39
|
+
|
40
|
+
before :each do
|
41
|
+
loader = ProxyPacRb::ProxyPacLoader.new
|
42
|
+
loader.load(already_proxy_pac)
|
43
|
+
end
|
44
|
+
|
45
|
+
it { expect(already_proxy_pac).to be_the_same_proxy_pac_file proxy_pac }
|
46
|
+
end
|
47
|
+
|
37
48
|
context 'when file "a" and file "b" are strings' do
|
38
49
|
context 'when both are eqal' do
|
39
50
|
it { expect(file_a).to be_the_same_proxy_pac_file file_b }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proxy_pac_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis Günnewig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/proxy_pac_rb/rspec/helpers.rb
|
154
154
|
- lib/proxy_pac_rb/rspec/helpers/.keep
|
155
155
|
- lib/proxy_pac_rb/rspec/matchers/.keep
|
156
|
+
- lib/proxy_pac_rb/rspec/matchers/base_matcher.rb
|
156
157
|
- lib/proxy_pac_rb/rspec/matchers/proxy.rb
|
157
158
|
- lib/proxy_pac_rb/rspec/matchers/url.rb
|
158
159
|
- lib/proxy_pac_rb/rspec/shared_contexts/.keep
|