Skip to content

Commit

Permalink
Specifying code example as Ruby.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Tydén committed Mar 11, 2012
1 parent d9a4ecf commit f1c4b04
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions README.md
@@ -1,4 +1,3 @@

__ __ ______
/ / / /_ _________________/ ____/________________
/ /_/ / / / / __ \ _ \_ __/____ \/ __ \ _ \ ___/
Expand All @@ -13,42 +12,44 @@ HTTP APIs from the outside.

## Example

service "http://localhost:4567" do
def response_json
JSON.parse(response.body)
end

resource "/lolz" do
get do
it { responds_with.status :ok }
it { response_json['lolz'].must_be_instance_of Array }

with_query("q=monorail") do
it "only lists lolz that match the query" do
response_json['lolz'].wont_be_empty
response_json['lolz'].each do |lol|
lol['title'].must_match /monorail/
end
end
```ruby
service "http://localhost:4567" do
def response_json
JSON.parse(response.body)
end

resource "/lolz" do
get do
it { responds_with.status :ok }
it { response_json['lolz'].must_be_instance_of Array }

with_query("q=monorail") do
it "only lists lolz that match the query" do
response_json['lolz'].wont_be_empty
response_json['lolz'].each do |lol|
lol['title'].must_match /monorail/
end
end
end
end

post do
describe "without request body" do
it { responds_with.status :unprocessable_entity }
end
post do
describe "without request body" do
it { responds_with.status :unprocessable_entity }
end

describe "with request body" do
with_headers({ 'Content-Type' => 'application/json' }) do
with_request_body({ "title" => "Roflcopter!" }.to_json) do
it { responds_with.status :created }
it { response_json['lol']['title'].must_equal 'Roflcopter!' }
end
end
describe "with request body" do
with_headers({ 'Content-Type' => 'application/json' }) do
with_request_body({ "title" => "Roflcopter!" }.to_json) do
it { responds_with.status :created }
it { response_json['lol']['title'].must_equal 'Roflcopter!' }
end
end
end
end
end
end
```

## Concepts

Expand Down

0 comments on commit f1c4b04

Please sign in to comment.