the_wizard_of_api 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf9b2e9d6271e57b48f843c4acfbd9d093b36106
4
- data.tar.gz: 590cb0698da72963df534396fea4d9624a14cc12
3
+ metadata.gz: 6439a0d26b20a6bec2b1e1feb9cea37b06b2945e
4
+ data.tar.gz: 2f796b30721613db65a3b5be5e4ea359750408d4
5
5
  SHA512:
6
- metadata.gz: cc3fbaa708376e3bdd32ef5188ee634c2036085d49d5c77019a47039eb2faa79a26f41d422409daf79c1d1395beb6f864d7ae0de2da8c88a6d0291e66131c9da
7
- data.tar.gz: dfd5d921116c7a34601c1d83129418516dcb3cbab6bca118e1fb587a098e769497aba6304c1c28ba02e609c9c31bc5f11d1847a61ec60dbabd049eaf794ee3f2
6
+ metadata.gz: a57a5274c7ff943dde2ac37948a11d77910f302e44975c5982ae318d744121c586cfee1c630aa2f8ea1cda521f0cfc86e7db2f1a0b0160dd96fcc87199bc4293
7
+ data.tar.gz: 62518f5ee347b3e799a8531d4f742d7a6d08ad11e0bbdc9242697e57c05d0e2209615e571a558f8cc08a533cf724b444d30cd40e14e0f970518dc478454d769e
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- TheWizardOfApi ![Build Status](https://travis-ci.org/cpb/the_wizard_of_api.png)
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
@@ -15,6 +15,7 @@ require 'debugging_pry_helper'
15
15
  After(&DebuggingPryHelper::After)
16
16
 
17
17
  require 'timing_error_helper'
18
+ After(&TimingErrorHelper::After)
18
19
 
19
20
  require 'process_helper'
20
21
  After(&ProcessHelper::After)
@@ -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
- run_process(start: curl("dorothy", "http://localhost:3000#{path}"),
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
@@ -52,6 +52,7 @@ module TheWizardOfApi
52
52
  body.call [" " * 1024]
53
53
  }
54
54
 
55
+ env.merge!("Body" => env["rack.input"].read)
55
56
  client.publish('/api', env)
56
57
 
57
58
  callback = env['async.callback']
@@ -1,3 +1,3 @@
1
1
  module TheWizardOfApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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.1.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-12 00:00:00.000000000 Z
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