mocki 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.markdown +76 -0
  2. data/lib/mocki.rb +11 -0
  3. metadata +47 -0
@@ -0,0 +1,76 @@
1
+ A micro library for mocking up APIs with Sinatra, allowing you to do
2
+ things like this:
3
+
4
+ require 'sinatra'
5
+ require 'faker'
6
+ require 'mocki'
7
+
8
+ get '/users' do
9
+ mocki do
10
+ {
11
+ status: :ok,
12
+ results: 2.records {|id| {
13
+ id: id,
14
+ name: Faker::Name.name,
15
+ email: Faker::Internet.email,
16
+ comments: 2.records {{
17
+ title: Faker::Lorem.words.map(&:capitalize).join(" "),
18
+ body: Faker::Lorem.paragraph
19
+ }}
20
+ }}
21
+ }
22
+ end
23
+ end
24
+
25
+ post '/users' do
26
+ mocki do
27
+ {
28
+ status: :created,
29
+ first_name: params[:first_name],
30
+ last_name: params[:last_name],
31
+ email: params[:email],
32
+ }
33
+ end
34
+ end
35
+
36
+ Which, combined with the awesomeness that is Sinatra, allows you to make
37
+ an HTTP request to /users and get this:
38
+
39
+ {
40
+ status: "ok",
41
+ results: [
42
+ id: 1,
43
+ name: "Aaron Becker Sr.",
44
+ email: "aleandro_halvorson@kling.net",
45
+ comments: [
46
+ {
47
+ title: "Iste Ratione Dolorum",
48
+ body: "Deserunt porro ab qui doloremque est ea sint. Amet tempora officiis. Porro atque quo libero ipsa voluptas doloremque possimus. Sunt dolore et amet aperiam. Sit aut voluptatem sunt ipsum non odio iste."
49
+ },
50
+ {
51
+ title: "Enim Et Aut",
52
+ body: "Dolorum a est quae nisi qui placeat. Non iusto ut dignissimos accusantium at aut est. Alias illum repellat qui pariatur. Dolorem reiciendis eaque impedit illum corrupti enim."
53
+ }
54
+ ]
55
+ },
56
+ {
57
+ id: 2,
58
+ name: "Leta Volkman",
59
+ email: "jerrell_luettgen@balistreri.org",
60
+ comments: [
61
+ {
62
+ title: "Deleniti Ut Quia",
63
+ body: "Assumenda rem impedit. Accusantium in esse voluptas harum nisi doloribus nihil. Esse animi occaecati quibusdam atque vel autem laboriosam. Eos rerum est sit. Autem voluptatum reprehenderit inventore esse quidem voluptatem."
64
+ },
65
+ {
66
+ title: "Sunt Quidem Nam",
67
+ body: "In temporibus iure. Sapiente fuga ipsum praesentium illum dolor consequuntur est. Nemo ab sit exercitationem et ex delectus. Placeat voluptatum voluptas maiores temporibus. Hic ipsam error est qui illum."
68
+ }
69
+ ]
70
+ }
71
+ ]
72
+ }
73
+
74
+ To install:
75
+
76
+ gem install mocki
@@ -0,0 +1,11 @@
1
+ require 'json'
2
+
3
+ def mocki
4
+ yield.to_json
5
+ end
6
+
7
+ class Fixnum
8
+ def records
9
+ times.each_with_index.map {|i| yield i+1}
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mocki
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric Rafaloff
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-21 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: A micro library for mocking up APIs with Sinatra.
15
+ email:
16
+ - hello@ericrafaloff.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/mocki.rb
22
+ - README.markdown
23
+ homepage: http://github.com/ericr/mocki
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.10
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: A micro library for mocking up APIs with Sinatra.
47
+ test_files: []