Skip to content

Commit

Permalink
Bugfix #9 - Readme examples are failing. Put a valid JSON for test ag…
Browse files Browse the repository at this point in the history
…ainst.
  • Loading branch information
tomas-stefano committed Oct 29, 2012
1 parent 5f2aed8 commit 9f88a12
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions TODO.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Refactor Core::FindInJSON#find method.
1 change: 1 addition & 0 deletions lib/api_matchers/core/find_in_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/api_matchers/response_body/have_json_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 26 additions & 0 deletions spec/api_matchers/response_body/have_json_node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 9f88a12

Please sign in to comment.