capybara-json 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.2.3
2
+ * ENHANCEMENT
3
+ * add json interface to get json
4
+
1
5
  ## 0.2.2
2
6
  * BUGFIX
3
7
  * rack_test_json works POST, PUT, DELETE as well (thanks to @sonots)
data/README.md CHANGED
@@ -9,22 +9,25 @@ capybara-json provides the same interface to testing JSON API (both local and re
9
9
  Capybara is an acceptance test framework, and it has no interest with client error(4xx response).
10
10
 
11
11
  ## USAGE
12
- require 'capybara/json'
13
- include Capybara::Json
14
-
15
- Capybara.current_driver = :rack_test_json
16
- post '/', { "this is" => "json" } # POST '/'
17
- body #=> parsed json response
18
- source #=> raw response body
19
- get '/errors/400'
20
- status_code #=> 400
21
- get! '/errors' #=> raise Capybara::Json::Error
22
-
23
- Capybara.current_driver = :httpclient_json
24
- Capybara.app_host = 'http://example.com'
25
- post '/', { "this is" => "json" } # POST 'http://example.com/'
26
- body #=> parsed json response
27
- source #=> raw response body
28
- get '/errors/400'
29
- status_code #=> 400
30
- get! '/errors' #=> raise Capybara::Json::Error
12
+
13
+ ```ruby
14
+ require 'capybara/json'
15
+ include Capybara::Json
16
+
17
+ Capybara.current_driver = :rack_test_json
18
+ post '/', { "this is" => "json" } # POST '/'
19
+ json #=> parsed json response
20
+ source #=> raw response body
21
+ get '/errors/400'
22
+ status_code #=> 400
23
+ get! '/errors' #=> raise Capybara::Json::Error
24
+
25
+ Capybara.current_driver = :httpclient_json
26
+ Capybara.app_host = 'http://example.com'
27
+ post '/', { "this is" => "json" } # POST 'http://example.com/'
28
+ json #=> parsed json response
29
+ source #=> raw response body
30
+ get '/errors/400'
31
+ status_code #=> 400
32
+ get! '/errors' #=> raise Capybara::Json::Error
33
+ ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
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.11"
25
25
  s.add_development_dependency "sinatra"
26
26
  s.add_development_dependency "thin"
27
27
  s.add_development_dependency "yajl-ruby"
@@ -37,6 +37,10 @@ class Capybara::HTTPClientJson::Driver < Capybara::Json::Driver::Base
37
37
  MultiJson.load(source) || {}
38
38
  end
39
39
 
40
+ def json
41
+ MultiJson.load(source) || {}
42
+ end
43
+
40
44
  def response_headers
41
45
  response.headers
42
46
  end
data/lib/capybara/json.rb CHANGED
@@ -6,7 +6,7 @@ require 'multi_json'
6
6
  module Capybara
7
7
  module Json
8
8
  def self.to_include
9
- Capybara.const_defined?("DSL") ? Capybara::DSL : Capybara
9
+ ::Capybara.const_defined?("DSL") ? ::Capybara::DSL : ::Capybara
10
10
  end
11
11
 
12
12
  def self.included(base)
@@ -63,6 +63,10 @@ class Capybara::RackTestJson::Driver < Capybara::Json::Driver::Base
63
63
  MultiJson.load(source) || {}
64
64
  end
65
65
 
66
+ def json
67
+ MultiJson.load(source) || {}
68
+ end
69
+
66
70
  def response_headers
67
71
  last_response.headers
68
72
  end
@@ -5,23 +5,23 @@ klass = Capybara::HTTPClientJson::Driver
5
5
  describe klass do
6
6
  before { @driver = described_class.new(JsonTestApp) }
7
7
 
8
- it_should_behave_like 'driver'
9
- it_should_behave_like 'driver with header support'
10
- it_should_behave_like 'driver with custom header support'
11
- it_should_behave_like 'driver with status code support'
12
- it_should_behave_like 'driver with cookies support'
13
- it_should_behave_like "driver with redirect support"
14
- it_should_behave_like 'driver with infinite redirect detection'
8
+ it_behaves_like 'driver'
9
+ it_behaves_like 'driver with header support'
10
+ it_behaves_like 'driver with custom header support'
11
+ it_behaves_like 'driver with status code support'
12
+ it_behaves_like 'driver with cookies support'
13
+ it_behaves_like "driver with redirect support"
14
+ it_behaves_like 'driver with infinite redirect detection'
15
15
 
16
- it_should_behave_like 'driver to post json'
17
- it_should_behave_like 'driver to put json'
16
+ it_behaves_like 'driver to post json'
17
+ it_behaves_like 'driver to put json'
18
18
 
19
- it_should_behave_like 'driver for client error'
20
- it_should_behave_like 'driver for server error'
19
+ it_behaves_like 'driver for client error'
20
+ it_behaves_like 'driver for server error'
21
21
  end
22
22
 
23
23
  describe klass do
24
24
  before { @driver = described_class.new(JsonTestApp, :follow_redirect => false) }
25
25
 
26
- it_should_behave_like "driver not to follow redirect"
26
+ it_behaves_like "driver not to follow redirect"
27
27
  end
@@ -5,23 +5,23 @@ klass = Capybara::RackTestJson::Driver
5
5
  describe klass do
6
6
  before { @driver = described_class.new(JsonTestApp) }
7
7
 
8
- it_should_behave_like 'driver'
9
- it_should_behave_like 'driver with header support'
10
- it_should_behave_like 'driver with custom header support'
11
- it_should_behave_like 'driver with status code support'
12
- it_should_behave_like 'driver with cookies support'
13
- it_should_behave_like "driver with redirect support"
14
- it_should_behave_like 'driver with infinite redirect detection'
8
+ it_behaves_like 'driver'
9
+ it_behaves_like 'driver with header support'
10
+ it_behaves_like 'driver with custom header support'
11
+ it_behaves_like 'driver with status code support'
12
+ it_behaves_like 'driver with cookies support'
13
+ it_behaves_like "driver with redirect support"
14
+ it_behaves_like 'driver with infinite redirect detection'
15
15
 
16
- it_should_behave_like 'driver to post json'
17
- it_should_behave_like 'driver to put json'
16
+ it_behaves_like 'driver to post json'
17
+ it_behaves_like 'driver to put json'
18
18
 
19
- it_should_behave_like 'driver for client error'
20
- it_should_behave_like 'driver for server error'
19
+ it_behaves_like 'driver for client error'
20
+ it_behaves_like 'driver for server error'
21
21
  end
22
22
 
23
23
  describe klass do
24
24
  before { @driver = described_class.new(JsonTestApp, :follow_redirect => false) }
25
25
 
26
- it_should_behave_like "driver not to follow redirect"
26
+ it_behaves_like "driver not to follow redirect"
27
27
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,9 @@
1
- ROOT = File.dirname(__FILE__)
2
- $: << File.expand_path('../lib', ROOT)
1
+ require "bundler/setup"
3
2
 
4
3
  require "pry"
4
+ require "tapp"
5
+
6
+ ROOT = File.dirname(__FILE__)
5
7
 
6
8
  require 'capybara/json'
7
9
  Dir[File.expand_path("support/**/*.rb", ROOT)].each {|f| require f }
@@ -25,11 +25,28 @@ shared_examples_for 'driver' do
25
25
  describe '#body' do
26
26
  it "should return json reponses" do
27
27
  @driver.visit('/')
28
+ @driver.body.should be_a(Hash)
28
29
  @driver.body.should include('Hello world!')
29
30
  end
30
31
  # pending encoding
31
32
  end
32
33
 
34
+ context '#source' do
35
+ it "should return raw reponse" do
36
+ @driver.visit('/')
37
+ @driver.source.should be_a(String)
38
+ @driver.source.should include('Hello world!')
39
+ end
40
+ end
41
+
42
+ describe '#json' do
43
+ it "should return json reponses" do
44
+ @driver.visit('/')
45
+ @driver.json.should be_a(Hash)
46
+ @driver.json.should include('Hello world!')
47
+ end
48
+ # pending encoding
49
+ end
33
50
  # TODO: find by jsonpath?
34
51
  end
35
52
 
@@ -92,7 +109,7 @@ end
92
109
 
93
110
  shared_examples_for 'driver for client error' do
94
111
  it 'should not raise exception' do
95
- expect { @driver.get('/errors/400') }.should_not raise_exception
112
+ expect { @driver.get('/errors/400') }.not_to raise_exception
96
113
  end
97
114
 
98
115
  it 'should make the status code available' do
@@ -111,13 +128,13 @@ shared_examples_for 'driver for client error' do
111
128
  end
112
129
 
113
130
  it 'should raise error using bang!' do
114
- expect { @driver.get!('/errors/400') }.should raise_exception(Capybara::Json::Error)
131
+ expect { @driver.get!('/errors/400') }.to raise_exception(Capybara::Json::Error)
115
132
  end
116
133
  end
117
134
 
118
135
  shared_examples_for 'driver for server error' do
119
136
  it 'should not raise exception' do
120
- expect { @driver.get('/errors/500') }.should_not raise_exception
137
+ expect { @driver.get('/errors/500') }.not_to raise_exception
121
138
  end
122
139
 
123
140
  it 'should make the status_code available' do
@@ -126,6 +143,6 @@ shared_examples_for 'driver for server error' do
126
143
  end
127
144
 
128
145
  it 'should raise error using bang!' do
129
- expect { @driver.get!('/errors/500') }.should raise_exception(Capybara::Json::Error)
146
+ expect { @driver.get!('/errors/500') }.to raise_exception(Capybara::Json::Error)
130
147
  end
131
148
  end
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.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-13 00:00:00.000000000 Z
12
+ date: 2012-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -82,7 +82,7 @@ dependencies:
82
82
  requirements:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: '2.8'
85
+ version: '2.11'
86
86
  type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: '2.8'
93
+ version: '2.11'
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: sinatra
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -253,3 +253,4 @@ test_files:
253
253
  - spec/spec_helper.rb
254
254
  - spec/support/driver_examples.rb
255
255
  - spec/support/json_test_app.rb
256
+ has_rdoc: