specdiff 0.2.0 → 0.3.0.rc2
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/.gitignore +14 -0
- data/CHANGELOG.md +29 -0
- data/README.md +22 -6
- data/lib/specdiff/colorize.rb +5 -0
- data/lib/specdiff/compare.rb +2 -2
- data/lib/specdiff/diff.rb +10 -5
- data/lib/specdiff/differ/hash.rb +179 -0
- data/lib/specdiff/differ/not_found.rb +1 -1
- data/lib/specdiff/differ/text.rb +21 -7
- data/lib/specdiff/differ.rb +1 -1
- data/lib/specdiff/hashprint.rb +174 -0
- data/lib/specdiff/inspect.rb +134 -0
- data/lib/specdiff/rspec.rb +26 -0
- data/lib/specdiff/version.rb +1 -1
- data/lib/specdiff/webmock.rb +43 -1
- data/lib/specdiff.rb +15 -1
- data/specdiff.gemspec +6 -7
- metadata +14 -21
- data/.rspec +0 -3
- data/.rubocop.yml +0 -203
- data/.tool-versions +0 -1
- data/Gemfile +0 -12
- data/Gemfile.lock +0 -76
- data/Rakefile +0 -12
- data/examples/webmock/Gemfile +0 -6
- data/examples/webmock/Gemfile.lock +0 -50
- data/examples/webmock/json.rb +0 -37
- data/examples/webmock/text.rb +0 -39
- data/lib/specdiff/differ/hashdiff.rb +0 -86
- data/lib/specdiff/webmock/request_body_diff.rb +0 -41
@@ -1,50 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ../..
|
3
|
-
specs:
|
4
|
-
specdiff (0.2.0)
|
5
|
-
diff-lcs (~> 1.5)
|
6
|
-
hashdiff (~> 1.0)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
addressable (2.8.5)
|
12
|
-
public_suffix (>= 2.0.2, < 6.0)
|
13
|
-
crack (0.4.5)
|
14
|
-
rexml
|
15
|
-
diff-lcs (1.5.0)
|
16
|
-
domain_name (0.6.20231109)
|
17
|
-
ffi (1.16.3)
|
18
|
-
ffi-compiler (1.0.1)
|
19
|
-
ffi (>= 1.0.0)
|
20
|
-
rake
|
21
|
-
hashdiff (1.0.1)
|
22
|
-
http (5.1.1)
|
23
|
-
addressable (~> 2.8)
|
24
|
-
http-cookie (~> 1.0)
|
25
|
-
http-form_data (~> 2.2)
|
26
|
-
llhttp-ffi (~> 0.4.0)
|
27
|
-
http-cookie (1.0.5)
|
28
|
-
domain_name (~> 0.5)
|
29
|
-
http-form_data (2.3.0)
|
30
|
-
llhttp-ffi (0.4.0)
|
31
|
-
ffi-compiler (~> 1.0)
|
32
|
-
rake (~> 13.0)
|
33
|
-
public_suffix (5.0.4)
|
34
|
-
rake (13.1.0)
|
35
|
-
rexml (3.2.6)
|
36
|
-
webmock (3.19.1)
|
37
|
-
addressable (>= 2.8.0)
|
38
|
-
crack (>= 0.3.2)
|
39
|
-
hashdiff (>= 0.4.0, < 2.0.0)
|
40
|
-
|
41
|
-
PLATFORMS
|
42
|
-
x86_64-linux
|
43
|
-
|
44
|
-
DEPENDENCIES
|
45
|
-
http
|
46
|
-
specdiff!
|
47
|
-
webmock
|
48
|
-
|
49
|
-
BUNDLED WITH
|
50
|
-
2.3.5
|
data/examples/webmock/json.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require "webmock"
|
2
|
-
require "specdiff"
|
3
|
-
require "specdiff/webmock"
|
4
|
-
|
5
|
-
Specdiff.load!(:json)
|
6
|
-
|
7
|
-
include WebMock::API
|
8
|
-
|
9
|
-
WebMock.enable!
|
10
|
-
WebMock.show_body_diff! # on by default
|
11
|
-
|
12
|
-
stub_request(:post, "https://www.example.com")
|
13
|
-
.with(
|
14
|
-
body: JSON.generate({
|
15
|
-
my_hash: "is great",
|
16
|
-
the_hash: "is amazing",
|
17
|
-
})
|
18
|
-
)
|
19
|
-
.to_return(status: 400, body: "hello")
|
20
|
-
|
21
|
-
begin
|
22
|
-
HTTP.post(
|
23
|
-
"https://www.example.com",
|
24
|
-
body: JSON.generate({
|
25
|
-
i_had_to_go: "and post a different hash",
|
26
|
-
my_hash: "is different",
|
27
|
-
}),
|
28
|
-
)
|
29
|
-
rescue WebMock::NetConnectNotAllowedError => e
|
30
|
-
puts "success! webmock stopped the request"
|
31
|
-
puts "here is the error text:\n\n"
|
32
|
-
|
33
|
-
puts e.message
|
34
|
-
exit 0
|
35
|
-
end
|
36
|
-
|
37
|
-
puts "nothing was raised??"
|
data/examples/webmock/text.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require "webmock"
|
2
|
-
require "specdiff"
|
3
|
-
require "specdiff/webmock"
|
4
|
-
|
5
|
-
include WebMock::API
|
6
|
-
|
7
|
-
WebMock.enable!
|
8
|
-
WebMock.show_body_diff! # on by default
|
9
|
-
|
10
|
-
stub_request(:post, "https://www.example.com")
|
11
|
-
.with(
|
12
|
-
body: <<~TEXT1,
|
13
|
-
this is the expected body
|
14
|
-
that you should send
|
15
|
-
nothing less
|
16
|
-
nothing more
|
17
|
-
TEXT1
|
18
|
-
)
|
19
|
-
.to_return(status: 400, body: "hello")
|
20
|
-
|
21
|
-
begin
|
22
|
-
HTTP.post(
|
23
|
-
"https://www.example.com",
|
24
|
-
body: <<~TEXT2,
|
25
|
-
this is the unexpected body
|
26
|
-
that i should not have sent
|
27
|
-
nothing less
|
28
|
-
nothing more
|
29
|
-
TEXT2
|
30
|
-
)
|
31
|
-
rescue WebMock::NetConnectNotAllowedError => e
|
32
|
-
puts "success! webmock stopped the request"
|
33
|
-
puts "here is the error text:\n\n"
|
34
|
-
|
35
|
-
puts e.message
|
36
|
-
exit 0
|
37
|
-
end
|
38
|
-
|
39
|
-
puts "nothing was raised??"
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require "hashdiff"
|
2
|
-
|
3
|
-
class Specdiff::Differ::Hashdiff
|
4
|
-
extend ::Specdiff::Colorize
|
5
|
-
|
6
|
-
def self.diff(a, b)
|
7
|
-
# array_path: true returns the path as an array, which differentiates
|
8
|
-
# between symbol keys and string keys in hashes, while the string
|
9
|
-
# representation does not.
|
10
|
-
# hmm it really seems like use_lcs: true gives much less human-readable
|
11
|
-
# (human-comprehensible) output when arrays are involved.
|
12
|
-
::Hashdiff.diff(
|
13
|
-
a.value, b.value,
|
14
|
-
array_path: true,
|
15
|
-
use_lcs: false,
|
16
|
-
)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.empty?(diff)
|
20
|
-
diff.raw.empty?
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.stringify(diff)
|
24
|
-
result = +""
|
25
|
-
|
26
|
-
diff.raw.each do |change|
|
27
|
-
type = change[0] # the char '+', '-' or '~'
|
28
|
-
path = change[1] # for example key1.key2[2] (as ["key1", :key2, 2])
|
29
|
-
path2 = _stringify_path(path)
|
30
|
-
|
31
|
-
if type == "+"
|
32
|
-
value = change[2]
|
33
|
-
|
34
|
-
result << "added #{path2} with value #{value.inspect}"
|
35
|
-
elsif type == "-"
|
36
|
-
value = change[2]
|
37
|
-
|
38
|
-
result << "removed #{path2} with value #{value.inspect}"
|
39
|
-
elsif type == "~"
|
40
|
-
from = change[2]
|
41
|
-
to = change[3]
|
42
|
-
|
43
|
-
result << "changed #{path2} from #{from.inspect} to #{to.inspect}"
|
44
|
-
else
|
45
|
-
result << change.inspect
|
46
|
-
end
|
47
|
-
|
48
|
-
result << "\n"
|
49
|
-
end
|
50
|
-
|
51
|
-
colorize_by_line(result) do |line|
|
52
|
-
if line.start_with?("removed")
|
53
|
-
red(line)
|
54
|
-
elsif line.start_with?("added")
|
55
|
-
green(line)
|
56
|
-
elsif line.start_with?("changed")
|
57
|
-
yellow(line)
|
58
|
-
else
|
59
|
-
reset_color(line)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
PATH_SEPARATOR = ".".freeze
|
65
|
-
|
66
|
-
def self._stringify_path(path)
|
67
|
-
result = +""
|
68
|
-
|
69
|
-
path.each do |component|
|
70
|
-
if component.is_a?(Numeric)
|
71
|
-
result.chomp!(PATH_SEPARATOR)
|
72
|
-
result << "[#{component}]"
|
73
|
-
elsif component.is_a?(Symbol)
|
74
|
-
# by not inspecting symbols they look prettier than strings, but you
|
75
|
-
# can still tell the difference in the printed output
|
76
|
-
result << component.to_s
|
77
|
-
else
|
78
|
-
result << component.inspect
|
79
|
-
end
|
80
|
-
|
81
|
-
result << PATH_SEPARATOR
|
82
|
-
end
|
83
|
-
|
84
|
-
result.chomp(PATH_SEPARATOR)
|
85
|
-
end
|
86
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require "hashdiff"
|
2
|
-
require "json"
|
3
|
-
|
4
|
-
module WebMock
|
5
|
-
class RequestBodyDiff
|
6
|
-
def initialize(request_signature, request_stub)
|
7
|
-
@request_signature = request_signature
|
8
|
-
@request_stub = request_stub
|
9
|
-
end
|
10
|
-
|
11
|
-
PrettyPrintableThingy = Struct.new(:specdiff) do
|
12
|
-
# webmock does not print the diff if it responds true to this.
|
13
|
-
def empty?
|
14
|
-
specdiff.empty?
|
15
|
-
end
|
16
|
-
|
17
|
-
# webmock prints the diff by passing us to PP.pp, which in turn uses this
|
18
|
-
# method.
|
19
|
-
def pretty_print(pp)
|
20
|
-
pp.text("\r") # remove a space that isn't supposed to be there
|
21
|
-
pp.text(specdiff.to_s)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def body_diff
|
26
|
-
specdiff = Specdiff.diff(request_stub_body, request_signature.body)
|
27
|
-
PrettyPrintableThingy.new(specdiff)
|
28
|
-
end
|
29
|
-
|
30
|
-
attr_reader :request_signature, :request_stub
|
31
|
-
private :request_signature, :request_stub
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def request_stub_body
|
36
|
-
request_stub.request_pattern &&
|
37
|
-
request_stub.request_pattern.body_pattern &&
|
38
|
-
request_stub.request_pattern.body_pattern.pattern
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|