goodall 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1,2 +1,3 @@
1
1
  rvm --create use 1.9.3@goodall
2
2
  #rvm --create use ree@goodall
3
+ #rvm --create use 2.0.0@goodall
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.0.0
3
4
  - 1.9.3
4
5
  - 1.9.2
5
6
  - rbx-18mode
data/README.md CHANGED
@@ -124,6 +124,9 @@ For cucumber, the best way is to have often-reused methods in each scenario, and
124
124
  Given /^I get \"(.+)\"$/ do |path|
125
125
  get(path)
126
126
  Goodall.document_request(:get, path)
127
+ # If this were a POST, we would so something like this:
128
+ #
129
+ # Goodall.document_request(:post, path, posted_data)
127
130
  end
128
131
 
129
132
  Given /^the response should be valid json$/ do
@@ -167,9 +170,16 @@ for the get/post/put/delete/patch verbs:
167
170
  # spec_helper.rb
168
171
 
169
172
  def documented_get(*args)
173
+
170
174
  Goodall.document_request(:get, args[0])
175
+ # If this were a POST, we would so something like this:
176
+ #
177
+ # Goodall.document_request(:post, args[0], posted_data)
178
+
171
179
  get_response = get(args)
180
+
172
181
  Goodall.document_response(response.body)
182
+
173
183
  get_response
174
184
  end
175
185
 
@@ -300,8 +310,22 @@ handled, and self is the **class** of the handler.
300
310
 
301
311
  ## Methods
302
312
 
303
- Documented with rdoc.
313
+ These are the method you will use most with Goodall.
314
+
315
+ #### Goodall.document_request(method, path, payload=nil)
316
+
317
+ Document a request.
304
318
 
319
+ * :method - a symbol of the verb: :get, :post, :put, :delete, :patch
320
+ * :path - a string of the path (URL/URI) of the request
321
+ * :payload - the parameters sent, e.g. post body. Usually a hash. For things with no payload, like a GET, it can be nil.
322
+
323
+ #### Goodalldocument_response(payload)
324
+
325
+ Document a response.
326
+
327
+ * :payload - the data returned from the request, e.g. response.body. "payload" will be run through the current handler and be pretty-printed to the output file.
328
+
305
329
  ## Contributing
306
330
 
307
331
  1. Fork it
data/goodall.gemspec CHANGED
@@ -20,6 +20,7 @@ write your tests.}
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_dependency "multi_json", ">= 1.6"
23
+ spec.add_dependency "tolerate_json"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.3"
25
26
  spec.add_development_dependency "rake"
@@ -1,9 +1,11 @@
1
1
  require 'multi_json'
2
2
  require "goodall/handler/base"
3
+ require 'tolerate_json'
3
4
 
4
5
  class Goodall
5
6
  module Handler
6
7
  class Json < Base
8
+ include TolerateJson
7
9
  Goodall.register_handler :json, self
8
10
 
9
11
  def parse_payload(payload)
@@ -18,47 +20,15 @@ class Goodall
18
20
  else
19
21
  payload
20
22
  end
21
-
23
+
22
24
  # detect "pretty" json by seeing if there are CRs in here
23
25
  if (json = MultiJson.dump(payload)) =~ /\n/
24
26
  json
25
27
  else
26
- pretty_print(json)
28
+ pretty_print_json(json)
27
29
  # json
28
30
  end
29
31
  end
30
-
31
-
32
- private
33
-
34
- # We're doing this outselves because it's too unreliable detecting which parsers support pretty-print and whoch one don't. If this method is broken, at least it will be *consitently* broken.
35
- def pretty_print(json)
36
- return json if json.to_s.size < 1
37
-
38
- str = json.to_s.gsub("},", "},\n").gsub("],", "],\n").gsub("{[", "{\n[").gsub("}]", "}\n]").gsub("[{", "[\n{").gsub("]}", "]\n}").gsub("{\"", "{\n\"").gsub("\"}", "\"\n}").gsub("\",\"", "\",\n\"")
39
-
40
- if str.match(/[^\n]\}$/)
41
- str.gsub!(/\}$/, "\n}")
42
- end
43
-
44
- output = []
45
-
46
- indent_level = 0
47
- str.split("\n").each do |s|
48
- indent_level -= 1 if ["]", "}"].include?(s.split('').first) && indent_level > 0
49
- output << (" "*indent_level) + s
50
- if ["{", "["].include?(s.split('').last)
51
- indent_level += 1
52
- next
53
- end
54
-
55
- if ["{", "["].include?(s.split('').first)
56
- indent_level += 1
57
- next
58
- end
59
- end
60
- output.join("\n")
61
- end
62
32
  end
63
33
  end
64
34
  end
@@ -1,3 +1,3 @@
1
1
  class Goodall
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -8,12 +8,12 @@ describe Goodall::Handler::Json do
8
8
  context 'string is valid json' do
9
9
 
10
10
  let(:valid_json_string) { '{"foo":"bar"}' }
11
-
11
+
12
12
  it 'should return it as pretty-printed json' do
13
13
  expect(
14
14
  subject.parse_payload(valid_json_string)
15
- ).to eq("{\n \"foo\":\"bar\"\n}")
16
- end
15
+ ).to eq("{\n \"foo\":\"bar\"\n}\n")
16
+ end
17
17
  end
18
18
  context 'the string not valid json' do
19
19
 
@@ -34,7 +34,7 @@ describe Goodall::Handler::Json do
34
34
  it 'should return it as pretty-printed json' do
35
35
  expect(
36
36
  subject.parse_payload(payload)
37
- ).to eq("{\n \"foo\":\"bar\"\n}")
37
+ ).to eq("{\n \"foo\":\"bar\"\n}\n")
38
38
  end
39
39
  end
40
40
  end
metadata CHANGED
@@ -1,93 +1,105 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: goodall
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Matthew Nielsen
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-08-30 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-08-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: multi_json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :runtime
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
24
25
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 1
31
- - 6
32
- version: "1.6"
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: tolerate_json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
33
38
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: bundler
37
39
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
39
41
  none: false
40
- requirements:
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
41
51
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 9
44
- segments:
45
- - 1
46
- - 3
47
- version: "1.3"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
48
54
  type: :development
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: rake
52
55
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
54
65
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
62
70
  type: :development
63
- version_requirements: *id003
64
- - !ruby/object:Gem::Dependency
65
- name: rspec
66
71
  prerelease: false
67
- requirement: &id004 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
68
81
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 23
73
- segments:
74
- - 2
75
- - 10
76
- version: "2.10"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '2.10'
77
86
  type: :development
78
- version_requirements: *id004
79
- description: |-
80
- An easy interface for documenting your API while you
81
- write your tests.
82
- email:
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '2.10'
94
+ description: ! 'An easy interface for documenting your API while you
95
+
96
+ write your tests.'
97
+ email:
83
98
  - xunker@pyxidis.org
84
99
  executables: []
85
-
86
100
  extensions: []
87
-
88
101
  extra_rdoc_files: []
89
-
90
- files:
102
+ files:
91
103
  - .gitignore
92
104
  - .rspec
93
105
  - .rvmrc
@@ -113,39 +125,34 @@ files:
113
125
  - spec/lib/goodall_spec.rb
114
126
  - spec/spec_helper.rb
115
127
  homepage: http://github.com/xunker/goodall
116
- licenses:
128
+ licenses:
117
129
  - MIT
118
130
  post_install_message:
119
131
  rdoc_options: []
120
-
121
- require_paths:
132
+ require_paths:
122
133
  - lib
123
- required_ruby_version: !ruby/object:Gem::Requirement
134
+ required_ruby_version: !ruby/object:Gem::Requirement
124
135
  none: false
125
- requirements:
126
- - - ">="
127
- - !ruby/object:Gem::Version
128
- hash: 3
129
- segments:
130
- - 0
131
- version: "0"
132
- required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
141
  none: false
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- hash: 3
138
- segments:
139
- - 0
140
- version: "0"
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
141
146
  requirements: []
142
-
143
147
  rubyforge_project:
144
148
  rubygems_version: 1.8.25
145
149
  signing_key:
146
150
  specification_version: 3
147
- summary: Goodall provides an easy interface for documenting your API while you write your tests. It is compatible with Rspec, Cucumber and test-unit, as well as others. Goodall is named after Jane Goodall who has spent her life observing and documenting the behviour of chimpanzees.
148
- test_files:
151
+ summary: Goodall provides an easy interface for documenting your API while you write
152
+ your tests. It is compatible with Rspec, Cucumber and test-unit, as well as others.
153
+ Goodall is named after Jane Goodall who has spent her life observing and documenting
154
+ the behviour of chimpanzees.
155
+ test_files:
149
156
  - spec/lib/goodall/handler/json_spec.rb
150
157
  - spec/lib/goodall_spec.rb
151
158
  - spec/spec_helper.rb