capybara-json 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +8 -1
- data/VERSION +1 -1
- data/capybara-json.gemspec +5 -5
- data/lib/capybara/httpclient_json/driver.rb +8 -8
- data/lib/capybara/json/driver/base.rb +1 -1
- data/lib/capybara/rack_test_json/client.rb +8 -4
- data/lib/capybara/rack_test_json/driver.rb +8 -5
- data/spec/capybara/httpclient_json/driver_spec.rb +6 -0
- data/spec/capybara/json_spec.rb +7 -7
- data/spec/capybara/rack_test_json/driver_spec.rb +6 -0
- data/spec/support/driver_examples.rb +10 -2
- data/spec/support/json_test_app.rb +2 -2
- metadata +87 -32
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.2.1
|
2
|
+
* ENHANCEMENT
|
3
|
+
* options to switch redirect
|
4
|
+
|
5
|
+
## 0.2.0
|
6
|
+
* stop using capybara/rack_test/driver
|
7
|
+
|
1
8
|
## 0.1.2
|
2
9
|
* BUGFIX
|
3
10
|
* I forgot to add get! etc to Capybara::DSL
|
@@ -22,4 +29,4 @@
|
|
22
29
|
|
23
30
|
## 0.0.1
|
24
31
|
* ENHANCEMENT
|
25
|
-
* create :rack_test_json driver
|
32
|
+
* create :rack_test_json driver
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/capybara-json.gemspec
CHANGED
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.authors = ["okitan"]
|
6
6
|
s.email = ["okitakunio@gmail.com"]
|
7
7
|
s.homepage = "http://github.com/okitan/capybara-json"
|
8
|
-
s.summary = %q{for testing json-api
|
9
|
-
s.description = %q{for testing json-api
|
8
|
+
s.summary = %q{for testing json-api}
|
9
|
+
s.description = %q{for testing json-api}
|
10
10
|
|
11
11
|
s.rubyforge_project = "capybara-json"
|
12
12
|
|
@@ -16,12 +16,12 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
|
18
18
|
s.add_runtime_dependency "capybara"
|
19
|
-
s.add_runtime_dependency "httpclient"
|
20
|
-
s.add_runtime_dependency "multi_json"
|
19
|
+
s.add_runtime_dependency "httpclient", "~> 2.2"
|
20
|
+
s.add_runtime_dependency "multi_json", "~> 1.3"
|
21
21
|
|
22
22
|
# for testing
|
23
23
|
s.add_development_dependency "rake"
|
24
|
-
s.add_development_dependency "rspec", "~> 2.8
|
24
|
+
s.add_development_dependency "rspec", "~> 2.8"
|
25
25
|
s.add_development_dependency "sinatra"
|
26
26
|
s.add_development_dependency "thin"
|
27
27
|
s.add_development_dependency "yajl-ruby"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'httpclient'
|
2
2
|
|
3
3
|
class Capybara::HTTPClientJson::Driver < Capybara::Json::Driver::Base
|
4
|
-
attr_reader :app, :
|
4
|
+
attr_reader :app, :options, :current_url, :response, :cookies
|
5
5
|
|
6
6
|
def client
|
7
7
|
unless @client
|
@@ -19,8 +19,8 @@ class Capybara::HTTPClientJson::Driver < Capybara::Json::Driver::Base
|
|
19
19
|
@client
|
20
20
|
end
|
21
21
|
|
22
|
-
def initialize(app)
|
23
|
-
@app = app
|
22
|
+
def initialize(app, options = {})
|
23
|
+
@app, @options = app, { :follow_redirect => true }.merge(options)
|
24
24
|
@rack_server = Capybara::Server.new(@app)
|
25
25
|
@rack_server.boot if Capybara.run_server
|
26
26
|
end
|
@@ -34,7 +34,7 @@ class Capybara::HTTPClientJson::Driver < Capybara::Json::Driver::Base
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def body
|
37
|
-
MultiJson.
|
37
|
+
MultiJson.load(source) || {}
|
38
38
|
end
|
39
39
|
|
40
40
|
def response_headers
|
@@ -42,18 +42,18 @@ class Capybara::HTTPClientJson::Driver < Capybara::Json::Driver::Base
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def get(url, params = {}, headers = {})
|
45
|
-
process :get, url, params, headers,
|
45
|
+
process :get, url, params, headers, options[:follow_redirect]
|
46
46
|
end
|
47
47
|
alias visit get
|
48
48
|
|
49
49
|
def post(url, json, headers = {})
|
50
|
-
json = MultiJson.
|
50
|
+
json = MultiJson.dump(json) unless json.is_a?(String)
|
51
51
|
headers['Content-Type'] = "application/json; charset=#{json.encoding.to_s.downcase}"
|
52
|
-
process :post, url, json, headers,
|
52
|
+
process :post, url, json, headers, options[:follow_redirect]
|
53
53
|
end
|
54
54
|
|
55
55
|
def put(url, json, headers = {})
|
56
|
-
json = MultiJson.
|
56
|
+
json = MultiJson.dump(json) unless json.is_a?(String)
|
57
57
|
headers['Content-Type'] = "application/json; charset=#{json.encoding.to_s.downcase}"
|
58
58
|
process :put, url, json, headers
|
59
59
|
end
|
@@ -4,17 +4,21 @@ module Capybara::RackTestJson
|
|
4
4
|
class Client
|
5
5
|
include Rack::Test::Methods
|
6
6
|
|
7
|
-
attr_accessor :app
|
7
|
+
attr_accessor :app, :options
|
8
8
|
|
9
|
-
def initialize(app)
|
10
|
-
@app = app
|
9
|
+
def initialize(app, options)
|
10
|
+
@app, @options = app, options
|
11
11
|
end
|
12
12
|
|
13
13
|
%w[ get post put delete ].each do |method|
|
14
14
|
module_eval %{
|
15
15
|
def #{method}(uri, params = {}, env = {}, &block)
|
16
16
|
env.merge(:method => "#{method.upcase}", :params => params)
|
17
|
-
|
17
|
+
if options[:follow_redirect]
|
18
|
+
request_with_follow_redirect(uri, env, &block)
|
19
|
+
else
|
20
|
+
request(uri, env)
|
21
|
+
end
|
18
22
|
end
|
19
23
|
}
|
20
24
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
class Capybara::RackTestJson::Driver < Capybara::Json::Driver::Base
|
2
|
-
|
3
|
-
|
2
|
+
attr_reader :app, :options
|
3
|
+
|
4
|
+
def initialize(app, options = {})
|
5
|
+
@app, @options = app, { :follow_redirect => true }.merge(options)
|
4
6
|
end
|
5
7
|
|
6
8
|
def client
|
7
|
-
@client ||= Capybara::RackTestJson::Client.new(
|
9
|
+
@client ||= Capybara::RackTestJson::Client.new(app, options)
|
8
10
|
end
|
9
11
|
|
10
12
|
def last_request
|
@@ -14,6 +16,7 @@ class Capybara::RackTestJson::Driver < Capybara::Json::Driver::Base
|
|
14
16
|
def last_response
|
15
17
|
client.last_response
|
16
18
|
end
|
19
|
+
alias response last_response
|
17
20
|
|
18
21
|
%w[ get delete ].each do |method|
|
19
22
|
class_eval %{
|
@@ -31,7 +34,7 @@ class Capybara::RackTestJson::Driver < Capybara::Json::Driver::Base
|
|
31
34
|
%w[ post put ].each do |method|
|
32
35
|
class_eval %{
|
33
36
|
def #{method}(path, json, env = {})
|
34
|
-
json = MultiJson.
|
37
|
+
json = MultiJson.dump(json) unless json.is_a?(String)
|
35
38
|
|
36
39
|
request_env = {
|
37
40
|
'CONTENT_LENGTH' => json.size,
|
@@ -57,7 +60,7 @@ class Capybara::RackTestJson::Driver < Capybara::Json::Driver::Base
|
|
57
60
|
end
|
58
61
|
|
59
62
|
def body
|
60
|
-
MultiJson.
|
63
|
+
MultiJson.load(source) || {}
|
61
64
|
end
|
62
65
|
|
63
66
|
def response_headers
|
@@ -19,3 +19,9 @@ describe klass do
|
|
19
19
|
it_should_behave_like 'driver for client error'
|
20
20
|
it_should_behave_like 'driver for server error'
|
21
21
|
end
|
22
|
+
|
23
|
+
describe klass do
|
24
|
+
before { @driver = described_class.new(JsonTestApp, :follow_redirect => false) }
|
25
|
+
|
26
|
+
it_should_behave_like "driver not to follow redirect"
|
27
|
+
end
|
data/spec/capybara/json_spec.rb
CHANGED
@@ -9,36 +9,36 @@ require 'spec_helper'
|
|
9
9
|
|
10
10
|
describe Capybara::Json do
|
11
11
|
include described_class
|
12
|
-
|
12
|
+
|
13
13
|
before(:all) do
|
14
14
|
Capybara.app = JsonTestApp
|
15
15
|
Capybara.current_driver = driver
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
after(:all) do
|
19
19
|
Capybara.app = nil
|
20
20
|
Capybara.current_driver = Capybara.default_driver
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
%w[ get get! delete delete! ].each do |method|
|
24
24
|
it "register #{method}" do
|
25
25
|
__send__(method, '/')
|
26
26
|
body.should == { 'Hello world!' => 'Hello world!' }
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
%w[ post post! put put! ].each do |method|
|
31
31
|
it "register #{method}" do
|
32
32
|
__send__(method, '/', {})
|
33
33
|
body.should == { 'Hello world!' => 'Hello world!' }
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "#{method} send json" do
|
37
37
|
json = { "some" => "args" }
|
38
38
|
__send__(method, '/env', json)
|
39
|
-
|
39
|
+
|
40
40
|
body['content_type'].should =~ %r"application/json"
|
41
|
-
body['rack.input'].should == MultiJson.
|
41
|
+
body['rack.input'].should == MultiJson.dump(json)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -19,3 +19,9 @@ describe klass do
|
|
19
19
|
it_should_behave_like 'driver for client error'
|
20
20
|
it_should_behave_like 'driver for server error'
|
21
21
|
end
|
22
|
+
|
23
|
+
describe klass do
|
24
|
+
before { @driver = described_class.new(JsonTestApp, :follow_redirect => false) }
|
25
|
+
|
26
|
+
it_should_behave_like "driver not to follow redirect"
|
27
|
+
end
|
@@ -54,6 +54,14 @@ shared_examples_for "driver with redirect support" do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
shared_examples_for "driver not to follow redirect" do
|
58
|
+
it "should not follow redirect" do
|
59
|
+
@driver.get "/redirect"
|
60
|
+
@driver.status_code.should == 302
|
61
|
+
URI.parse(@driver.current_url).path.should == "/redirect"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
57
65
|
%w[ post put ].each do |method|
|
58
66
|
shared_examples_for "driver to #{method} json" do
|
59
67
|
it 'should set content type as json to request' do
|
@@ -65,14 +73,14 @@ end
|
|
65
73
|
json = { :some => :args }
|
66
74
|
|
67
75
|
@driver.__send__(method, '/env', json)
|
68
|
-
@driver.body['content_length'].to_i.should == MultiJson.
|
76
|
+
@driver.body['content_length'].to_i.should == MultiJson.dump(json).length
|
69
77
|
end
|
70
78
|
|
71
79
|
it 'should post body' do
|
72
80
|
json = { :some => :args }
|
73
81
|
|
74
82
|
@driver.__send__(method, '/env', json)
|
75
|
-
@driver.body['rack.input'].should == MultiJson.
|
83
|
+
@driver.body['rack.input'].should == MultiJson.dump(json)
|
76
84
|
end
|
77
85
|
end
|
78
86
|
end
|
@@ -21,8 +21,8 @@ class JsonTestApp < TestApp
|
|
21
21
|
def invoke
|
22
22
|
res = catch(:halt) { yield }
|
23
23
|
|
24
|
-
res = [ MultiJson.
|
25
|
-
res = [ MultiJson.
|
24
|
+
res = [ MultiJson.dump(res => res) ] if Fixnum === res or String === res
|
25
|
+
res = [ MultiJson.dump(res) ] if Hash === res
|
26
26
|
if Array === res and Fixnum === res.first
|
27
27
|
status(res.shift)
|
28
28
|
body(res.pop)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capybara
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,32 +21,47 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: httpclient
|
27
|
-
requirement: &70155556457240 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
27
|
- - ! '>='
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: httpclient
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.2'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.2'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: multi_json
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
|
-
- -
|
51
|
+
- - ~>
|
42
52
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
53
|
+
version: '1.3'
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rake
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,21 +69,31 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: rspec
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ~>
|
64
84
|
- !ruby/object:Gem::Version
|
65
|
-
version: 2.8
|
85
|
+
version: '2.8'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.8'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: sinatra
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,10 +101,15 @@ dependencies:
|
|
76
101
|
version: '0'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
80
110
|
- !ruby/object:Gem::Dependency
|
81
111
|
name: thin
|
82
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
83
113
|
none: false
|
84
114
|
requirements:
|
85
115
|
- - ! '>='
|
@@ -87,10 +117,15 @@ dependencies:
|
|
87
117
|
version: '0'
|
88
118
|
type: :development
|
89
119
|
prerelease: false
|
90
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
91
126
|
- !ruby/object:Gem::Dependency
|
92
127
|
name: yajl-ruby
|
93
|
-
requirement:
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
94
129
|
none: false
|
95
130
|
requirements:
|
96
131
|
- - ! '>='
|
@@ -98,10 +133,15 @@ dependencies:
|
|
98
133
|
version: '0'
|
99
134
|
type: :development
|
100
135
|
prerelease: false
|
101
|
-
version_requirements:
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
102
142
|
- !ruby/object:Gem::Dependency
|
103
143
|
name: autowatchr
|
104
|
-
requirement:
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
105
145
|
none: false
|
106
146
|
requirements:
|
107
147
|
- - ! '>='
|
@@ -109,10 +149,15 @@ dependencies:
|
|
109
149
|
version: '0'
|
110
150
|
type: :development
|
111
151
|
prerelease: false
|
112
|
-
version_requirements:
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
113
158
|
- !ruby/object:Gem::Dependency
|
114
159
|
name: pry
|
115
|
-
requirement:
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
116
161
|
none: false
|
117
162
|
requirements:
|
118
163
|
- - ! '>='
|
@@ -120,10 +165,15 @@ dependencies:
|
|
120
165
|
version: '0'
|
121
166
|
type: :development
|
122
167
|
prerelease: false
|
123
|
-
version_requirements:
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
124
174
|
- !ruby/object:Gem::Dependency
|
125
175
|
name: tapp
|
126
|
-
requirement:
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
127
177
|
none: false
|
128
178
|
requirements:
|
129
179
|
- - ! '>='
|
@@ -131,8 +181,13 @@ dependencies:
|
|
131
181
|
version: '0'
|
132
182
|
type: :development
|
133
183
|
prerelease: false
|
134
|
-
version_requirements:
|
135
|
-
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ! '>='
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
description: for testing json-api
|
136
191
|
email:
|
137
192
|
- okitakunio@gmail.com
|
138
193
|
executables: []
|
@@ -186,10 +241,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
241
|
version: '0'
|
187
242
|
requirements: []
|
188
243
|
rubyforge_project: capybara-json
|
189
|
-
rubygems_version: 1.8.
|
244
|
+
rubygems_version: 1.8.24
|
190
245
|
signing_key:
|
191
246
|
specification_version: 3
|
192
|
-
summary: for testing json-api
|
247
|
+
summary: for testing json-api
|
193
248
|
test_files:
|
194
249
|
- spec/capybara/httpclient_json/driver_spec.rb
|
195
250
|
- spec/capybara/json_spec.rb
|