the_wizard_of_api 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/features/post_data.feature +24 -0
- data/features/step_definitions/post_data_steps.rb +9 -0
- data/features/support/env.rb +1 -0
- data/features/support/the_wizard_of_api_helper.rb +14 -2
- data/features/support/timing_error_helper.rb +9 -0
- data/lib/the_wizard_of_api.rb +1 -0
- data/lib/the_wizard_of_api/version.rb +1 -1
- data/public/index.html +17 -2
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6439a0d26b20a6bec2b1e1feb9cea37b06b2945e
|
4
|
+
data.tar.gz: 2f796b30721613db65a3b5be5e4ea359750408d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a57a5274c7ff943dde2ac37948a11d77910f302e44975c5982ae318d744121c586cfee1c630aa2f8ea1cda521f0cfc86e7db2f1a0b0160dd96fcc87199bc4293
|
7
|
+
data.tar.gz: 62518f5ee347b3e799a8531d4f742d7a6d08ad11e0bbdc9242697e57c05d0e2209615e571a558f8cc08a533cf724b444d30cd40e14e0f970518dc478454d769e
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
TheWizardOfApi
|
1
|
+
TheWizardOfApi
|
2
2
|
===
|
3
3
|
|
4
4
|
[Wizard of Oz experiments](http://en.wikipedia.org/wiki/Wizard_of_Oz_experiment) help early on in the [design of novel services](http://www.deaneckles.com/blog/305_aardvarks-use-of-wizard-of-oz-prototyping-to-design-their-social-interfaces/).
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Feature: Shows Request Body
|
2
|
+
In order to create a response for entity creation requests
|
3
|
+
As The Wizard
|
4
|
+
I want to see the request body
|
5
|
+
|
6
|
+
Scenario: Receiving a POST from a form
|
7
|
+
Given TheWizardOfApi is running in the browser
|
8
|
+
When someone else makes a POST request to "/api" these values in a form:
|
9
|
+
"""
|
10
|
+
---
|
11
|
+
user[email]: john@smith.com
|
12
|
+
user[password]: P@ssw0rd
|
13
|
+
user[password_confirmation]: P@ssw0rd
|
14
|
+
"""
|
15
|
+
Then I should see:
|
16
|
+
"""
|
17
|
+
POST /api HTTP/1.1
|
18
|
+
Accept: */*
|
19
|
+
User-Agent: curl
|
20
|
+
Host: localhost:3000
|
21
|
+
Content-Type: application/x-www-form-urlencoded
|
22
|
+
|
23
|
+
user[email]=john@smith.com&user[password]=P@ssw0rd&user[password_confirmation]=P@ssw0rd
|
24
|
+
"""
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
When(/^someone else makes a POST request to "(.*?)" these values in a form:$/) do |path, string|
|
4
|
+
last_response = avoid_timing_errors do
|
5
|
+
dorothy_request(path, :post,
|
6
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
7
|
+
"Body" => URI::encode_www_form(YAML::load(string)))
|
8
|
+
end
|
9
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -25,9 +25,21 @@ module TheWizardOfApiHelper
|
|
25
25
|
wait_for_log_to_contain(thin_log_path,"Listening on")
|
26
26
|
end
|
27
27
|
|
28
|
-
def dorothy_request(path)
|
28
|
+
def dorothy_request(path, method = :get, headers = {})
|
29
29
|
# Curl or new webkit process, or rest client
|
30
|
-
|
30
|
+
start_command = case method
|
31
|
+
when :get
|
32
|
+
curl("dorothy", "http://localhost:3000#{path}")
|
33
|
+
when :post
|
34
|
+
body = headers.fetch("Body") { |k| raise ArgumentError, "Sorry, POST requests require a \"Body\" value" }
|
35
|
+
content_type = headers.fetch("Content-Type") { |k| raise ArgumentError, "Sorry, POST request require a \"Content-Type\" value" }
|
36
|
+
|
37
|
+
curl("dorothy", "-X POST -d #{body.inspect} -H \"Content-Type: #{content_type}\" http://localhost:3000#{path}")
|
38
|
+
else
|
39
|
+
pending
|
40
|
+
end
|
41
|
+
|
42
|
+
run_process(start: start_command,
|
31
43
|
stop: cleanup_curl("dorothy"))
|
32
44
|
|
33
45
|
wait_for_log_to_contain(log_path("dorothy"))
|
@@ -19,6 +19,9 @@ module TimingErrorHelper
|
|
19
19
|
rescue Errno::ECONNREFUSED => e
|
20
20
|
debug(',')
|
21
21
|
retry
|
22
|
+
rescue Capybara::Webkit::NodeNotAttachedError => e
|
23
|
+
debug('?')
|
24
|
+
retry
|
22
25
|
rescue Capybara::Webkit::InvalidResponseError => e
|
23
26
|
if e.message.include?("Unable to load URL")
|
24
27
|
debug('!')
|
@@ -47,4 +50,10 @@ module TimingErrorHelper
|
|
47
50
|
carefully.call
|
48
51
|
end
|
49
52
|
end
|
53
|
+
|
54
|
+
After = lambda do |scenario|
|
55
|
+
if scenario.failed? && !page.driver.error_messages.empty?
|
56
|
+
warn "Failed with #{page.driver.error_messages.inspect}"
|
57
|
+
end
|
58
|
+
end.freeze
|
50
59
|
end
|
data/lib/the_wizard_of_api.rb
CHANGED
data/public/index.html
CHANGED
@@ -31,12 +31,27 @@
|
|
31
31
|
});
|
32
32
|
|
33
33
|
client.subscribe("/api", function(message){
|
34
|
-
request = [
|
34
|
+
var request = [
|
35
35
|
formatFirstLine(message),
|
36
36
|
formatLine("Accept", message, "HTTP_ACCEPT"),
|
37
37
|
formatLine("User-Agent", message, "HTTP_USER_AGENT"),
|
38
38
|
formatLine("Host", message, "HTTP_HOST")
|
39
|
-
|
39
|
+
];
|
40
|
+
|
41
|
+
if (message["CONTENT_TYPE"]) {
|
42
|
+
request.push(formatLine("Content-Type", message, "CONTENT_TYPE"));
|
43
|
+
}
|
44
|
+
|
45
|
+
if (message["Body"] && message["Body"].length > 0) {
|
46
|
+
request.push("");
|
47
|
+
|
48
|
+
try {
|
49
|
+
var uriDecodedBody = decodeURIComponent(message["Body"]);
|
50
|
+
request.push(uriDecodedBody);
|
51
|
+
} catch(e) {
|
52
|
+
request.push(message["Body"]);
|
53
|
+
}
|
54
|
+
}
|
40
55
|
|
41
56
|
document.body.querySelector("form").insertAdjacentHTML("beforeBegin","<pre>"+request.join("\n")+"</pre>")
|
42
57
|
});
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_wizard_of_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Buxton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faye
|
@@ -235,8 +235,10 @@ files:
|
|
235
235
|
- README.md
|
236
236
|
- Rakefile
|
237
237
|
- features/javascript_frontend.feature
|
238
|
+
- features/post_data.feature
|
238
239
|
- features/readme.feature
|
239
240
|
- features/step_definitions/javascript_frontend_steps.rb
|
241
|
+
- features/step_definitions/post_data_steps.rb
|
240
242
|
- features/step_definitions/readme_steps.rb
|
241
243
|
- features/step_definitions/streaming_requests_to_the_throne_room_steps.rb
|
242
244
|
- features/streaming_requests_to_the_throne_room.feature
|
@@ -278,8 +280,10 @@ specification_version: 4
|
|
278
280
|
summary: Enables a human-wizard to craft each response for a yet unimplemented API.
|
279
281
|
test_files:
|
280
282
|
- features/javascript_frontend.feature
|
283
|
+
- features/post_data.feature
|
281
284
|
- features/readme.feature
|
282
285
|
- features/step_definitions/javascript_frontend_steps.rb
|
286
|
+
- features/step_definitions/post_data_steps.rb
|
283
287
|
- features/step_definitions/readme_steps.rb
|
284
288
|
- features/step_definitions/streaming_requests_to_the_throne_room_steps.rb
|
285
289
|
- features/streaming_requests_to_the_throne_room.feature
|