pact-support 1.11.0 → 1.12.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/CHANGELOG.md +16 -0
- data/lib/pact/consumer_contract/consumer_contract.rb +11 -0
- data/lib/pact/consumer_contract/interaction.rb +4 -1
- data/lib/pact/consumer_contract/interaction_v2_parser.rb +9 -1
- data/lib/pact/consumer_contract/interaction_v3_parser.rb +10 -1
- data/lib/pact/support/version.rb +1 -1
- metadata +4 -227
- data/.github/ISSUE_TEMPLATE.md +0 -33
- data/.gitignore +0 -32
- data/.rspec +0 -3
- data/.travis.yml +0 -29
- data/Appraisals +0 -7
- data/Gemfile +0 -4
- data/RELEASING.md +0 -5
- data/Rakefile +0 -4
- data/gemfiles/default.gemfile +0 -5
- data/gemfiles/ruby_under_22.gemfile +0 -8
- data/pact-support.gemspec +0 -39
- data/script/release.sh +0 -9
- data/script/update-pact-specification-v2 +0 -9
- data/spec/fixtures/interaction-with-matching-rules.json +0 -27
- data/spec/fixtures/multipart-form-diff.txt +0 -9
- data/spec/fixtures/not-a-pact.json +0 -3
- data/spec/fixtures/pact-http-v2.json +0 -36
- data/spec/fixtures/pact-http-v3.json +0 -36
- data/spec/integration/matching_rules_extract_and_merge_spec.rb +0 -127
- data/spec/lib/pact/array_like_spec.rb +0 -37
- data/spec/lib/pact/configuration_spec.rb +0 -61
- data/spec/lib/pact/consumer/request_spec.rb +0 -25
- data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +0 -58
- data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +0 -142
- data/spec/lib/pact/consumer_contract/file_name_spec.rb +0 -24
- data/spec/lib/pact/consumer_contract/headers_spec.rb +0 -107
- data/spec/lib/pact/consumer_contract/http_consumer_contract_parser_spec.rb +0 -25
- data/spec/lib/pact/consumer_contract/interaction_parser_spec.rb +0 -62
- data/spec/lib/pact/consumer_contract/interaction_spec.rb +0 -121
- data/spec/lib/pact/consumer_contract/interaction_v2_parser_spec.rb +0 -54
- data/spec/lib/pact/consumer_contract/interaction_v3_parser_spec.rb +0 -48
- data/spec/lib/pact/consumer_contract/pact_file_spec.rb +0 -204
- data/spec/lib/pact/consumer_contract/query_hash_spec.rb +0 -154
- data/spec/lib/pact/consumer_contract/query_string_spec.rb +0 -131
- data/spec/lib/pact/consumer_contract/request_spec.rb +0 -486
- data/spec/lib/pact/consumer_contract/response_spec.rb +0 -82
- data/spec/lib/pact/helpers_spec.rb +0 -143
- data/spec/lib/pact/matchers/differ_spec.rb +0 -215
- data/spec/lib/pact/matchers/difference_spec.rb +0 -22
- data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +0 -90
- data/spec/lib/pact/matchers/extract_diff_messages_spec.rb +0 -78
- data/spec/lib/pact/matchers/index_not_found_spec.rb +0 -21
- data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +0 -121
- data/spec/lib/pact/matchers/matchers_array_like_spec.rb +0 -222
- data/spec/lib/pact/matchers/matchers_messages_hash_and_array_spec.rb +0 -146
- data/spec/lib/pact/matchers/matchers_messages_mismatched_value_spec.rb +0 -72
- data/spec/lib/pact/matchers/matchers_messages_regexp_spec.rb +0 -103
- data/spec/lib/pact/matchers/matchers_spec.rb +0 -561
- data/spec/lib/pact/matchers/multipart_form_diff_formatter_spec.rb +0 -36
- data/spec/lib/pact/matchers/no_diff_at_index_spec.rb +0 -15
- data/spec/lib/pact/matchers/regexp_difference_spec.rb +0 -20
- data/spec/lib/pact/matchers/type_difference_spec.rb +0 -36
- data/spec/lib/pact/matchers/unexpected_index_spec.rb +0 -20
- data/spec/lib/pact/matchers/unexpected_key_spec.rb +0 -20
- data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +0 -235
- data/spec/lib/pact/matching_rules/extract_spec.rb +0 -216
- data/spec/lib/pact/matching_rules/merge_spec.rb +0 -436
- data/spec/lib/pact/matching_rules/v3/extract_spec.rb +0 -238
- data/spec/lib/pact/matching_rules/v3/merge_spec.rb +0 -485
- data/spec/lib/pact/matching_rules_spec.rb +0 -82
- data/spec/lib/pact/reification_spec.rb +0 -172
- data/spec/lib/pact/shared/dsl_spec.rb +0 -100
- data/spec/lib/pact/shared/form_differ_spec.rb +0 -71
- data/spec/lib/pact/shared/json_differ_spec.rb +0 -36
- data/spec/lib/pact/shared/key_not_found_spec.rb +0 -20
- data/spec/lib/pact/shared/multipart_form_differ_spec.rb +0 -49
- data/spec/lib/pact/shared/request_spec.rb +0 -235
- data/spec/lib/pact/shared/text_differ_spec.rb +0 -54
- data/spec/lib/pact/something_like_spec.rb +0 -23
- data/spec/lib/pact/support_spec.rb +0 -9
- data/spec/lib/pact/symbolize_keys_spec.rb +0 -15
- data/spec/lib/pact/term_spec.rb +0 -89
- data/spec/pact_specification/compliance-2.0.rb +0 -66
- data/spec/spec_helper.rb +0 -18
- data/spec/support/a_consumer-a_producer.json +0 -32
- data/spec/support/a_consumer-a_provider.json +0 -32
- data/spec/support/active_support_if_configured.rb +0 -6
- data/spec/support/case-insensitive-response-header-matching.json +0 -21
- data/spec/support/consumer_contract_template.json +0 -24
- data/spec/support/dsl_spec_support.rb +0 -7
- data/spec/support/factories.rb +0 -87
- data/spec/support/generated_index.md +0 -4
- data/spec/support/generated_markdown.md +0 -55
- data/spec/support/interaction_view_model.json +0 -63
- data/spec/support/interaction_view_model_with_terms.json +0 -50
- data/spec/support/markdown_pact.json +0 -48
- data/spec/support/missing_provider_states_output.txt +0 -25
- data/spec/support/options.json +0 -21
- data/spec/support/ruby_version_helpers.rb +0 -23
- data/spec/support/shared_examples_for_request.rb +0 -132
- data/spec/support/spec_support.rb +0 -29
- data/spec/support/stubbing.json +0 -22
- data/spec/support/term.json +0 -48
- data/spec/support/test_app_fail.json +0 -61
- data/spec/support/test_app_pass.json +0 -38
- data/spec/support/test_app_with_right_content_type_differ.json +0 -23
- data/tasks/release.rake +0 -5
- data/tasks/spec.rake +0 -14
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pact/consumer_contract/response'
|
3
|
-
|
4
|
-
module Pact
|
5
|
-
|
6
|
-
describe Response do
|
7
|
-
|
8
|
-
subject { Response.from_hash(status: 200, headers: {'Content-Type' => 'application/json'}, body: {some: 'body'}) }
|
9
|
-
|
10
|
-
describe "initialize" do
|
11
|
-
context "with invalid params" do
|
12
|
-
it "ignores the invalid params" do
|
13
|
-
response = Response.new(foo: 'bar')
|
14
|
-
expect(response).to_not have_key(:foo)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#status" do
|
20
|
-
it "returns the status" do
|
21
|
-
expect(subject.status).to eq 200
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#headers" do
|
26
|
-
it "returns the Headers" do
|
27
|
-
expect(subject.headers).to eq Headers.new('Content-Type' => 'application/json')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#body" do
|
32
|
-
it "returns the body" do
|
33
|
-
expect(subject.body).to eq some: 'body'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "#body_allows_any_value?" do
|
38
|
-
context "when the body is not specified" do
|
39
|
-
subject { Response.from_hash(status: 200, headers: {'Content-Type' => 'application/json'}) }
|
40
|
-
|
41
|
-
it "returns true" do
|
42
|
-
expect(subject.body_allows_any_value?).to be true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when the body is an empty hash" do
|
47
|
-
subject { Response.from_hash(status: 200, headers: {'Content-Type' => 'application/json'}, body: {}) }
|
48
|
-
|
49
|
-
it "returns true" do
|
50
|
-
expect(subject.body_allows_any_value?).to be true
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "when the body is an empty string" do
|
55
|
-
subject { Response.from_hash(status: 200, headers: {'Content-Type' => 'text/plain'}, body: '') }
|
56
|
-
|
57
|
-
it "returns false" do
|
58
|
-
expect(subject.body_allows_any_value?).to be false
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "when the body is a hash with values" do
|
63
|
-
subject { Response.from_hash(status: 200, headers: {'Content-Type' => 'text/plain'}, body: {some: 'body'}) }
|
64
|
-
|
65
|
-
it "returns false" do
|
66
|
-
expect(subject.body_allows_any_value?).to be false
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "when the body is a non-empty String" do
|
71
|
-
subject { Response.from_hash(status: 200, headers: {'Content-Type' => 'text/plain'}, body: 'a string') }
|
72
|
-
|
73
|
-
it "returns false" do
|
74
|
-
expect(subject.body_allows_any_value?).to be false
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
require 'pact/helpers'
|
2
|
-
|
3
|
-
module Pact
|
4
|
-
describe Helpers do
|
5
|
-
|
6
|
-
include Pact::Helpers
|
7
|
-
|
8
|
-
describe "#term" do
|
9
|
-
|
10
|
-
context "with a Hash argument" do
|
11
|
-
it "creates a Pact::Term" do
|
12
|
-
expect(term(generate: 'food', matcher: /foo/)).to eq Pact::Term.new(generate: 'food', matcher: /foo/)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "with a Regexp and a String" do
|
17
|
-
it "creates a Pact::Term" do
|
18
|
-
expect(term(/foo/, 'food')).to eq Pact::Term.new(generate: 'food', matcher: /foo/)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "with a String and a Regexp" do
|
23
|
-
it "creates a Pact::Term" do
|
24
|
-
expect(term('food', /foo/)).to eq Pact::Term.new(generate: 'food', matcher: /foo/)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "with anything else" do
|
29
|
-
it "raises an ArgumentError" do
|
30
|
-
expect{ term(1, /foo/) }.to raise_error(ArgumentError, /Cannot create.*1.*foo/)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#like" do
|
36
|
-
it "creates a Pact::SomethingLike" do
|
37
|
-
expect(like(1)).to eq Pact::SomethingLike.new(1)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#each_like" do
|
42
|
-
it "creates a Pact::ArrayLike" do
|
43
|
-
expect(each_like(1)).to eq Pact::ArrayLike.new(1)
|
44
|
-
expect(each_like(1, min: 2)).to eq Pact::ArrayLike.new(1, min: 2)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#like_uuid" do
|
49
|
-
let(:uuid) { '11111111-2222-3333-4444-000000000000' }
|
50
|
-
|
51
|
-
it "creates a Pact::Term with UUID matcher" do
|
52
|
-
expect(like_uuid(uuid)).to eq Pact::Term.new(
|
53
|
-
generate: uuid,
|
54
|
-
matcher: /^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/
|
55
|
-
)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "#like_datetime" do
|
60
|
-
let(:datetime) { '2015-08-06T16:53:10+01:00' }
|
61
|
-
|
62
|
-
it "creates a Pact::Term with DateTime matcher" do
|
63
|
-
expect(like_datetime(datetime)).to eq Pact::Term.new(
|
64
|
-
generate: datetime,
|
65
|
-
matcher: /^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)$/
|
66
|
-
)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "#like_datetime_with_milliseconds" do
|
71
|
-
let(:datetime) { '2015-08-06T16:53:10.123+01:00' }
|
72
|
-
|
73
|
-
it "creates a Pact::Term with DateTime and Millisecond precision matcher" do
|
74
|
-
expect(like_datetime_with_milliseconds(datetime)).to eq Pact::Term.new(
|
75
|
-
generate: datetime,
|
76
|
-
matcher: /^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d{3}([+-][0-2]\d:[0-5]\d|Z)$/
|
77
|
-
)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "#like_date" do
|
82
|
-
let(:date) { '2015-08-06' }
|
83
|
-
|
84
|
-
it "creates a Pact::Term with Date matcher" do
|
85
|
-
expect(like_date(date)).to eq Pact::Term.new(
|
86
|
-
generate: date,
|
87
|
-
matcher: /^\d{4}-[01]\d-[0-3]\d$/
|
88
|
-
)
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "#like_datetime_rfc822" do
|
92
|
-
context "Day is Tue" do
|
93
|
-
let(:datetime) { 'Tue, 04 Apr 2017 19:03:19 +0000' }
|
94
|
-
it "creates a Pact::Term with a rfc822 matcher" do
|
95
|
-
expect(like_datetime_rfc822(datetime)).to eq Pact::Term.new(
|
96
|
-
generate: datetime,
|
97
|
-
matcher: /(?x)(Mon|Tue|Wed|Thu|Fri|Sat|Sun),
|
98
|
-
\s\d{2}\s
|
99
|
-
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
|
100
|
-
\s\d{4}\s\d{2}:\d{2}:\d{2}\s(\+|-)\d{4}/)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "Day is Sun" do
|
105
|
-
let(:datetime) { 'Sun, 09 Apr 2017 19:03:19 +0000' }
|
106
|
-
it "creates a Pact::Term with a rfc822 matcher" do
|
107
|
-
expect(like_datetime_rfc822(datetime)).to eq Pact::Term.new(
|
108
|
-
generate: datetime,
|
109
|
-
matcher: /(?x)(Mon|Tue|Wed|Thu|Fri|Sat|Sun),
|
110
|
-
\s\d{2}\s
|
111
|
-
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
|
112
|
-
\s\d{4}\s\d{2}:\d{2}:\d{2}\s(\+|-)\d{4}/)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "Month is Jan" do
|
117
|
-
let(:datetime) { 'Mon, 02 Jan 2017 19:03:19 +0000' }
|
118
|
-
it "creates a Pact::Term with a rfc822 matcher" do
|
119
|
-
expect(like_datetime_rfc822(datetime)).to eq Pact::Term.new(
|
120
|
-
generate: datetime,
|
121
|
-
matcher: /(?x)(Mon|Tue|Wed|Thu|Fri|Sat|Sun),
|
122
|
-
\s\d{2}\s
|
123
|
-
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
|
124
|
-
\s\d{4}\s\d{2}:\d{2}:\d{2}\s(\+|-)\d{4}/)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
context "Negative Offset" do
|
129
|
-
let(:datetime) { 'Mon, 31 Oct 2016 15:21:41 -0400' }
|
130
|
-
it "creates a Pact::Term with a rfc822 matcher" do
|
131
|
-
expect(like_datetime_rfc822(datetime)).to eq Pact::Term.new(
|
132
|
-
generate: datetime,
|
133
|
-
matcher: /(?x)(Mon|Tue|Wed|Thu|Fri|Sat|Sun),
|
134
|
-
\s\d{2}\s
|
135
|
-
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
|
136
|
-
\s\d{4}\s\d{2}:\d{2}:\d{2}\s(\+|-)\d{4}/)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
@@ -1,215 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# Ripped from spec/rspec/expectations/differ_spec.rb in rspec-expectations 2.14.3
|
4
|
-
|
5
|
-
require 'spec_helper'
|
6
|
-
require 'ostruct'
|
7
|
-
require 'pact/matchers/differ'
|
8
|
-
|
9
|
-
module Pact
|
10
|
-
module Matchers
|
11
|
-
describe Differ do
|
12
|
-
context "without --color" do
|
13
|
-
|
14
|
-
let(:differ) { Pact::Matchers::Differ.new }
|
15
|
-
|
16
|
-
# color disabled context
|
17
|
-
|
18
|
-
describe '#diff_as_string' do
|
19
|
-
subject { differ.diff_as_string(@expected, @actual) }
|
20
|
-
it "outputs unified diff of two strings" do
|
21
|
-
@expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
|
22
|
-
@actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
|
23
|
-
expect(subject).to eql(<<-'EOD')
|
24
|
-
|
25
|
-
|
26
|
-
@@ -1,6 +1,6 @@
|
27
|
-
foo
|
28
|
-
-zap
|
29
|
-
bar
|
30
|
-
+zap
|
31
|
-
this
|
32
|
-
is
|
33
|
-
soo
|
34
|
-
@@ -9,6 +9,5 @@
|
35
|
-
equal
|
36
|
-
insert
|
37
|
-
a
|
38
|
-
-another
|
39
|
-
line
|
40
|
-
EOD
|
41
|
-
|
42
|
-
end
|
43
|
-
if RUBY_VERSION.to_f > 1.9
|
44
|
-
it 'copes with encoded strings', :pending => (Diff::LCS::VERSION < '1.2.2') do
|
45
|
-
@expected="Tu avec carté {count} itém has".encode('UTF-16LE')
|
46
|
-
@actual="Tu avec carte {count} item has".encode('UTF-16LE')
|
47
|
-
expect(subject).to eql(<<-EOD.encode('UTF-16LE'))
|
48
|
-
|
49
|
-
@@ -1,2 +1,2 @@
|
50
|
-
-Tu avec carte {count} item has
|
51
|
-
+Tu avec carté {count} itém has
|
52
|
-
EOD
|
53
|
-
end
|
54
|
-
it 'copes with encoded strings', :pending => (Diff::LCS::VERSION >= '1.2.2') do
|
55
|
-
@expected="Tu avec carté {count} itém has".encode('UTF-16LE')
|
56
|
-
@actual="Tu avec carte {count} item has".encode('UTF-16LE')
|
57
|
-
expect(subject).to eql 'Could not produce a diff because of the encoding of the string (UTF-16LE)'
|
58
|
-
end
|
59
|
-
it 'ouputs a message when encountering differently encoded strings' do
|
60
|
-
@expected="Tu avec carté {count} itém has".encode('UTF-16LE')
|
61
|
-
@actual="Tu avec carte {count} item has"
|
62
|
-
expect(subject).to eql 'Could not produce a diff because the encoding of the actual string (UTF-8) differs from the encoding of the expected string (UTF-16LE)'
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe '#diff_as_object' do
|
68
|
-
it "outputs unified diff message of two objects" do
|
69
|
-
animal_class = Class.new do
|
70
|
-
def initialize(name, species)
|
71
|
-
@name, @species = name, species
|
72
|
-
end
|
73
|
-
|
74
|
-
def inspect
|
75
|
-
<<-EOA
|
76
|
-
<Animal
|
77
|
-
name=#{@name},
|
78
|
-
species=#{@species}
|
79
|
-
>
|
80
|
-
EOA
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
expected = animal_class.new "bob", "giraffe"
|
85
|
-
actual = animal_class.new "bob", "tortoise"
|
86
|
-
|
87
|
-
expected_diff = <<'EOD'
|
88
|
-
|
89
|
-
@@ -1,5 +1,5 @@
|
90
|
-
<Animal
|
91
|
-
name=bob,
|
92
|
-
- species=tortoise
|
93
|
-
+ species=giraffe
|
94
|
-
>
|
95
|
-
EOD
|
96
|
-
|
97
|
-
diff = differ.diff_as_object(expected,actual)
|
98
|
-
expect(diff).to eq expected_diff
|
99
|
-
end
|
100
|
-
|
101
|
-
it "outputs unified diff message of two arrays" do
|
102
|
-
expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
|
103
|
-
actual = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango' , :width, 'very wide' ]
|
104
|
-
|
105
|
-
expected_diff = <<'EOD'
|
106
|
-
|
107
|
-
|
108
|
-
@@ -5,7 +5,7 @@
|
109
|
-
:metasyntactic,
|
110
|
-
"variable",
|
111
|
-
:delta,
|
112
|
-
- "tango",
|
113
|
-
+ "charlie",
|
114
|
-
:width,
|
115
|
-
- "very wide"]
|
116
|
-
+ "quite wide"]
|
117
|
-
EOD
|
118
|
-
|
119
|
-
diff = differ.diff_as_object(expected,actual)
|
120
|
-
expect(diff).to eq expected_diff
|
121
|
-
end
|
122
|
-
|
123
|
-
it "outputs unified diff message of two hashes" do
|
124
|
-
expected = { :foo => 'bar', :baz => 'quux', :metasyntactic => 'variable', :delta => 'charlie', :width =>'quite wide' }
|
125
|
-
actual = { :foo => 'bar', :metasyntactic => 'variable', :delta => 'charlotte', :width =>'quite wide' }
|
126
|
-
|
127
|
-
expected_diff = <<'EOD'
|
128
|
-
|
129
|
-
@@ -1,4 +1,5 @@
|
130
|
-
-:delta => "charlotte",
|
131
|
-
+:baz => "quux",
|
132
|
-
+:delta => "charlie",
|
133
|
-
:foo => "bar",
|
134
|
-
:metasyntactic => "variable",
|
135
|
-
:width => "quite wide"
|
136
|
-
EOD
|
137
|
-
|
138
|
-
diff = differ.diff_as_object(expected,actual)
|
139
|
-
expect(diff).to eq expected_diff
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'outputs unified diff messaoge of two hashes with differing encoding' do
|
143
|
-
expected_diff = %Q{
|
144
|
-
@@ -1,2 +1,2 @@
|
145
|
-
-"a" => "a"
|
146
|
-
#{ (RUBY_VERSION.to_f > 1.8) ? %Q{+"ö" => "ö"} : '+"\303\266" => "\303\266"' }
|
147
|
-
}
|
148
|
-
|
149
|
-
diff = differ.diff_as_object({'ö' => 'ö'}, {'a' => 'a'})
|
150
|
-
expect(diff).to eq expected_diff
|
151
|
-
end
|
152
|
-
|
153
|
-
it "outputs unified diff message of two hashes with object keys" do
|
154
|
-
expected_diff = %Q{
|
155
|
-
@@ -1,2 +1,2 @@
|
156
|
-
-["a", "c"] => "b"
|
157
|
-
+["d", "c"] => "b"
|
158
|
-
}
|
159
|
-
|
160
|
-
diff = differ.diff_as_object({ ['d','c'] => 'b'}, { ['a','c'] => 'b' })
|
161
|
-
expect(diff).to eq expected_diff
|
162
|
-
end
|
163
|
-
|
164
|
-
it "outputs unified diff of single line strings" do
|
165
|
-
expected = "this is one string"
|
166
|
-
actual = "this is another string"
|
167
|
-
|
168
|
-
expected_diff = <<'EOD'
|
169
|
-
|
170
|
-
@@ -1,2 +1,2 @@
|
171
|
-
-"this is another string"
|
172
|
-
+"this is one string"
|
173
|
-
EOD
|
174
|
-
|
175
|
-
diff = differ.diff_as_object(expected,actual)
|
176
|
-
expect(diff).to eq expected_diff
|
177
|
-
end
|
178
|
-
|
179
|
-
it "outputs unified diff of multi line strings" do
|
180
|
-
expected = "this is:\n one string"
|
181
|
-
actual = "this is:\n another string"
|
182
|
-
|
183
|
-
expected_diff = <<'EOD'
|
184
|
-
|
185
|
-
@@ -1,3 +1,3 @@
|
186
|
-
this is:
|
187
|
-
- another string
|
188
|
-
+ one string
|
189
|
-
EOD
|
190
|
-
|
191
|
-
diff = differ.diff_as_object(expected,actual)
|
192
|
-
expect(diff).to eq expected_diff
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context "with --color" do
|
198
|
-
|
199
|
-
let(:differ) { Pact::Matchers::Differ.new(true) }
|
200
|
-
|
201
|
-
it "outputs colored diffs" do
|
202
|
-
expected = "foo bar baz"
|
203
|
-
actual = "foo bang baz"
|
204
|
-
expected_diff = "\n\e[34m@@ -1,2 +1,2 @@\n\e[0m\e[31m-foo bang baz\n\e[0m\e[32m+foo bar baz\n\e[0m"
|
205
|
-
|
206
|
-
|
207
|
-
diff = differ.diff_as_string(expected,actual)
|
208
|
-
expect(diff).to eq expected_diff
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pact/matchers/difference'
|
3
|
-
|
4
|
-
module Pact
|
5
|
-
module Matchers
|
6
|
-
describe Difference do
|
7
|
-
|
8
|
-
describe "#as_json" do
|
9
|
-
|
10
|
-
context "when something other than a regexp is expected" do
|
11
|
-
|
12
|
-
subject { Difference.new("apple", 'pear').as_json }
|
13
|
-
|
14
|
-
it "indicates that the actual was intended 'to eq'" do
|
15
|
-
expect(subject).to eq({:EXPECTED => "apple", :ACTUAL => "pear"})
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|