api_matchers 0.4.0 → 0.5.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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/History.markdown +9 -0
  4. data/LICENSE +1 -1
  5. data/README.markdown +3 -1
  6. data/TODO.markdown +2 -1
  7. data/api_matchers.gemspec +1 -1
  8. data/lib/api_matchers.rb +1 -0
  9. data/lib/api_matchers/core/rspec_matchers.rb +4 -0
  10. data/lib/api_matchers/headers/base.rb +1 -1
  11. data/lib/api_matchers/headers/be_json.rb +7 -3
  12. data/lib/api_matchers/headers/be_xml.rb +7 -3
  13. data/lib/api_matchers/http_status_code/base.rb +1 -1
  14. data/lib/api_matchers/http_status_code/be_bad_request.rb +7 -3
  15. data/lib/api_matchers/http_status_code/be_internal_server_error.rb +7 -3
  16. data/lib/api_matchers/http_status_code/be_not_found.rb +7 -3
  17. data/lib/api_matchers/http_status_code/be_ok.rb +7 -3
  18. data/lib/api_matchers/http_status_code/be_unauthorized.rb +7 -3
  19. data/lib/api_matchers/http_status_code/be_unprocessable_entity.rb +21 -0
  20. data/lib/api_matchers/http_status_code/create_resource.rb +7 -3
  21. data/lib/api_matchers/response_body/base.rb +6 -2
  22. data/lib/api_matchers/response_body/have_json.rb +6 -3
  23. data/lib/api_matchers/version.rb +1 -1
  24. data/spec/api_matchers/core/find_in_json_spec.rb +4 -4
  25. data/spec/api_matchers/headers/be_json_spec.rb +17 -9
  26. data/spec/api_matchers/headers/be_xml_spec.rb +13 -9
  27. data/spec/api_matchers/http_status_code/be_bad_request_spec.rb +12 -6
  28. data/spec/api_matchers/http_status_code/be_internal_server_error_spec.rb +12 -6
  29. data/spec/api_matchers/http_status_code/be_not_found_spec.rb +12 -6
  30. data/spec/api_matchers/http_status_code/be_ok_spec.rb +12 -6
  31. data/spec/api_matchers/http_status_code/be_unauthorized_spec.rb +12 -6
  32. data/spec/api_matchers/http_status_code/be_unprocessable_entity_spec.rb +27 -0
  33. data/spec/api_matchers/http_status_code/create_resource_spec.rb +12 -6
  34. data/spec/api_matchers/response_body/base_spec.rb +4 -4
  35. data/spec/api_matchers/response_body/have_json_node_spec.rb +63 -57
  36. data/spec/api_matchers/response_body/have_json_spec.rb +7 -7
  37. data/spec/api_matchers/response_body/have_node_spec.rb +2 -2
  38. data/spec/api_matchers/response_body/have_xml_node_spec.rb +51 -38
  39. metadata +9 -5
@@ -3,21 +3,25 @@ require 'spec_helper'
3
3
  describe APIMatchers::HTTPStatusCode::BeBadRequest do
4
4
  describe "should be_bad_request" do
5
5
  it "should passes if the actual is equal to 400" do
6
- 400.should be_bad_request
6
+ expect(400).to be_bad_request
7
7
  end
8
8
 
9
9
  it "should fails if the actual is not equal to 400" do
10
- expect { 401.should be_bad_request }.to fail_with(%Q{expected that '401' to be a Bad Request with the status '400'.})
10
+ expect {
11
+ expect(401).to be_bad_request
12
+ }.to fail_with(%Q{expected that '401' to be a Bad Request with the status '400'.})
11
13
  end
12
14
  end
13
15
 
14
16
  describe "should_not be_bad_request" do
15
17
  it "should passes if the actual is not equal to 400" do
16
- 401.should_not be_bad_request
18
+ expect(401).not_to be_bad_request
17
19
  end
18
20
 
19
21
  it "should fail if the actual is equal to 400" do
20
- expect { 400.should_not be_bad_request }.to fail_with(%Q{expected that '400' to NOT be a Bad Request with the status '400'.})
22
+ expect {
23
+ expect(400).not_to be_bad_request
24
+ }.to fail_with(%Q{expected that '400' to NOT be a Bad Request with the status '400'.})
21
25
  end
22
26
  end
23
27
 
@@ -32,12 +36,14 @@ describe APIMatchers::HTTPStatusCode::BeBadRequest do
32
36
 
33
37
  it "should pass if the actual.http_status is equal to 400" do
34
38
  response = OpenStruct.new(:http_status => 400)
35
- response.should be_bad_request
39
+ expect(response).to be_bad_request
36
40
  end
37
41
 
38
42
  it "should fail if the actual.http_status is not equal to 400" do
39
43
  response = OpenStruct.new(:http_status => 500)
40
- expect { response.should be_bad_request }.to fail_with(%Q{expected that '500' to be a Bad Request with the status '400'.})
44
+ expect {
45
+ expect(response).to be_bad_request
46
+ }.to fail_with(%Q{expected that '500' to be a Bad Request with the status '400'.})
41
47
  end
42
48
  end
43
49
  end
@@ -3,21 +3,25 @@ require 'spec_helper'
3
3
  describe APIMatchers::HTTPStatusCode::BeInternalServerError do
4
4
  describe "should be_internal_server_error" do
5
5
  it "should passes if the actual is equal to 500" do
6
- 500.should be_internal_server_error
6
+ expect(500).to be_internal_server_error
7
7
  end
8
8
 
9
9
  it "should fails if the actual is not equal to 500" do
10
- expect { 401.should be_internal_server_error }.to fail_with(%Q{expected that '401' to be Internal Server Error with the status '500'.})
10
+ expect {
11
+ expect(401).to be_internal_server_error
12
+ }.to fail_with(%Q{expected that '401' to be Internal Server Error with the status '500'.})
11
13
  end
12
14
  end
13
15
 
14
16
  describe "should_not be_internal_server_error" do
15
17
  it "should passes if the actual is not equal to 500" do
16
- 400.should_not be_internal_server_error
18
+ expect(400).not_to be_internal_server_error
17
19
  end
18
20
 
19
21
  it "should fail if the actual is equal to 500" do
20
- expect { 500.should_not be_internal_server_error }.to fail_with(%Q{expected that '500' to NOT be Internal Server Error.})
22
+ expect {
23
+ expect(500).not_to be_internal_server_error
24
+ }.to fail_with(%Q{expected that '500' to NOT be Internal Server Error.})
21
25
  end
22
26
  end
23
27
 
@@ -32,12 +36,14 @@ describe APIMatchers::HTTPStatusCode::BeInternalServerError do
32
36
 
33
37
  it "should pass if the actual.http_status is equal to 500" do
34
38
  response = OpenStruct.new(:http_status => 500)
35
- response.should be_internal_server_error
39
+ expect(response).to be_internal_server_error
36
40
  end
37
41
 
38
42
  it "should fail if the actual.http_status is not equal to 500" do
39
43
  response = OpenStruct.new(:http_status => 402)
40
- expect { response.should be_internal_server_error }.to fail_with(%Q{expected that '402' to be Internal Server Error with the status '500'.})
44
+ expect {
45
+ expect(response).to be_internal_server_error
46
+ }.to fail_with(%Q{expected that '402' to be Internal Server Error with the status '500'.})
41
47
  end
42
48
  end
43
49
  end
@@ -3,21 +3,25 @@ require 'spec_helper'
3
3
  describe APIMatchers::HTTPStatusCode::BeBadRequest do
4
4
  describe "should be_not_found" do
5
5
  it "should passes if the actual is equal to 404" do
6
- 404.should be_not_found
6
+ expect(404).to be_not_found
7
7
  end
8
8
 
9
9
  it "should fails if the actual is not equal to 404" do
10
- expect { 401.should be_not_found }.to fail_with(%Q{expected that '401' to be Not Found with the status '404'.})
10
+ expect {
11
+ expect(401).to be_not_found
12
+ }.to fail_with(%Q{expected that '401' to be Not Found with the status '404'.})
11
13
  end
12
14
  end
13
15
 
14
16
  describe "should_not be_not_found" do
15
17
  it "should passes if the actual is not equal to 404" do
16
- 401.should_not be_not_found
18
+ expect(401).not_to be_not_found
17
19
  end
18
20
 
19
21
  it "should fail if the actual is equal to 404" do
20
- expect { 404.should_not be_not_found }.to fail_with(%Q{expected that '404' to NOT be Not Found with the status '404'.})
22
+ expect {
23
+ expect(404).not_to be_not_found
24
+ }.to fail_with(%Q{expected that '404' to NOT be Not Found with the status '404'.})
21
25
  end
22
26
  end
23
27
 
@@ -32,12 +36,14 @@ describe APIMatchers::HTTPStatusCode::BeBadRequest do
32
36
 
33
37
  it "should pass if the actual.http_status is equal to 404" do
34
38
  response = OpenStruct.new(:http_status => 404)
35
- response.should be_not_found
39
+ expect(response).to be_not_found
36
40
  end
37
41
 
38
42
  it "should fail if the actual.http_status is not equal to 400" do
39
43
  response = OpenStruct.new(:http_status => 500)
40
- expect { response.should be_not_found }.to fail_with(%Q{expected that '500' to be Not Found with the status '404'.})
44
+ expect {
45
+ expect(response).to be_not_found
46
+ }.to fail_with(%Q{expected that '500' to be Not Found with the status '404'.})
41
47
  end
42
48
  end
43
49
  end
@@ -3,21 +3,25 @@ require 'spec_helper'
3
3
  describe APIMatchers::HTTPStatusCode::BeOk do
4
4
  describe "should be_ok" do
5
5
  it "should passes if the actual is equal to 200" do
6
- 200.should be_ok
6
+ expect(200).to be_ok
7
7
  end
8
8
 
9
9
  it "should fails if the actual is not equal to 200" do
10
- expect { 201.should be_ok }.to fail_with(%Q{expected that '201' to be ok with the status '200'.})
10
+ expect {
11
+ expect(201).to be_ok
12
+ }.to fail_with(%Q{expected that '201' to be ok with the status '200'.})
11
13
  end
12
14
  end
13
15
 
14
16
  describe "should_not be_ok_request" do
15
17
  it "should passes if the actual is not equal to 200" do
16
- 201.should_not be_ok
18
+ expect(201).not_to be_ok
17
19
  end
18
20
 
19
21
  it "should fail if the actual is equal to 200" do
20
- expect { 200.should_not be_ok }.to fail_with(%Q{expected that '200' to NOT be ok with the status '200'.})
22
+ expect {
23
+ expect(200).not_to be_ok
24
+ }.to fail_with(%Q{expected that '200' to NOT be ok with the status '200'.})
21
25
  end
22
26
  end
23
27
 
@@ -32,12 +36,14 @@ describe APIMatchers::HTTPStatusCode::BeOk do
32
36
 
33
37
  it "should pass if the actual.http_status is equal to 200" do
34
38
  response = OpenStruct.new(:http_status => 200)
35
- response.should be_ok
39
+ expect(response).to be_ok
36
40
  end
37
41
 
38
42
  it "should fail if the actual.http_status is not equal to 200" do
39
43
  response = OpenStruct.new(:http_status => 500)
40
- expect { response.should be_ok }.to fail_with(%Q{expected that '500' to be ok with the status '200'.})
44
+ expect {
45
+ expect(response).to be_ok
46
+ }.to fail_with(%Q{expected that '500' to be ok with the status '200'.})
41
47
  end
42
48
  end
43
49
  end
@@ -3,21 +3,25 @@ require 'spec_helper'
3
3
  describe APIMatchers::HTTPStatusCode::BeUnauthorized do
4
4
  describe "should be_unauthorized" do
5
5
  it "should passes if the actual is equal to 401" do
6
- 401.should be_unauthorized
6
+ expect(401).to be_unauthorized
7
7
  end
8
8
 
9
9
  it "should fails if the actual is not equal to 401" do
10
- expect { 400.should be_unauthorized }.to fail_with(%Q{expected that '400' to be Unauthorized with the status '401'.})
10
+ expect {
11
+ expect(400).to be_unauthorized
12
+ }.to fail_with(%Q{expected that '400' to be Unauthorized with the status '401'.})
11
13
  end
12
14
  end
13
15
 
14
16
  describe "should_not be_unauthorized" do
15
17
  it "should passes if the actual is not equal to 401" do
16
- 201.should_not be_unauthorized
18
+ expect(201).not_to be_unauthorized
17
19
  end
18
20
 
19
21
  it "should fail if the actual is equal equal to 401" do
20
- expect { 401.should_not be_unauthorized }.to fail_with(%Q{expected that '401' to NOT be Unauthorized.})
22
+ expect {
23
+ expect(401).not_to be_unauthorized
24
+ }.to fail_with(%Q{expected that '401' to NOT be Unauthorized.})
21
25
  end
22
26
  end
23
27
 
@@ -32,12 +36,14 @@ describe APIMatchers::HTTPStatusCode::BeUnauthorized do
32
36
 
33
37
  it "should pass if the actual.http_status is equal to 401" do
34
38
  response = OpenStruct.new(:http_status => 401)
35
- response.should be_unauthorized
39
+ expect(response).to be_unauthorized
36
40
  end
37
41
 
38
42
  it "should fail if the actual.http_status is not equal to 401" do
39
43
  response = OpenStruct.new(:http_status => 402)
40
- expect { response.should be_unauthorized }.to fail_with(%Q{expected that '402' to be Unauthorized with the status '401'.})
44
+ expect {
45
+ expect(response).to be_unauthorized
46
+ }.to fail_with(%Q{expected that '402' to be Unauthorized with the status '401'.})
41
47
  end
42
48
  end
43
49
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe APIMatchers::HTTPStatusCode::BeUnprocessableEntity do
4
+ describe "should be_unprocessable_entity" do
5
+ it "should passes if the actual is equal to 422" do
6
+ expect(422).to be_unprocessable_entity
7
+ end
8
+
9
+ it "should fails if the actual is not equal to 422" do
10
+ expect {
11
+ expect(500).to be_unprocessable_entity
12
+ }.to fail_with(%Q{expected that '500' to be Unprocessable entity with the status '422'.})
13
+ end
14
+ end
15
+
16
+ describe "should_not be_unprocessable_entity" do
17
+ it "should passes if the actual is not equal to 200" do
18
+ expect(400).not_to be_unprocessable_entity
19
+ end
20
+
21
+ it "should fail if the actual is equal to 200" do
22
+ expect {
23
+ expect(422).not_to be_unprocessable_entity
24
+ }.to fail_with(%Q{expected that '422' to NOT be Unprocessable entity with the status '422'.})
25
+ end
26
+ end
27
+ end
@@ -3,21 +3,25 @@ require 'spec_helper'
3
3
  describe APIMatchers::HTTPStatusCode::CreateResource do
4
4
  describe "should create_resource" do
5
5
  it "should passes if the actual is equal to 201" do
6
- 201.should create_resource
6
+ expect(201).to create_resource
7
7
  end
8
8
 
9
9
  it "should fails if the actual is not equal to 201" do
10
- expect { 200.should create_resource }.to fail_with(%Q{expected that '200' to be Created Resource with the status '201'.})
10
+ expect {
11
+ expect(200).to create_resource
12
+ }.to fail_with(%Q{expected that '200' to be Created Resource with the status '201'.})
11
13
  end
12
14
  end
13
15
 
14
16
  describe "should_not create_resource" do
15
17
  it "should passes if the actual is not equal to 201" do
16
- 401.should_not create_resource
18
+ expect(401).not_to create_resource
17
19
  end
18
20
 
19
21
  it "should fail if the actual is equal equal to 201" do
20
- expect { 201.should_not create_resource }.to fail_with(%Q{expected that '201' to NOT be Created Resource.})
22
+ expect {
23
+ expect(201).not_to create_resource
24
+ }.to fail_with(%Q{expected that '201' to NOT be Created Resource.})
21
25
  end
22
26
  end
23
27
 
@@ -32,12 +36,14 @@ describe APIMatchers::HTTPStatusCode::CreateResource do
32
36
 
33
37
  it "should pass if the actual.http_status is equal to 201" do
34
38
  response = OpenStruct.new(:http_status => 201)
35
- response.should create_resource
39
+ expect(response).to create_resource
36
40
  end
37
41
 
38
42
  it "should fail if the actual.http_status is not equal to 201" do
39
43
  response = OpenStruct.new(:http_status => 402)
40
- expect { response.should create_resource }.to fail_with(%Q{expected that '402' to be Created Resource with the status '201'.})
44
+ expect {
45
+ expect(response).to create_resource
46
+ }.to fail_with(%Q{expected that '402' to be Created Resource with the status '201'.})
41
47
  end
42
48
  end
43
49
  end
@@ -14,13 +14,13 @@ describe APIMatchers::ResponseBody::Base do
14
14
 
15
15
  describe "#setup" do
16
16
  it "should read from the initialize" do
17
- subject.setup.should equal setup
17
+ expect(subject.setup).to equal setup
18
18
  end
19
19
  end
20
20
 
21
21
  describe "#expected_node" do
22
22
  it "should read from the initialize" do
23
- subject.expected_node.should equal :status
23
+ expect(subject.expected_node).to equal :status
24
24
  end
25
25
  end
26
26
 
@@ -30,7 +30,7 @@ describe APIMatchers::ResponseBody::Base do
30
30
  context 'when have configuration' do
31
31
  it "should call the method when is config" do
32
32
  subject.actual = OpenStruct.new(:body => body)
33
- subject.response_body.should eql body
33
+ expect(subject.response_body).to eql body
34
34
  end
35
35
  end
36
36
 
@@ -40,7 +40,7 @@ describe APIMatchers::ResponseBody::Base do
40
40
 
41
41
  it "should return the actual when do not have config" do
42
42
  subject.actual = body
43
- subject.response_body.should eql body
43
+ expect(subject.response_body).to eql body
44
44
  end
45
45
  end
46
46
  end
@@ -1,82 +1,82 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe APIMatchers::ResponseBody::HaveJsonNode do
4
- describe "actual.should have_json_node" do
4
+ describe "actual).to have_json_node" do
5
5
  context 'expected key and value in top level' do
6
6
  it "pass when the expected key exist" do
7
- { :product => 'gateway' }.to_json.should have_json_node(:product)
7
+ expect({ :product => 'gateway' }.to_json).to have_json_node(:product)
8
8
  end
9
9
 
10
10
  it "fail when the expected key does not exist" do
11
11
  expect {
12
- { :product => 'pabx' }.to_json.should have_json_node(:developers)
12
+ expect({ :product => 'pabx' }.to_json).to have_json_node(:developers)
13
13
  }.to fail_with(%Q{expected to have node called: 'developers'. Got: '{"product":"pabx"}'})
14
14
  end
15
15
 
16
16
  it "pass when the expected key exist with the expected value" do
17
- { :product => 'payment-gateway' }.to_json.should have_json_node(:product).with('payment-gateway')
17
+ expect({ :product => 'payment-gateway' }.to_json).to have_json_node(:product).with('payment-gateway')
18
18
  end
19
19
 
20
20
  it "pass when the expected key exist with the expected value (as integer)" do
21
- { :number => 1 }.to_json.should have_json_node(:number).with(1)
21
+ expect({ :number => 1 }.to_json).to have_json_node(:number).with(1)
22
22
  end
23
23
 
24
24
  it "pass when the expected key exist with the expected value (as boolean, true)" do
25
- { :number => true }.to_json.should have_json_node(:number).with(true)
25
+ expect({ :number => true }.to_json).to have_json_node(:number).with(true)
26
26
  end
27
27
 
28
28
  it "pass when the expected key exist with the expected value (as boolean, false)" do
29
- { :number => false }.to_json.should have_json_node(:number).with(false)
29
+ expect({ :number => false }.to_json).to have_json_node(:number).with(false)
30
30
  end
31
31
 
32
32
  it "pass when the expected key exist but the expected value is wrong (as boolean, true)" do
33
- { :number => true }.to_json.should_not have_json_node(:number).with(false)
33
+ expect({ :number => true }.to_json).not_to have_json_node(:number).with(false)
34
34
  end
35
35
 
36
36
  it "pass when the expected key exist but the expected value is wrong (as boolean, false)" do
37
- { :number => false }.to_json.should_not have_json_node(:number).with(true)
37
+ expect({ :number => false }.to_json).not_to have_json_node(:number).with(true)
38
38
  end
39
39
 
40
40
  it "pass when the expected key exists with the expected value (as DateTime)" do
41
- now = DateTime.now
42
- { :date => now }.to_json.should have_json_node(:date).with(now)
41
+ now = DateTime.now.to_s
42
+ expect({ :date => now }.to_json).to have_json_node(:date).with(now)
43
43
  end
44
44
 
45
45
  it "pass when the expected key exists with the expected value (as Date)" do
46
46
  now = Date.today
47
- { :date => now }.to_json.should have_json_node(:date).with(now)
47
+ expect({ :date => now }.to_json).to have_json_node(:date).with(now)
48
48
  end
49
49
 
50
50
  it "pass when the expected key exists with the expected value (as Time)" do
51
- now = Time.now
52
- { :time => now }.to_json.should have_json_node(:time).with(now)
51
+ now = Time.now.to_s
52
+ expect({ :time => now }.to_json).to have_json_node(:time).with(now)
53
53
  end
54
54
 
55
55
  it "fail when the expected key exist but the expected value don't exist" do
56
56
  expect {
57
- { :product => 'payment-gateway' }.to_json.should have_json_node(:product).with('email-marketing')
57
+ expect({ :product => 'payment-gateway' }.to_json).to have_json_node(:product).with('email-marketing')
58
58
  }.to fail_with(%Q{expected to have node called: 'product' with value: 'email-marketing'. Got: '{"product":"payment-gateway"}'})
59
59
  end
60
60
 
61
61
  it "not parse the matcher for json when you pass a xml" do
62
62
  expect {
63
- "<product><name>webdesk</name></product>".should have_json_node(:name).with('webdesk')
63
+ expect("<product><name>webdesk</name></product>").to have_json_node(:name).with('webdesk')
64
64
  }.to raise_error(APIMatchers::InvalidJSON, "Invalid JSON: '<product><name>webdesk</name></product>'")
65
65
  end
66
66
  end
67
67
 
68
68
  context 'expected key and nil value' do
69
69
  it "pass when the expected key exists" do
70
- { :product => nil }.to_json.should have_json_node(:product)
70
+ expect({ :product => nil }.to_json).to have_json_node(:product)
71
71
  end
72
72
 
73
73
  it "pass when the expected key exists and the expected value is nil" do
74
- { :product => nil }.to_json.should have_json_node(:product).with( nil )
74
+ expect({ :product => nil }.to_json).to have_json_node(:product).with( nil )
75
75
  end
76
76
 
77
77
  it "fail when the expected key exist but the expected value don't exist" do
78
78
  expect {
79
- { :product => nil }.to_json.should have_json_node(:product).with('email-marketing')
79
+ expect({ :product => nil }.to_json).to have_json_node(:product).with('email-marketing')
80
80
  }.to fail_with(%Q{expected to have node called: 'product' with value: 'email-marketing'. Got: '{"product":null}'})
81
81
  end
82
82
  end
@@ -84,141 +84,145 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
84
84
  context 'expected key and value in more deep in the JSON' do
85
85
  context '.to_json used' do
86
86
  it "pass when the expected key exist" do
87
- { :transaction => { :id => 150 } }.to_json.should have_json_node(:id)
87
+ expect({ :transaction => { :id => 150 } }.to_json).to have_json_node(:id)
88
88
  end
89
89
 
90
90
  it "pass when the expected key and expected value exist" do
91
- { :transaction => { :error => { :code => '999' } } }.to_json.should have_json_node(:code).with('999')
91
+ expect({ :transaction => { :error => { :code => '999' } } }.to_json).to have_json_node(:code).with('999')
92
92
  end
93
93
 
94
94
  it "pass when the expected key and expected value exist in very deep" do
95
- { :first=>"A", :second=>nil, :third=>{ :stuff => { :first_stuff=>{ :color=>"green", :size=>"small", :shape=>"circle", :uid=>"first_stuff"}, :second_stuff=>{ :color=>"blue", :size=>"large", :shape=>"square", :uid=>"second_stuff"}}, :junk=>[{"name"=>"junk_one", :uid=>"junk_one", :stuff_uid=>"first_stuff"}, { :name=>"junk_two", :uid=>"junk_two", :stuff_uid=>"second_stuff"}]}}.to_json.should have_json_node( :junk )
95
+ expect({ :first=>"A", :second=>nil, :third=>{ :stuff => { :first_stuff=>{ :color=>"green", :size=>"small", :shape=>"circle", :uid=>"first_stuff"}, :second_stuff=>{ :color=>"blue", :size=>"large", :shape=>"square", :uid=>"second_stuff"}}, :junk=>[{"name"=>"junk_one", :uid=>"junk_one", :stuff_uid=>"first_stuff"}, { :name=>"junk_two", :uid=>"junk_two", :stuff_uid=>"second_stuff"}]}}.to_json).to have_json_node( :junk )
96
96
  end
97
97
 
98
98
  it "pass when the expected key and expected value exist in very deep" do
99
- { :first=>"A", :second=>nil, :third=>{ :stuff => { :first_stuff=>{ :color=>"green", :size=>"small", :shape=>"circle", :uid=>"first_stuff"}, :second_stuff=>{ :color=>"blue", :size=>"large", :shape=>"square", :uid=>"second_stuff"}}, :junk=>[{"name"=>"junk_one", :uid=>"junk_one", :stuff_uid=>"first_stuff"}, { :name=>"junk_two", :uid=>"junk_two", :stuff_uid=>"second_stuff"}]}}.to_json.should have_json_node( :name ).with( "junk_two" )
99
+ expect({ :first=>"A", :second=>nil, :third=>{ :stuff => { :first_stuff=>{ :color=>"green", :size=>"small", :shape=>"circle", :uid=>"first_stuff"}, :second_stuff=>{ :color=>"blue", :size=>"large", :shape=>"square", :uid=>"second_stuff"}}, :junk=>[{"name"=>"junk_one", :uid=>"junk_one", :stuff_uid=>"first_stuff"}, { :name=>"junk_two", :uid=>"junk_two", :stuff_uid=>"second_stuff"}]}}.to_json).to have_json_node( :name ).with( "junk_two" )
100
100
  end
101
101
 
102
102
  it "fail when the expected key does not exist" do
103
103
  expect {
104
- { :transaction => { :id => 150, :error => {} } }.to_json.should have_json_node(:code)
104
+ expect({ :transaction => { :id => 150, :error => {} } }.to_json).to have_json_node(:code)
105
105
  }.to fail_with(%Q{expected to have node called: 'code'. Got: '{"transaction":{"id":150,"error":{}}}'})
106
106
  end
107
107
 
108
108
  it "fail when the expected key exist but don't exist the expected value" do
109
109
  expect {
110
- { :transaction => { :id => 150, :error => { :code => '999' } } }.to_json.should have_json_node(:code).with('001')
110
+ expect({ :transaction => { :id => 150, :error => { :code => '999' } } }.to_json).to have_json_node(:code).with('001')
111
111
  }.to fail_with(%Q{expected to have node called: 'code' with value: '001'. Got: '{"transaction":{"id":150,"error":{"code":"999"}}}'})
112
112
  end
113
113
  end
114
114
  context 'json string used' do
115
115
  it "pass when the expected key exist" do
116
- '{ "transaction": {"id": 150 } }'.should have_json_node(:id)
116
+ expect('{ "transaction": {"id": 150 } }').to have_json_node(:id)
117
117
  end
118
118
 
119
119
  it "pass when the expected key and expected value exist" do
120
- '{ "transaction": {"error": { "code": "999" } } }'.should have_json_node(:code).with('999')
120
+ expect('{ "transaction": {"error": { "code": "999" } } }').to have_json_node(:code).with('999')
121
121
  end
122
122
 
123
123
  it "pass when the expected key exist with the expected value (as integer)" do
124
- '{"number":1 }'.should have_json_node(:number).with(1)
124
+ expect('{"number":1 }').to have_json_node(:number).with(1)
125
125
  end
126
126
 
127
127
  it "pass when the expected key exist with the expected value (as boolean)" do
128
- '{"boolean":true}'.should have_json_node(:boolean).with(true)
128
+ expect('{"boolean":true}').to have_json_node(:boolean).with(true)
129
129
  end
130
130
 
131
131
  it "pass when the expected key exists with the expected value (as DateTime)" do
132
132
  now = DateTime.parse( "2012-09-18T15:42:12-07:00" )
133
- '{"date": "2012-09-18T15:42:12-07:00"}'.should have_json_node(:date).with(now)
133
+ expect('{"date": "2012-09-18T15:42:12-07:00"}').to have_json_node(:date).with(now)
134
134
  end
135
135
 
136
136
  it "pass when the expected key exists with the expected value (as Date)" do
137
137
  now = Date.parse( "2012-09-18" )
138
- '{"date": "2012-09-18"}'.should have_json_node(:date).with(now)
138
+ expect('{"date": "2012-09-18"}').to have_json_node(:date).with(now)
139
139
  end
140
140
 
141
141
  it "pass when the expected key exists with the expected value (as Time)" do
142
142
  now = Time.parse("2012-09-18T15:42:12Z")
143
- '{"time": "2012-09-18T15:42:12+00:00"}'.should have_json_node(:time).with(now)
143
+ expect('{"time": "2012-09-18T15:42:12+00:00"}').to have_json_node(:time).with(now)
144
144
  end
145
145
 
146
146
  it "pass when the expected key exist with the expected value (as boolean) in a multi node" do
147
- '{"uid":"123456","boolean":true}'.should have_json_node(:boolean).with(true)
147
+ expect('{"uid":"123456","boolean":true}').to have_json_node(:boolean).with(true)
148
148
  end
149
149
 
150
150
  it "pass when the expected key and expected value exist in very deep" do
151
- '{"first":"A","second":null,"third":{"stuff":{"first_stuff":{"color":"green","size":"small","shape":"circle","uid":"first_stuff"},"second_stuff":{"color":"blue","size":"large","shape":"square","uid":"second_stuff"}},"junk":[{"name":"junk_one","uid":"junk_one","stuff_uid":"first_stuff"},{"name":"junk_two","uid":"junk_two","stuff_uid":"second_stuff"}]}}'.should have_json_node( :junk )
151
+ expect('{"first":"A","second":null,"third":{"stuff":{"first_stuff":{"color":"green","size":"small","shape":"circle","uid":"first_stuff"},"second_stuff":{"color":"blue","size":"large","shape":"square","uid":"second_stuff"}},"junk":[{"name":"junk_one","uid":"junk_one","stuff_uid":"first_stuff"},{"name":"junk_two","uid":"junk_two","stuff_uid":"second_stuff"}]}}').to have_json_node( :junk )
152
152
  end
153
153
 
154
154
  it "pass when the expected key and expected value exist in very deep" do
155
- '{"first":"A","second":null,"third":{"stuff":{"first_stuff":{"color":"green","size":"small","shape":"circle","uid":"first_stuff"},"second_stuff":{"color":"blue","size":"large","shape":"square","uid":"second_stuff"}},"junk":[{"name":"junk_one","uid":"junk_one","stuff_uid":"first_stuff"},{"name":"junk_two","uid":"junk_two","stuff_uid":"second_stuff"}]}}'.should have_json_node( :name ).with( "junk_two" )
155
+ expect('{"first":"A","second":null,"third":{"stuff":{"first_stuff":{"color":"green","size":"small","shape":"circle","uid":"first_stuff"},"second_stuff":{"color":"blue","size":"large","shape":"square","uid":"second_stuff"}},"junk":[{"name":"junk_one","uid":"junk_one","stuff_uid":"first_stuff"},{"name":"junk_two","uid":"junk_two","stuff_uid":"second_stuff"}]}}').to have_json_node( :name ).with( "junk_two" )
156
156
  end
157
157
 
158
158
  it "pass when the expected key and including text exist" do
159
- '{"Key":"A=123456-abcdef-09876-ghijkl; path=/; expires=Sun, 05-Sep-2032 05:50:39 GMT\nB=ABCDEF123456; path=/; expires=Sun, 05-Sep-2032 05:50:39 GMT", "Content-Type":"application/json; charset=utf-8"}'.should have_json_node( "Key" ).including_text( "123456-abcdef-09876-ghijkl" )
159
+ expect('{"Key":"A=123456-abcdef-09876-ghijkl; path=/; expires=Sun, 05-Sep-2032 05:50:39 GMT\nB=ABCDEF123456; path=/; expires=Sun, 05-Sep-2032 05:50:39 GMT", "Content-Type":"application/json; charset=utf-8"}').to have_json_node( "Key" ).including_text( "123456-abcdef-09876-ghijkl" )
160
160
  end
161
161
 
162
162
  it "fail when the expected key does not exist" do
163
163
  expect {
164
- '{"transaction":{"id":150,"error":{}}}'.should have_json_node(:code)
164
+ expect('{"transaction":{"id":150,"error":{}}}').to have_json_node(:code)
165
165
  }.to fail_with(%Q{expected to have node called: 'code'. Got: '{"transaction":{"id":150,"error":{}}}'})
166
166
  end
167
167
 
168
168
  it "fail when the expected key exist but don't exist the expected value" do
169
169
  expect {
170
- '{"transaction":{"id":150,"error":{"code":"999"}}}'.should have_json_node(:code).with('001')
170
+ expect('{"transaction":{"id":150,"error":{"code":"999"}}}').to have_json_node(:code).with('001')
171
171
  }.to fail_with(%Q{expected to have node called: 'code' with value: '001'. Got: '{"transaction":{"id":150,"error":{"code":"999"}}}'})
172
172
  end
173
173
  end
174
174
  end
175
175
 
176
176
  context "including_text" do
177
+ let(:json) do
178
+ { :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json
179
+ end
180
+
177
181
  it "pass when the expected is included in the actual" do
178
- { :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json.should have_json_node(:message).including_text("Transaction error")
182
+ expect({ :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json).to have_json_node(:message).including_text("Transaction error")
179
183
  end
180
184
 
181
185
  it "fail when the expected is not included in the actual" do
182
186
  expect {
183
- { :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json.should have_json_node(:message).including_text("Fox on the run")
187
+ expect(json).to have_json_node(:message).including_text("Fox on the run")
184
188
  }.to fail_with(%Q{expected to have node called: 'message' including text: 'Fox on the run'. Got: '{"transaction":{"error":{"message":"Transaction error: Name can't be blank"}}}'})
185
189
  end
186
190
  end
187
191
  end
188
192
 
189
- describe "actual.should_not have_json_node" do
193
+ describe "actual).not_to have_json_node" do
190
194
  it "pass when don't have the expected node in root level" do
191
- { :product => 'gateway' }.to_json.should_not have_json_node(:status)
195
+ expect({ :product => 'gateway' }.to_json).not_to have_json_node(:status)
192
196
  end
193
197
 
194
198
  it "pass when don't have the expected node in any level" do
195
- { :transaction => { :id => 12, :status => 'paid' } }.to_json.should_not have_json_node(:error)
199
+ expect({ :transaction => { :id => 12, :status => 'paid' } }.to_json).not_to have_json_node(:error)
196
200
  end
197
201
 
198
202
  it "fail when the expected key exist" do
199
203
  expect {
200
- { :status => 'paid' }.to_json.should_not have_json_node(:status)
204
+ expect({ :status => 'paid' }.to_json).not_to have_json_node(:status)
201
205
  }.to fail_with(%Q{expected to NOT have node called: 'status'. Got: '{"status":"paid"}'})
202
206
  end
203
207
 
204
208
  it "pass when have the expected key but have a different value" do
205
- { :status => 'paid' }.to_json.should_not have_json_node(:status).with('not_authorized')
209
+ expect({ :status => 'paid' }.to_json).not_to have_json_node(:status).with('not_authorized')
206
210
  end
207
211
 
208
212
  it "fail when have the expected key and have the expected value" do
209
213
  expect {
210
- { :status => 'paid' }.to_json.should_not have_json_node(:status).with('paid')
214
+ expect({ :status => 'paid' }.to_json).not_to have_json_node(:status).with('paid')
211
215
  }.to fail_with(%Q{expected to NOT have node called: 'status' with value: 'paid'. Got: '{"status":"paid"}'})
212
216
  end
213
217
 
214
218
  context "including_text" do
215
219
  it "pass when the expected is NOT included in the actual" do
216
- { :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json.should_not have_json_node(:message).including_text("Love gun")
220
+ expect({ :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json).not_to have_json_node(:message).including_text("Love gun")
217
221
  end
218
222
 
219
223
  it "fail when the expected is included in the actual" do
220
224
  expect {
221
- { :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json.should_not have_json_node(:message).including_text("Transaction error")
225
+ expect({ :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json).not_to have_json_node(:message).including_text("Transaction error")
222
226
  }.to fail_with(%Q{expected to NOT have node called: 'message' including text: 'Transaction error'. Got: '{"transaction":{"error":{"message":"Transaction error: Name can't be blank"}}}'})
223
227
  end
224
228
  end
@@ -226,27 +230,27 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
226
230
 
227
231
  describe "some assumptions" do
228
232
  it "pass when have the json node name" do
229
- '{ "transaction": { "id": 54, "status": "paid" } }'.should have_json_node(:transaction)
233
+ expect('{ "transaction": { "id": 54, "status": "paid" } }').to have_json_node(:transaction)
230
234
  end
231
235
 
232
236
  it "pass when have json node with integer value" do
233
- '{ "transaction": { "id": 54, "status": "paid" } }'.should have_json_node(:id).with(54)
237
+ expect('{ "transaction": { "id": 54, "status": "paid" } }').to have_json_node(:id).with(54)
234
238
  end
235
239
 
236
240
  it "should have json node including text" do
237
- '{"error": "Transaction error: Name cant be blank"}'.should have_json_node(:error).including_text("Transaction error")
241
+ expect('{"error": "Transaction error: Name cant be blank"}').to have_json_node(:error).including_text("Transaction error")
238
242
  end
239
243
 
240
244
  it "pass have json node with boolean value" do
241
- '{"creditcard": true}'.should have_json_node(:creditcard).with(true)
245
+ expect('{"creditcard": true}').to have_json_node(:creditcard).with(true)
242
246
  end
243
247
 
244
248
  it "pass have json node with string" do
245
- '{ "error": "not_authorized", "transaction": { "id": "55" } }'.should have_node(:error).with('not_authorized')
249
+ expect('{ "error": "not_authorized", "transaction": { "id": "55" } }').to have_node(:error).with('not_authorized')
246
250
  end
247
251
 
248
252
  it "pass have json node with integer" do
249
- '{"parcels": 1 }'.should have_node(:parcels).with(1)
253
+ expect('{"parcels": 1 }').to have_node(:parcels).with(1)
250
254
  end
251
255
  end
252
256
 
@@ -261,12 +265,14 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
261
265
 
262
266
  it "pass if the actual.http_status is equal to 400" do
263
267
  response = OpenStruct.new(:response_body => { :foo => :bar }.to_json)
264
- response.should have_json_node(:foo).with('bar')
268
+ expect(response).to have_json_node(:foo).with('bar')
265
269
  end
266
270
 
267
271
  it "fail if the actual.http_status is not equal to 400" do
268
272
  response = OpenStruct.new(:response_body => { :baz => :foo}.to_json)
269
- expect { response.should have_json_node(:bar) }.to fail_with(%Q{expected to have node called: 'bar'. Got: '{"baz":"foo"}'})
273
+ expect {
274
+ expect(response).to have_json_node(:bar)
275
+ }.to fail_with(%Q{expected to have node called: 'bar'. Got: '{"baz":"foo"}'})
270
276
  end
271
277
  end
272
- end
278
+ end