Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bugfix #9 - Readme examples are failing. Put a valid JSON for test ag…

…ainst.
  • Loading branch information...
commit 9f88a1279991af331db45d0204f57e75def92fc3 1 parent 5f2aed8
@tomas-stefano authored
View
8 README.markdown
@@ -40,17 +40,17 @@ The have_node matcher parse the actual and see if have the expcted node with the
You can verify if node exists:
```ruby
- "{ 'transaction': { 'id': '54', 'status': 'paid' } }".should have_node(:transaction)
+ '{ "transaction": { "id": 54, "status": "paid" } }'.should have_node(:transaction)
```
Or if node exist with a value:
```ruby
- "{ 'transaction': { 'id': '54', 'status': 'paid' } }".should have_node(:id).with(54)
+ '{ "transaction": { "id": 54, "status": "paid" } }'.should have_node(:id).with(54)
```
```ruby
- "{ 'error': 'not_authorized', 'transaction': { 'id': '55' } }".should have_node(:error).with('not_authorized')
+ '{ "error": "not_authorized", "transaction": { "id": "55" } }'.should have_node(:error).with('not_authorized')
```
```ruby
@@ -126,7 +126,7 @@ Then you can use *without* call the **#body** method:
### Have JSON Node Matcher
```ruby
- "{ 'transaction': { 'id': '54', 'status': 'paid' } }".should have_json_node(:id).with(54)
+ '{ "transaction": { "id": 54, "status": "paid" } }'.should have_json_node(:id).with(54)
```
### Have XML Node Matcher
View
1  TODO.markdown
@@ -0,0 +1 @@
+* Refactor Core::FindInJSON#find method.
View
1  lib/api_matchers/core/find_in_json.rb
@@ -23,6 +23,7 @@ def find(options={})
return value if value == expected_value or expected_value.nil?
end
+
# do we have more to recurse through?
keep_going = nil
if value.is_a? Hash or value.is_a? Array
View
3  lib/api_matchers/response_body/have_json_node.rb
@@ -16,8 +16,7 @@ def matches?(actual)
true # the node is present
end
rescue ::APIMatchers::KeyNotFound
- # the key was not found
- false
+ false # the key was not found
end
end
View
26 spec/api_matchers/response_body/have_json_node_spec.rb
@@ -224,6 +224,32 @@
end
end
+ describe "some assumptions" do
+ it "shouldn't fail" do
+ '{ "transaction": { "id": 54, "status": "paid" } }'.should have_json_node(:transaction)
+ end
+
+ it "also shouldn't fail" do
+ '{ "transaction": { "id": 54, "status": "paid" } }'.should have_json_node(:id).with(54)
+ end
+
+ it "should have json node including text" do
+ '{"error": "Transaction error: Name cant be blank"}'.should have_json_node(:error).including_text("Transaction error")
+ end
+
+ it "should have json node with boolean value" do
+ '{"creditcard": true}'.should have_json_node(:creditcard).with(true)
+ end
+
+ it "should have json node with value" do
+ '{ "error": "not_authorized", "transaction": { "id": "55" } }'.should have_node(:error).with('not_authorized')
+ end
+
+ it "should have json node with integer" do
+ '{"parcels": 1 }'.should have_node(:parcels).with(1)
+ end
+ end
+
describe "with change configuration" do
before do
APIMatchers.setup { |config| config.response_body_method = :response_body }
Please sign in to comment.
Something went wrong with that request. Please try again.