capybara-json 0.3.0.beta2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,8 @@ rvm:
2
2
  # - 1.8.7
3
3
  - 1.9.2
4
4
  - 1.9.3
5
- - ruby-head
5
+ # - ruby-head
6
6
  gemfile:
7
7
  - Gemfile
8
+ - Gemfile.capybara.lt.2.0
8
9
  - Gemfile.capybara.lt.1.0
@@ -1,8 +1,5 @@
1
- ## 0.3.0.beta2
2
- * Fix #8
3
-
4
- ## 0.3.0.beta1
5
- * Capybara 2.x support, but test not working now... (thanks to gkellogg)
1
+ ## 0.3.0
2
+ * Capybara 2.x support (Thanks to @sonots, @gkellogg)
6
3
 
7
4
  ## 0.2.4
8
5
  * Added __FILE__ and __LINE__ so that pry can find generated methods (thanks to @mad_p)
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in capybara-json.gemspec
4
+ gem 'capybara', '< 2.0.0'
5
+ gemspec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # capybara-json [![Build Status](https://secure.travis-ci.org/okitan/capybara-json.png?branch=master)](http://travis-ci.org/okitan/capybara-json) [![Dependency Status](https://gemnasium.com/okitan/capybara-json.png)](https://gemnasium.com/okitan/capybara-json)
2
2
 
3
- testing ruby: 1.9.2, 1.9.3 and ruby-head; Capybara: < 1.0 and > 1.0
3
+ testing ruby: 1.9.2, 1.9.3; Capybara: 0.4.x, 1.1.x, 2.0.x
4
4
 
5
5
  ## About capybara-json
6
6
 
@@ -15,12 +15,15 @@ require 'capybara/json'
15
15
  include Capybara::Json
16
16
 
17
17
  Capybara.current_driver = :rack_test_json
18
+ Capybara.app = MyRackApp
18
19
  post '/', { "this is" => "json" } # POST '/'
19
20
  json #=> parsed json response
20
21
  source #=> raw response body
21
22
  get '/errors/400'
22
23
  status_code #=> 400
23
24
  get! '/errors' #=> raise Capybara::Json::Error
25
+ get '/errors', {}, { 'header' => '' } # request headers
26
+ response_headers #=> response headers
24
27
 
25
28
  Capybara.current_driver = :httpclient_json
26
29
  Capybara.app_host = 'http://example.com'
@@ -30,4 +33,6 @@ source #=> raw response body
30
33
  get '/errors/400'
31
34
  status_code #=> 400
32
35
  get! '/errors' #=> raise Capybara::Json::Error
36
+ get '/errors', {}, { 'header' => '' } # request headers
37
+ response_headers #=> response headers
33
38
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0.beta2
1
+ 0.3.0
@@ -30,4 +30,5 @@ Gem::Specification.new do |s|
30
30
  # for debug
31
31
  s.add_development_dependency "pry"
32
32
  s.add_development_dependency "tapp"
33
+ s.add_development_dependency "pry-debugger"
33
34
  end
@@ -11,31 +11,10 @@ module Capybara
11
11
 
12
12
  def self.included(base)
13
13
  base.__send__(:include, to_include) unless base < to_include
14
- base.extend(self)
15
- end
16
-
17
- %w[ get get! delete delete! ].each do |method|
18
- module_eval <<-DEF, __FILE__, __LINE__ + 1
19
- def #{method}(path, params = {}, env = {})
20
- page.driver.#{method}(path, params, env)
21
- end
22
- DEF
23
- end
24
-
25
- %w[ post post! put put! ].each do |method|
26
- module_eval <<-DEF, __FILE__, __LINE__ + 1
27
- def #{method}(path, json, env = {})
28
- page.driver.#{method}(path, json, env)
29
- end
30
- DEF
31
- end
32
-
33
- %w[ raw_json json ].each do |method|
34
- define_method(method) do
35
- page.driver.__send__(method)
36
- end
14
+ base.__send__(:include, ::Capybara::Json::Dsl)
37
15
  end
38
16
 
17
+ autoload :Dsl, 'capybara/json/dsl'
39
18
  autoload :Error, 'capybara/json/error'
40
19
 
41
20
  module Driver
@@ -0,0 +1,31 @@
1
+ module Capybara
2
+ module Json
3
+ module Dsl
4
+ def self.included(base)
5
+ base.extend(self)
6
+ end
7
+
8
+ %w[ get get! delete delete! ].each do |method|
9
+ module_eval <<-DEF, __FILE__, __LINE__ + 1
10
+ def #{method}(path, params = {}, env = {})
11
+ page.driver.#{method}(path, params, env)
12
+ end
13
+ DEF
14
+ end
15
+
16
+ %w[ post post! put put! ].each do |method|
17
+ module_eval <<-DEF, __FILE__, __LINE__ + 1
18
+ def #{method}(path, json, env = {})
19
+ page.driver.#{method}(path, json, env)
20
+ end
21
+ DEF
22
+ end
23
+
24
+ %w[ raw_json json source body status_code response_headers ].each do |method|
25
+ define_method(method) do
26
+ page.driver.__send__(method)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::HTTPClientJson do
4
+ before { @driver = :httpclient_json }
5
+
6
+ it_behaves_like 'dsl'
7
+ it_behaves_like "dsl with redirect support"
8
+ it_behaves_like "dsl not to follow redirect"
9
+ end
@@ -6,40 +6,4 @@ require 'spec_helper'
6
6
  Capybara.drivers.should have_key(driver)
7
7
  end
8
8
  end
9
-
10
- describe Capybara::Json do
11
- include described_class
12
-
13
- before(:all) do
14
- Capybara.app = JsonTestApp
15
- Capybara.current_driver = driver
16
- end
17
-
18
- after(:all) do
19
- Capybara.app = nil
20
- Capybara.current_driver = Capybara.default_driver
21
- end
22
-
23
- %w[ get get! delete delete! ].each do |method|
24
- it "register #{method}" do
25
- __send__(method, '/')
26
- body.should == { 'Hello world!' => 'Hello world!' }
27
- end
28
- end
29
-
30
- %w[ post post! put put! ].each do |method|
31
- it "register #{method}" do
32
- __send__(method, '/', {})
33
- body.should == { 'Hello world!' => 'Hello world!' }
34
- end
35
-
36
- it "#{method} send json" do
37
- json = { "some" => "args" }
38
- __send__(method, '/env', json)
39
-
40
- body['content_type'].should =~ %r"application/json"
41
- body['rack.input'].should == MultiJson.dump(json)
42
- end
43
- end
44
- end
45
9
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::RackTestJson do
4
+ before { @driver = :rack_test_json }
5
+
6
+ it_behaves_like 'dsl'
7
+ it_behaves_like "dsl with redirect support"
8
+ it_behaves_like "dsl not to follow redirect"
9
+ end
@@ -1,12 +1,6 @@
1
- require 'capybara/spec/driver'
2
-
3
1
  # this code is written in capybara's spec/spec_helper
4
2
  alias :running :lambda
5
3
 
6
- [ 'driver', 'driver with header support' ].each do |shared|
7
- RSpec.world.shared_example_groups.delete(shared)
8
- end
9
-
10
4
  shared_examples_for 'driver' do
11
5
  describe '#visit' do
12
6
  it "should move to another page" do
@@ -64,6 +58,45 @@ shared_examples_for 'driver with custom header support' do
64
58
  end
65
59
  end
66
60
 
61
+ shared_examples_for "driver with status code support" do
62
+ it "should make the status code available through status_code" do
63
+ @driver.visit('/with_simple_html')
64
+ @driver.status_code.should == 200
65
+ end
66
+ end
67
+
68
+ shared_examples_for "driver with cookies support" do
69
+ describe "#reset!" do
70
+ it "should set and clean cookies" do
71
+ @driver.visit('/get_cookie')
72
+ @driver.body.should_not include('test_cookie')
73
+
74
+ @driver.visit('/set_cookie')
75
+ @driver.body.should include('Cookie set to test_cookie')
76
+
77
+ @driver.visit('/get_cookie')
78
+ @driver.body.should include('test_cookie')
79
+
80
+ @driver.reset!
81
+ @driver.visit('/get_cookie')
82
+ @driver.body.should_not include('test_cookie')
83
+ end
84
+ end
85
+ end
86
+
87
+ shared_examples_for "driver with infinite redirect detection" do
88
+ it "should follow 5 redirects" do
89
+ @driver.visit('/redirect/5/times')
90
+ @driver.body.should include('redirection complete')
91
+ end
92
+
93
+ it "should not follow more than 5 redirects" do
94
+ running do
95
+ @driver.visit('/redirect/6/times')
96
+ end.should raise_error(Capybara::InfiniteRedirectError)
97
+ end
98
+ end
99
+
67
100
  shared_examples_for "driver with redirect support" do
68
101
  it "should update current_url" do
69
102
  @driver.get "/redirect"
@@ -76,6 +109,7 @@ shared_examples_for "driver not to follow redirect" do
76
109
  @driver.get "/redirect"
77
110
  @driver.status_code.should == 302
78
111
  URI.parse(@driver.current_url).path.should == "/redirect"
112
+ URI.parse(@driver.response_headers["Location"]).path.should == "/redirect_again"
79
113
  end
80
114
  end
81
115
 
@@ -0,0 +1,77 @@
1
+ shared_context 'prepare_dsl' do
2
+ include Capybara::Json
3
+
4
+ before do
5
+ Capybara.app = JsonTestApp
6
+ Capybara.current_driver = @driver
7
+ @default_follow_redirect = page.driver.options[:follow_redirect]
8
+ end
9
+
10
+ after do
11
+ page.driver.options[:follow_redirect] = @default_follow_redirect
12
+ Capybara.app = nil
13
+ Capybara.current_driver = Capybara.default_driver
14
+ end
15
+ end
16
+
17
+ shared_examples_for 'dsl' do
18
+ include_context 'prepare_dsl'
19
+
20
+ %w[ get get! delete delete! ].each do |method|
21
+ it "register #{method}" do
22
+ __send__(method, '/')
23
+ body.should == { 'Hello world!' => 'Hello world!' }
24
+ end
25
+ end
26
+
27
+ %w[ post post! put put! ].each do |method|
28
+ it "register #{method}" do
29
+ __send__(method, '/', {})
30
+ body.should == { 'Hello world!' => 'Hello world!' }
31
+ end
32
+
33
+ it "#{method} send json" do
34
+ json = { "some" => "args" }
35
+ __send__(method, '/env', json)
36
+
37
+ body['content_type'].should =~ %r"application/json"
38
+ body['rack.input'].should == MultiJson.dump(json)
39
+ end
40
+ end
41
+
42
+ %w[ raw_json source ].each do |method|
43
+ it "register #{method}" do
44
+ get('/', {})
45
+ __send__(method).should == MultiJson.dump({ 'Hello world!' => 'Hello world!' })
46
+ end
47
+ end
48
+
49
+ %w[ json body ].each do |method|
50
+ it "register #{method}" do
51
+ get('/', {})
52
+ __send__(method).should == { 'Hello world!' => 'Hello world!' }
53
+ end
54
+ end
55
+ end
56
+
57
+ shared_examples_for 'dsl with redirect support' do
58
+ include_context 'prepare_dsl'
59
+
60
+ it "should update current_url" do
61
+ page.driver.options[:follow_redirect] = true
62
+ get "/redirect"
63
+ URI.parse(current_url).path.should == "/landed"
64
+ end
65
+ end
66
+
67
+ shared_examples_for "dsl not to follow redirect" do
68
+ include_context 'prepare_dsl'
69
+
70
+ it "should not follow redirect" do
71
+ page.driver.options[:follow_redirect] = false
72
+ get "/redirect"
73
+ status_code.should == 302
74
+ URI.parse(current_url).path.should == "/redirect"
75
+ URI.parse(response_headers["Location"]).path.should == "/redirect_again"
76
+ end
77
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.beta2
5
- prerelease: 6
4
+ version: 0.3.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - okitan
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-07 00:00:00.000000000 Z
12
+ date: 2013-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -187,6 +187,22 @@ dependencies:
187
187
  - - ! '>='
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: pry-debugger
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
190
206
  description: for testing json-api
191
207
  email:
192
208
  - okitakunio@gmail.com
@@ -203,6 +219,7 @@ files:
203
219
  - CHANGELOG.md
204
220
  - Gemfile
205
221
  - Gemfile.capybara.lt.1.0
222
+ - Gemfile.capybara.lt.2.0
206
223
  - README.md
207
224
  - Rakefile
208
225
  - VERSION
@@ -211,15 +228,19 @@ files:
211
228
  - lib/capybara/httpclient_json/driver.rb
212
229
  - lib/capybara/json.rb
213
230
  - lib/capybara/json/driver/base.rb
231
+ - lib/capybara/json/dsl.rb
214
232
  - lib/capybara/json/error.rb
215
233
  - lib/capybara/rack_test_json/client.rb
216
234
  - lib/capybara/rack_test_json/driver.rb
217
235
  - spec/capybara/httpclient_json/driver_spec.rb
236
+ - spec/capybara/httpclient_json/dsl_spec.rb
218
237
  - spec/capybara/json_spec.rb
219
238
  - spec/capybara/rack_test_json/driver_spec.rb
239
+ - spec/capybara/rack_test_json/dsl_spec.rb
220
240
  - spec/spec.watchr
221
241
  - spec/spec_helper.rb
222
242
  - spec/support/driver_examples.rb
243
+ - spec/support/dsl_examples.rb
223
244
  - spec/support/json_test_app.rb
224
245
  homepage: http://github.com/okitan/capybara-json
225
246
  licenses: []
@@ -236,9 +257,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
257
  required_rubygems_version: !ruby/object:Gem::Requirement
237
258
  none: false
238
259
  requirements:
239
- - - ! '>'
260
+ - - ! '>='
240
261
  - !ruby/object:Gem::Version
241
- version: 1.3.1
262
+ version: '0'
242
263
  requirements: []
243
264
  rubyforge_project: capybara-json
244
265
  rubygems_version: 1.8.24
@@ -247,10 +268,13 @@ specification_version: 3
247
268
  summary: for testing json-api
248
269
  test_files:
249
270
  - spec/capybara/httpclient_json/driver_spec.rb
271
+ - spec/capybara/httpclient_json/dsl_spec.rb
250
272
  - spec/capybara/json_spec.rb
251
273
  - spec/capybara/rack_test_json/driver_spec.rb
274
+ - spec/capybara/rack_test_json/dsl_spec.rb
252
275
  - spec/spec.watchr
253
276
  - spec/spec_helper.rb
254
277
  - spec/support/driver_examples.rb
278
+ - spec/support/dsl_examples.rb
255
279
  - spec/support/json_test_app.rb
256
280
  has_rdoc: